07.4 Newton Raphson Method
07.4 Newton Raphson Method
07.4 Newton Raphson Method
Newton-Raphson Method
Let f(x) be a smooth and continuous function and xr be an unknown root of f(x). Now
assume that x0 is a guess for xr . Unless x0 is a very lucky guess, f(x0 ) will not be a
root. Given this scenario, we want to find an x1 that is an improvement on x0 (i.e., closer
to xr than x0 ). If we assume that x0 is "close enough" to xr , then we can improve upon
it by taking the linear approximation of f(x) around x0 , which is a line, and finding the
intersection of this line with the x-axis. Written out, the linear approximation of f(x)
around x0 is f(x) ≈ f(x0 ) + f ′ (x0 )(x − x0 ). Using this approximation, we find x1
such that f(x1 ) = 0. Plugging these values into the linear approximation results in the
equation
f(x0 )
x1 = x0 − .
f ′ (x0 )
An illustration of how this linear approximation improves an initial guess is shown in the
following figure.
g(xi−1 )
xi = xi−1 − .
g ′ (xi−1 )
The Newton-Raphson Method of finding roots iterates Newton steps from x0 until the
error is less than the tolerance.
2
file:///Users/diegouribe/Downloads/chapter19.04-Newton-Raphson-Method.html Page 1 of 3
chapter19.04-Newton-Raphson-Method 21/05/24 20:32
TRY IT! Again, the √2 is the root of the function f(x) = x2 − 2. Using x0 = 1.4 as a
starting point, use the previous equation to estimate √2. Compare this approximation
with the value computed by Python's sqrt function.
1.42 − 2
x = 1.4 − = 1.4142857142857144
2(1.4)
f = lambda x: x**2 - 2
f_prime = lambda x: 2*x
newton_raphson = 1.4 - (f(1.4))/(f_prime(1.4))
newton_raphson = 1.4142857142857144
sqrt(2) = 1.4142135623730951
TRY IT! Write a function my_newton(f, df, x0, tol), where the output is an estimation
of the root of f, f is a function object f(x), df is a function object to f ′ (x), x0 is an initial
guess, and tol is the error tolerance. The error measurement should be |f(x)|.
TRY IT! Use my_newton= to compute √2 to within tolerance of 1e-6 starting at x0 = 1.5.
estimate = 1.4142135623746899
sqrt(2) = 1.4142135623730951
file:///Users/diegouribe/Downloads/chapter19.04-Newton-Raphson-Method.html Page 2 of 3
chapter19.04-Newton-Raphson-Method 21/05/24 20:32
TRY IT! Compute a single Newton step to get an improved approximation of the root of
the function f(x) = x3 + 3x2 − 2x − 5 and an initial guess, x0 = 0.29.
In [4]: x0 = 0.29
x1 = x0-(x0**3+3*x0**2-2*x0-5)/(3*x0**2+6*x0-2)
print("x1 =", x1)
x1 = -688.4516883116648
TRY IT! Consider the polynomial f(x) = x3 − 100x2 − x + 100. This polynomial has a
root at x = 1 and x = 100. Use the Newton-Raphson to find a root of f starting at
x0 = 0 .
100
At x0 = 0, f(x0 ) = 100, and f ′ (x) = −1. A Newton step gives x1 = 0 − −1 = 100,
which is a root of f . However, note that this root is much farther from the initial guess
than the other root at x = 1, and it may not be the root you wanted from an initial guess
of 0.
file:///Users/diegouribe/Downloads/chapter19.04-Newton-Raphson-Method.html Page 3 of 3