PROGRAM
FINDING
APPROXIMATE ROOT OF A LINEAR EQUATION BY NEWTON-RAPHSON METHOD
#include<stdio.h>
#include<math.h>
#include<conio.h>
float f(float x)
{
return (x*x)-2*x;
}
float df(float y)
{
return(2*y)-2;
}
int main()
{
float x0,x1,h;
int n;
clrscr();
printf("\nenter the max no. of
iterations");
scanf("%d",&n);
printf("\nenter the initial approximate
value for the function (x*x)-(2*x)");
scanf("%f",&x0);
for(int i=0;i<n;i++)
{
h=f(x0)/df(x0);
x1=x0-h;
printf("\n at the iteration %d, root is
%f\n",(i+1),x1);
if(fabs(h)<0.001)
{
printf("\nafter %d iteration final root
is %f",(i+1),x1);
}
x0=x1;
}
getch();
return 0;
}
OUTPUT:-
1 comments:
commentsThank you.. :)
Reply