Spread the love

## Newton Raphson Method using C programming

* *Also known as successive substitution method.

__Algorithm__

1. Assign an initial value to x say x

_{0}.2. Evaluate f (x

_{0}) and f’(x_{0})3. Compute x

_{1}=x_{0}–f(x_{0})/f^{’}(x_{0})4. If f(x

_{1}) =0 then x_{1}, is the required root & stop the process.5. If f(x~~+~~0 then replace x

_{1})_{0 }by x_{1}& repeat the process till the root is found to the desired degree of accuracy. Let x

_{o }be the first approximation to the root of the equation f(x)=0. Let x_{1}=x_{0 }+ h be the better approximation which approximately satisfy the equation f(x) = 0Therefore,

f(x

_{0}+h)= 0 approximately f(x

_{0})+h f^{’}(x_{0})+h^{2}/2! f”(x_{0})+h/3! f’”(x_{0}) +….. =0Assumption since h is very small, neglecting its square and higher power, we get,

f(x

_{0}) +h f’(x_{0})=0 h= – f(x

_{0})/ f’(x_{0})Therefore ,

x
_{1}=x_{0}-f(x_{0})/f’(x_{0}) |

#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();

}

Spread the love