TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
successive_approximation.cpp
Go to the documentation of this file.
1
6#include <cmath>
7#include <iostream>
8
12static float eq(float y) { return (3 * y) - cos(y) - 2; }
13
17static float eqd(float y) { return 0.5 * (cos(y) + 2); }
18
20int main() {
21 float y, x1, x2, x3, sum, s, a, f1, f2, gd;
22 int i, n;
23
24 for (i = 0; i < 10; i++) {
25 sum = eq(y);
26 std::cout << "value of equation at " << i << " " << sum << "\n";
27 y++;
28 }
29 std::cout << "enter the x1->";
30 std::cin >> x1;
31 std::cout << "enter the no iteration to perform->\n";
32 std::cin >> n;
33
34 for (i = 0; i <= n; i++) {
35 x2 = eqd(x1);
36 std::cout << "\nenter the x2->" << x2;
37 x1 = x2;
38 }
39 return 0;
40}
static float eq(float y)
static float eqd(float y)