PROGRAM (TO FIND APPROXIMATE ROOT OF THE LINEAR EQUATION BY NEWTON-RAPHSON METHOD)

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:-


Share this

Related Posts

Previous
Next Post »

1 comments:

comments
Anonymous
27 March 2016 at 14:32 delete

Thank you.. :)

Reply
avatar

Powered by Blogger.

Popular Posts