Advertise

Responsive Ad

Newton Raphson Method process 2 C++

Newton Raphson Method

Newton Raphson Method, Newton Raphson Method in c
Newton Raphson Method

Problem: Using Newton’s method, find the root of x*log10(x) - 1.2.

C Programming: Dev c++


#include<stdio.h>
#include<math.h>
float f(float x)
{
    return x*log10(x) - 1.2;
}
float df (float x)
{
    return log10(x) + 0.43429;
}
main()
{
    int itr, maxmitr;
    float h, x0, x1, allerr;
    printf("\nEnter x0, allowed error and maximum iterations\n");
    scanf("%f %f %d", &x0, &allerr, &maxmitr);
    for (itr=1; itr<=maxmitr; itr++)
    {
        h=f(x0)/df(x0);
        x1=x0-h;
        printf(" At Iteration no. %3d, x = %9.6f\n", itr, x1);
        if (fabs(h) < allerr)
        {
            printf("After %3d iterations, root = %8.6f\n", itr, x1);
            return 0;
        }
        x0=x1;
    }
    printf(" The required solution does not converge or iterations are insufficient\n");
    return 1;
}


Output Screen:

 Output of Newton Raphson Mathod
Output of Newton Raphson Method

Post a Comment

0 Comments