0% found this document useful (0 votes)
54 views

1.to Find The Roots of Non-Linear Equation Using Newton Raphson's Method

The document describes an experiment using the Newton Raphson method to find the roots of a non-linear equation. The Newton Raphson method uses a formula to iteratively find the next value of the variable by taking the previous value minus the function value divided by the derivative value. The algorithm takes an initial guess and the function and derivative functions as inputs and outputs the root. Sample Python code is provided to find the root of x^3 - x^2 + 2 by calling the newtonRaphson function.

Uploaded by

manjula mandava
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

1.to Find The Roots of Non-Linear Equation Using Newton Raphson's Method

The document describes an experiment using the Newton Raphson method to find the roots of a non-linear equation. The Newton Raphson method uses a formula to iteratively find the next value of the variable by taking the previous value minus the function value divided by the derivative value. The algorithm takes an initial guess and the function and derivative functions as inputs and outputs the root. Sample Python code is provided to find the root of x^3 - x^2 + 2 by calling the newtonRaphson function.

Uploaded by

manjula mandava
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PYTHON PROGRAMMING LAB DATE:

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. 

Advantages of Newton Raphson Method:


 It is best method to solve the non-linear equations.
 It can also be used to solve the system of non-linear equations, non-linear differential
and non-linear integral equations.
 The order of convergence is quadric i.e. of second order which makes this method fast
as compared to other methods.
 It is very easy to implement on computer.
Input: A function of x (for example x 3 – x2 + 2),
derivative function of x (3x 2 – 2x for above example)
and an initial guess x0 = -20
Output: The value of root is : -1.00
OR any other value close to root.

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

You might also like