Generalized Newton Rapshon Method C++


#include<bits/stdc++.h>
using namespace std;
double x,y,z;
double func1(double x)
{
return (pow(x,3)-pow(x,2)-x+1);
}
double func2(double y)
{
return 3*y*y-2*y-1;
}
double func3(double z)
{
return 6*z -2;
}

int main()
{
double x0,p,x1,x2,c=0,temp;
cout<<"The given eqation is : x^3- x^2-x+1 = 0 "<<endl;
cout<<" \nNumber of root : ";
cin>>p;
cout<<"\n\nEnter no approximation of root : ";
cin>>x0;
do
{
c++;

x1=x0-(p)*(func1(x0)/func2(x0));

x2=x0-(p-1)*(func2(x0)/func3(x0));
x0=x1;
cout<< "iteration no "<<c<<" x = "<<x1<<endl;


}while(fabs(x1-x2)>=0.001);
cout<<"\n\nThe root is : "<<x1<<endl;
return 0;
}

Share on Google Plus
Earn @ Wap4dollar.Com

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment