Recent Post

3/recentposts

Sunday, January 21, 2018

NEWTON-RAPHSON METHOD IN C PROGRAMMING

//newton-raphson
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
float f(float x)
{
    return(pow(x,4)-x-10);
}
float df(float x)
{
    return(4*x*x-1);
}
void main()
{
    float x,x1;
    int c=0,i;
    printf("Enter initial guess and iteration : ");
    scanf("%f%d",&x,&i);
    do
    {
        if(df(x)==0)
        {
           printf("derivative zero");
           exit(0);
        }
        x1=x-(f(x)/df(x));
        x=x1;
        c++;
        if(c==i)
        {
            printf("Root not convergence");
            exit(0);
        }

    }while(fabs(f(x))>0.00005);
    printf("Root = %f,f(x) = %f",x1,f(x1));
}

Share:

0 comments:

Post a Comment

Recent

Unordered List

Definition List

Pages

Theme Support