Sunday, September 28, 2008

Newton Raphson Algorithm.

Let the equation be f(x)=x*x*x-18.

So in newton raphson we take f(x) and f'(x) ,so here we have to find f'(x) we write a function,

double f2(double s)
{
return 3*s*s;
}

double f1(double s)
{
return pow(s,3)-18;
}

void main()
{
double a[30],e;
int i=2;
a[0]=0;
cout<<"Enter the value of x:";
cin>>a[1];

cout<<"Enter the value of epslon:";
cin>>e;

do
{
a[i]=a[i-1]-( f1(a[i-1]) / f2(a[i-1]));
cout<<"\n" << a[i];
i++;
}
while( fabs(a[i-1]-a[i-2]) > =e);
getch();
}

No comments: