Newton Raphson Method

Home >> Sem 2 >> CONM program list  >> Newton Raphson Method
Just copy and paste to notepad 
 

//x^3-4x-9
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
void main()
{

        double x1,x2=0,x3,fx1,dx1,fx2,e;
        cout<<"Enter The Initial Approximation\n";
        cin>>x1;
        cout<<"Enter The Epsilon\n";
        cin>>e;
        fx1=pow(x1,3)-(4*x1)-9;
        dx1=3*pow(x1,2)-4;

        cout<<"x0"<<setw(15)<<"fx0"<<setw(15)<<"dx0"<<setw(15)<<"x1"<<setw(15)<<"fx1"<<endl;
        
        do
        {
                x3=x2;
                x2=x1-(fx1/dx1);
                fx2=pow(x2,3)-(4*x2)-9;
                cout<<x1<<setw(15)<<fx1<<setw(15)<<dx1<<setw(15)<<x2<<setw(15)<<fx2<<endl;
                x1=x2;
                fx1=fx2;
                dx1=3*pow(x1,2)-4;
        }
   while(fabs(x3-x2)>e);
         cout<<"Required Root is:="<<x2;
}