rename Computer Oriented Statistical Methods -> computer_oriented_statistical_methods (#656)

This commit is contained in:
Christian Clauss
2019-11-28 14:07:34 +01:00
committed by GitHub
parent 0174dad705
commit 81b25e578d
6 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
#include <iostream.h>
#include <conio.h>
#include <math.h>
float eq(float i)
{
return (pow(i, 3) - (4 * i) - 9); // original equation
}
void main()
{
float a, b, x, z;
clrscr();
for (int i = 0; i < 100; i++)
{
z = eq(i);
if (z >= 0)
{
b = i;
a = --i;
goto START;
}
}
START:
cout << "\nFirst initial: " << a;
cout << "\nSecond initial: " << b;
for (i = 0; i < 100; i++)
{
x = (a + b) / 2;
z = eq(x);
cout << "\n\nz: " << z << "\t[" << a << " , " << b << " | Bisect: " << x << "]";
if (z < 0)
{
a = x;
}
else
{
b = x;
}
if (z > 0 && z < 0.0009) // stoping criteria
{
goto END;
}
}
END:
cout << "\n\nRoot: " << x;
getch();
}

View File

@@ -0,0 +1,63 @@
#include <bits/stdc++.h>
using namespace std;
int main()
{
int mat_size, i, j, step;
cout << "Matrix size: ";
cin >> mat_size;
double mat[mat_size + 1][mat_size + 1], x[mat_size][mat_size + 1];
cout << endl
<< "Enter value of the matrix: " << endl;
for (i = 0; i < mat_size; i++)
{
for (j = 0; j <= mat_size; j++)
{
cin >> mat[i][j]; //Enter (mat_size*mat_size) value of the matrix.
}
}
for (step = 0; step < mat_size - 1; step++)
{
for (i = step; i < mat_size - 1; i++)
{
double a = (mat[i + 1][step] / mat[step][step]);
for (j = step; j <= mat_size; j++)
mat[i + 1][j] = mat[i + 1][j] - (a * mat[step][j]);
}
}
cout << endl
<< "Matrix using Gaussian Elimination method: " << endl;
for (i = 0; i < mat_size; i++)
{
for (j = 0; j <= mat_size; j++)
{
x[i][j] = mat[i][j];
cout << mat[i][j] << " ";
}
cout << endl;
}
cout << endl
<< "Value of the Gaussian Elimination method: " << endl;
for (i = mat_size - 1; i >= 0; i--)
{
double sum = 0;
for (j = mat_size - 1; j > i; j--)
{
x[i][j] = x[j][j] * x[i][j];
sum = x[i][j] + sum;
}
if (x[i][i] == 0)
x[i][i] = 0;
else
x[i][i] = (x[i][mat_size] - sum) / (x[i][i]);
cout << "x" << i << "= " << x[i][i] << endl;
}
return 0;
}

View File

@@ -0,0 +1,53 @@
#include <iostream.h>
#include <conio.h>
#include <math.h>
float eq(float i)
{
return (pow(i, 3) - (4 * i) - 9); // original equation
}
float eq_der(float i)
{
return ((3 * pow(i, 2)) - 4); // derivative of equation
}
void main()
{
float a, b, z, c, m, n;
clrscr();
for (int i = 0; i < 100; i++)
{
z = eq(i);
if (z >= 0)
{
b = i;
a = --i;
goto START;
}
}
START:
cout << "\nFirst initial: " << a;
cout << "\nSecond initial: " << b;
c = (a + b) / 2;
for (i = 0; i < 100; i++)
{
float h;
m = eq(c);
n = eq_der(c);
z = c - (m / n);
c = z;
if (m > 0 && m < 0.009) // stoping criteria
{
goto END;
}
}
END:
cout << "\n\nRoot: " << z;
getch();
}

View File

@@ -0,0 +1,49 @@
#include <iostream.h>
#include <conio.h>
#include <math.h>
float eq(float i)
{
return (pow(i, 3) - (4 * i) - 9); // original equation
}
void main()
{
float a, b, z, c, m, n;
clrscr();
for (int i = 0; i < 100; i++)
{
z = eq(i);
if (z >= 0)
{
b = i;
a = --i;
goto START;
}
}
START:
cout << "\nFirst initial: " << a;
cout << "\nSecond initial: " << b;
for (i = 0; i < 100; i++)
{
float h, d;
m = eq(a);
n = eq(b);
c = ((a * n) - (b * m)) / (n - m);
a = b;
b = c;
z = eq(c);
if (z > 0 && z < 0.09) // stoping criteria
{
goto END;
}
}
END:
cout << "\n\nRoot: " << c;
getch();
}

View File

@@ -0,0 +1,49 @@
#include <iostream.h>
#include <conio.h>
#include <math.h>
float eq(float i)
{
return (pow(i, 3) - (4 * i) - 9); // origial equation
}
void main()
{
float a, b, z, c, m, n;
clrscr();
for (int i = 0; i < 100; i++)
{
z = eq(i);
if (z >= 0)
{
b = i;
a = --i;
goto START;
}
}
START:
cout << "\nFirst initial: " << a;
cout << "\nSecond initial: " << b;
for (i = 0; i < 100; i++)
{
float h, d;
m = eq(a);
n = eq(b);
c = ((a * n) - (b * m)) / (n - m);
a = c;
z = eq(c);
if (z > 0 && z < 0.09) // stoping criteria
{
goto END;
}
}
END:
cout << "\n\nRoot: " << c;
getch();
}

View File

@@ -0,0 +1,37 @@
#include <conio.h>
#include <iostream.h>
#include <math.h>
float eq(float y)
{
return ((3 * y) - (cos(y)) - 2);
}
float eqd(float y)
{
return ((0.5) * ((cos(y)) + 2));
}
void main()
{
float y, x1, x2, x3, sum, s, a, f1, f2, gd;
int i, n;
clrscr();
for (i = 0; i < 10; i++)
{
sum = eq(y);
cout << "value of equation at " << i << " " << sum << "\n";
y++;
}
cout << "enter the x1->";
cin >> x1;
cout << "enter the no iteration to perform->\n";
cin >> n;
for (i = 0; i <= n; i++)
{
x2 = eqd(x1);
cout << "\nenter the x2->" << x2;
x1 = x2;
}
getch();
}