Navigation

Saturday, 28 February 2015

PROGRAM FOR FINDING ROOT USING NEWTON-RAPHSON ITERATIVE METHOD

 /*program for finding root using newton-raphson method*/
#include<math.h>
#define f(x) x*x*x*x-x-10
#define f1(x) 4*x*x*x-1
void main()
{
    float x0,x1,d,y0,y1;
    int i,n;
    clrscr();
    printf("\n\n\t\tPROGRAM FOR FINDING ROOT USING NEWTON-RAPHSON ITERATIVE METHOD\n\n\n");
    printf("Enter the value of x0,d,n\n");
    scanf("%f%f%f",&x0,&d,&n);
    for(i=1;i<=n;i++)
    {
        y0=f(x0);
        y1=f(x1);
        if(fabs(y1<=d))
        {
            printf("Slope is to small\n\n");
            exit(0);
        }
        x1=x0-(y0/y1);
        if(x0==x1)
        {
            printf("Convergent solution\n\n");
            printf("The required root is %f\n",x1);
            printf("The total number of iterations is %d\n\n",i);
            exit(0);
        }
        x0=x1;
        printf("x%d=%f\n",i,x1);
    }
    printf("Doesnot converge in %d iterations",i-1);
    getch();
}

No comments:

Post a Comment