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;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

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. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment