TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
successive_approximation.cpp File Reference

Method of successive approximations using fixed-point iteration method. More...

#include <cmath>
#include <iostream>
Include dependency graph for successive_approximation.cpp:

Go to the source code of this file.

Functions

static float eq (float y)
 
static float eqd (float y)
 
int main ()
 

Detailed Description

Method of successive approximations using fixed-point iteration method.

Definition in file successive_approximation.cpp.

Function Documentation

◆ eq()

static float eq ( float y)
static

equation 1

\[f(y) = 3y - \cos y -2\]

Definition at line 12 of file successive_approximation.cpp.

12{ return (3 * y) - cos(y) - 2; }

◆ eqd()

static float eqd ( float y)
static

equation 2

\[f(y) = \frac{\cos y+2}{2}\]

Definition at line 17 of file successive_approximation.cpp.

17{ return 0.5 * (cos(y) + 2); }

◆ main()

int main ( void )

Main function

Definition at line 20 of file successive_approximation.cpp.

20 {
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}
T sum(const std::vector< std::valarray< T > > &A)
static float eq(float y)
static float eqd(float y)