### Newton-Raphson Method:

The Newton-Raphson method (also known as Newton’s method) is a way to quickly find a good approximation for the root of a real-valued function $f(x)=0$. It uses the idea that a continuous and differentiable function can be approximated by a straight line tangent to it.

Newton-Raphson formula:

##### x_{n+1 }= x_{n}-f(x_{n})/f ‘(x_{n})

### How it works:

Suppose you need to find the root of a continuous, differentiable function $f(x)$, and you know the root you are looking for is near the point $x=x_{0}$. Then Newton’s method tells us that a better approximation for the root is

**$x_{1}=x_{0}−f(x)f(x) .$**

This process may be repeated as many times as necessary to get the desired accuracy. In general, for any $x$-value $x_{n}$, the next value is given by

**$x_{n+}=x_{n}−f(x)f(x) .$**

Note: the term “near” is used loosely because it does not need a precise definition in this context. However, $x_{0}$ should be closer to the root you need than to any other root (if the function has multiple roots)

### C++ program to find root using Newton-Raphson method:

#include <iostream> #include <math.h> using namespace std; float fn(float x) { return pow(x,2)+(3*x)+1 ; } float de(float x) { return 2*x + 3 ; } int main() { float a,e=0,z; cout<<"Enter Number "; cin>>a; do { e++; z=a-(fn(a)/de(a)); cout<<"The iterative "<<e<<" root is "<<z; a=z; cout<<endl; }while(abs(fn(z))>0.001); return 0; }

### Output:

$g++ -o main *.cpp $main Enter Number The iterative 1 root is -0.333333 The iterative 2 root is -0.380952 The iterative 3 root is -0.381966

Please comment in case of any query, issues or concerns.