Wednesday, June 22, 2016

FIXED POINT ITERATION

Fixed point iteration is one of the methods to calculate the root of the equation. It is also based on the numbers of iteration.

 In this method given equation f(x) = 0 is first converted into x=g(x),
 then using iterative recursive formula others values are calculated as:

 xi+1 = g(xi)  where i=0,1,2,3,…..


and x0  is guessed initially.



Program Code Implemented in C++

#include<iomanip>
#include<iostream>
#include<math.h>
#define e 0.00001
using namespace std;
float g(float a)
{
          return(0.5*((1/(a*a+a))+a));
}
int main()
{
          float x1,x2,x3;
          int i=1;
          cout<<"The given function is f(X)=x^3+X^2-1"<<endl;
    cout<<"Enter your initial guess:";
    cin>>x1;
          cout<<setw(2)<<"No."<<setw(12)<<"x1"<<setw(30)<<"x2=0.5((1/(X^2+X))+X)"<<setw(14)<<"Upgrade"<<endl;
          do
          {
              x2=g(x1);
                   cout<<setw(2)<<i<<setw(13)<<x1<<setw(30)<<x2<<setw(14)<<"x1=x2"<<endl;
                   i++;
                    x3=x1;
                   x1=x2;
    }while( fabs(x1-x3) >= e);
          cout<<"\nTHE REQUIRED Root IS ="<<x2;
          return 0;
}

NOTE: The above code is implemented in c++ and written using code blocks libraries.


No comments:

Post a Comment