1.to Find The Roots of Non-Linear Equation Using Newton Raphson's Method
1.to Find The Roots of Non-Linear Equation Using Newton Raphson's Method
EXPERIMENT-2
1.To find the roots of non-linear equation using Newton Raphson’s method.
Starting from initial guess x 1, the Newton Raphson method uses below formula to find next
value of x, i.e., xn+1 from previous va lue xn.
Algorithm:
Input: initial x, func(x), derivFunc(x)
Output: Root of Func()
1. Compute values of func(x) and derivFunc(x) for given initial x
2. Compute h: h = func(x) / derivFunc(x)
3. While h is greater than allowed error ε
1. h = func(x) / derivFunc(x)
2. x = x – h
PYTHON PROGRAMMING LAB DATE:
Source Code:
def func( x ):
return x * x * x - x * x + 2
# Derivative of the above function
# which is 3*x^x - 2*x
def derivFunc( x ):
return 3 * x * x - 2 * x
# Function to find the root
def newtonRaphson( x ):
h = func(x) / derivFunc(x)
while abs(h) >= 0.0001:
h = func(x)/derivFunc(x)
# x(i+1) = x(i) - f(x) / f'(x)
x = x - h
print("The value of the root is : ","%.4f"% x)
# Driver program to test above
x0 = -20 # Initial values assumed
newtonRaphson(x0)
OUTPUT:
The value of root is : -1.00