C Program to Implement Newton Raphson Method to find the root of the equation

/*Program to Implement Newton Raphson Method
to find the root of the equation f(x)=3x-cos(x)-1*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(3*x-cos(x)-1);
}
float df(float x)
{
return(3+sin(x));
}
void main()
{

float x0,x1,del,eps;
int i,n;
clrscr();
printf("\nEnter the value of x0");
scanf("%f",&x0);
printf("\nEnter the no of itreations");
scanf("%d",&n);
printf("\n ENter the value of delta : ");
scanf("%f",&del);

for(i=1;i<=n;i++)
{
if(fabs(df(x0))<del)
{
printf("Initialapprox is invalid");

}
else

{

x1=x0-(f(x0)/df(x0));
x0=x1;

}

 printf("\n Approximate root is : %f",x1);
}

getch();

}

Comments

Popular Posts