Showing posts with label RAPHSON. Show all posts
Showing posts with label RAPHSON. Show all posts

Tuesday, August 2, 2016

PROGRAM FOR NEWTON RAPHSON

/* PROGRAM FOR NEWTON RAPHSON*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x0,x1,e,delta,c;
int i,n,flag=0;
float f(float x);
float df(float x);
clrscr();
printf("enter the value of x0,e,delta,n:\n");
scanf("%f%f%f%d",&x0,&c,&delta,&n);
for (i=0;i<n;i++)
{
if (df(x0)<delta)
{
flag=1;
break;
}
x1=x0-(f(x0)/df(f(x0)));
if (fabs((x1-x0)/x1)<e)
{
flag=2;
break;
}
x0-x1;
}    //end for loop//
if(flag==0)
{
printf("\n solution does not converg in ittration\n");
}
else
if(flag==1)
printf("\n slop is root small.\n");
else
printf("\n root is %f",x1);
getch();
}
float f(float x)
{
return(x*x*x-x*x-1);
}
float df(float x)
{
return(3*x*x-2*x);
}


/*************OUTPUT***************
Enter the value of x0,c,delta,n:
1.5
.1
3
4

Root is 2.015119   */

ALGORITHM FOR NEWTON RAPHSON METHOD

ALGORITHM FOR NEWTON RAPHSON METHOD


  1.    Start
  2.    Read the values of x0,e,delta,n;
   Where x0 is initial approximation, e is error      
   allowed. delta is the slope and n is
   maximum number of iteration.
 
  1.    for i=1 to n,
  2.    if | f(x0 )|<delta,
   then goto 9
  1.    x1= x0 –[f (x0  )/f (x0 )]
  2.    if |( x0 – x1)/ x0 | <e, then goto 11
  3.    write “Solution does not converge in n
          iteration”.

  1.    Stop
  2.    Write “Slope is too small”.
  3. Stop
  4. Write ”Convergent solution is x”.
  5. Stop