N. Achyut Numerical Method Newton-Raphson Method in C++ Programming

Newton-Raphson Method in C++ Programming

Newton-Raphson Method

Newton-Raphson Method/Numerical Method / C++ Programming / CSIT / Computer science/ Engineering

The Newton-Raphson method, or Newton Method, is a powerful technique for solving equations numerically. Like so much of the differential calculus, it is based on the simple idea of linear approximation.

Newton-Raphson Method in C++ Programming

#include<iostream>
#include<math.h>
using namespace std;

#define f(x) 3*x*x-6*x+2 //equation
#define g(x) 6*x-6  // derivative of the equation

int main()
{
    float xi,x,fi,gi,f=1,e=1;
    cout<< "enter the initial guess x0:";
    cin>>xi;
    while(e>=0.0001 && f!=0)
    {
        fi=f(xi);
        gi=g(xi);
        x=xi-(fi/gi); //working formula
        f=f(x);
        e=fabs((x-xi)/x);
        xi=x;
    }
    cout<< "n the root of the equation="<<x;
    return 0;
}

Output of Newton-Raphson Method in C++ Programming

Enter the initial Guess x0 : 2
the root of the equation = 1.57735

You may like some other numerical method Questions :

BISECTION METHOD SOLUTION IN C++ PROGRAMMING
FALSE POSITION METHOD IN C++ PROGRAMMING
SECANT METHOD IN C++ PROGRAMMING
FIXED POINT METHOD / C++ PROGRAMMING

Related Post