Newton Raphson Method using C programming
Also known as successive substitution method.
Algorithm
1. Assign an initial value to x say x0.
2. Evaluate f (x0) and f’(x0)
3. Compute x1 =x0 –f(x0)/f’(x0)
4. If f(x1) =0 then x1, is the required root & stop the process.
5. If f(x1) +0 then replace x0 by x1 & repeat the process till the root is found to the desired degree of accuracy.
Let xo be the first approximation to the root of the equation f(x)=0. Let x1=x0 + h be the better approximation which approximately satisfy the equation f(x) = 0
Therefore,
f(x0+h)= 0 approximately
f(x0)+h f’(x0)+h2/2! f”(x0)+h/3! f’”(x0) +….. =0
Assumption since h is very small, neglecting its square and higher power, we get,
f(x0) +h f’(x0)=0
h= – f(x0)/ f’(x0)
Therefore ,
x1=x0-f(x0)/f’(x0) |
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define e 0.0001
float f(float x){
return (x*x*x-6*x+4);
}
float f1(float x){
return (3*x*x-6);
}
void main(){
float x0,x1;
clrscr();
printf(“enter initial value:”);
scanf(“%f”,&x0);
do{
x1=x0-(f(x0)/f1(x0));
if(f(x1)==0)
break;
else
x0=x1;
}while(fabs((x1-x0)/x1)>e);
printf(“the reqd. root is:%f”,x1);
getch();
}