Topic : Newton Raphson Method - Roots of Equations
Simulation : Pitfall - Root jumping several roots away
Language : Mathmatica 4.1
Authors : Nathan Collier, Autar Kaw
Date : 11 July 2002
Abstract : The following example illustrates how, in the Newton-Raphson method, an initial guess close to one root can jump to a location several roots away.

INPUTS: Enter the Following

Function in f[x] = 0

f[x_] := Sin[x]

Range of 'x' you want to see the function

(Subscript[x, begin]) = -10.0;
(Subscript[x, end]) = 10.0;

curve = 
        Plot[f[x], {x, (Subscript[x, begin]), (Subscript[x, end])}, 
          PlotLabel -> "Entered function on given interval", 
          TextStyle -> {FontSize -> 11}];

Initial guess

x0 = 1.431;

Because this method uses a line tangent to the function at the initial guess, we must calculate the derivative of the function to find the slope of the line at this point.  Here we will define the derivative of the function f(x) as g(x).

g[x_] := f'[x]

Iteration 1

x1 = x0 - f[x0]/g[x0]

(Subscript[ϵ, a]) = Abs[(x1 - x0)/x1*100]

tanline[x_] := 
      f[x0] + ((0 - f[x0])/(x1 - x0))*(x - x0)

tline = Plot[tanline[x], {x, (Subscript[x, begin]), (Subscript[x, end])}];

Show[Graphics[Line[{{x0, 1}, {x0, -1}}]], curve, 
        Graphics[Line[{{x1, 1}, {x1, -1}}]], tline, Axes -> True, 
        PlotLabel -> "Entered function on given interval with upper \
and lower guesses and estimated root", 
        TextStyle -> {FontSize -> 11}];

Iteration 2

x2 = x1 - f[x1]/g[x1]

(Subscript[ϵ, a]) = Abs[(x2 - x1)/x2*100]

tanline[x_] := 
      f[x1] + ((0 - f[x1])/(x2 - x1))*(x - x1)

tline = Plot[tanline[x], {x, (Subscript[x, begin]), (Subscript[x, end])}];

Show[Graphics[Line[{{x1, 1}, {x1, -1}}]], curve, 
        Graphics[Line[{{x2, 1}, {x2, -1}}]], tline, Axes -> True, 
        PlotLabel -> "Entered function on given interval with upper \
and lower guesses and estimated root", 
        TextStyle -> {FontSize -> 11}];