TheAlgorithms-C-Plus-Plus/Computer Oriented Statistical Methods/successive_approximation.CPP

37 lines
578 B
C++
Raw Normal View History

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