### C++ Program To Find Root Using Newton-Raphson Method

Description:
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.
It uses the formula:
##### xn+1 = xn-f(xn)/f '(xn)
Program Code:
#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:

#### More Articles of Avikrit Kohli:

Name Views Likes
C++ Program To Implement Simpsons 3/8th rule 360 2
C++ Program To Reverse String Without Using String Functions 382 20
C++ Program To Reverse Line In Text File 1243 1
C++ Program To Reverse Each Word In Text File 324 1
C++ Program To Read Text File Word By Word 1428 1
C++ Program To Create And Display Text File 303 1
C++ Program To Find Root Using Newton-Raphson Method 5396 11
C++ Program To Find Root Using Bisection Method 1125 1
C++ Program For Cohen Sutherland Clipping Algorithm 1839 1
To Sort Array Of Integers Using Bubble,Insertion And Selection Sort 317 1
C++ Program To Delete Element In Array At Particular Position 517 1
C++ Program To Insert Element In Array At Given Position 698 1
C++ Program To Implement Stack Using Arrays 331 1
Python Program To Add Source Code of A Webpage 239 1
Python Program To Extract Data From Excel 267 1
C++ Program To Find Sum Of Fibonacci Series Using Recursion 459 1
Program To Display Level Order Transversal Using Queue 254 1
C++ Program To Find The Minimum In Subarray Of Size k Using Deque 267 1
C++ Program To Sort Stack Recursively 857 1
C++ Program To Reverse Stack Recursively 262 1
C++ Program To Insert At Bottom Of Stack Using Recursion 266 1
C++ Program To Create Tower Of Hanoi 2427 1
C++ Program To Convert Infix To Postfix Expression Using Stack 10945 3
C++ Program To Balance Parenthesis Using Stack 963 1
C++ Program To Implement Queue Using Array 2256 2
C++ Program To Sort Two Arrays And Inserting Result In Third array 258 1
C++ Program To Find Length Of Linked List 675 1
C++ Program To Search An Element Recursively In Linked List 293 1
C++ Program To Reverse Linked List Recursively 1153 1