Fixed Point Method(Numerical Method) C++ Programming

#include<iostream>
#include<math.h>
using namespace std;

#define f(x) x*x-6*x+8 // equation 
#define g(x) (x*x+8)/6

int main()
{
    float x0,x1,e=1;
    cout<< "input the initial guess:";
    cin>>x0;
    while(e>0.005)
    {
        x1=g(x0);//working formula 
        e=fabs((x1-x0)/x1);
        x0=x1;
    }
    cout<< "\nthe root of the equation ="<<x0;
    return 0;
}
OUTPUT:
Here we can find the root of the equation x2-6x+8 by using fixed point iteration method.










Numerical Method Other Problems:

Powered by Blogger.