Topic : Newton Raphson Method - Roots of Equations
Simulation : Pitfall - Slow convergence around infection points
Language : Mathmatica 4.1
Authors : Nathan Collier, Autar Kaw
Date : 2 July 2002
Abstract : The following example illustrates slow convergence of the Newton-Raphson method due to an inflection point occuring in the vicinity of the root.

INPUTS: Enter the Following

Function in f[x] = 0

f[x_] := (x - 1)^3

Range of 'x' you want to see the function

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

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

Initial guess

x0 = -1;

Maximum number of iterations

(Subscript[n, maximum]) = 10;

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, -1.5, 0.5}];

Show[curve, tline, Graphics[Line[{{x0, 2}, {x0, -20}}]], 
        Graphics[Line[{{x1, 2}, {x1, -20}}]], Axes -> True, 
        PlotRange -> All, 
        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, -1, 1}];

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

Iteration 3

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

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

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

tline = Plot[tanline[x], {x, -1, 1}];

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

Iteration 4

x4 = x3 - f[x3]/g[x3]

(Subscript[ϵ, a]) = Abs[(x4 - x3)/x4*100]

tanline[x_] := 
      f[x3] + ((0 - f[x3])/(x4 - x3))*(x - x3)

tline = Plot[tanline[x], {x, -0.1, 1.1}];

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

Summary

Value of root as a function of iterations

Here the Newton-Raphson method algorithm is applied to generate the values of the roots, thrue error, absolute relative true error, approximate error, absolute relative approximate error, and the number of significant digits at least correct in the estimated root as a function of number of iterations.

Clear[xr];

SetPrecision[xr, 40]

Array[xr, (Subscript[n, maximum])];

For[i = 1; xr[0] = x0, i <= (Subscript[n, maximum]), i++, 
      xr[i] = xr[i - 1] - f[xr[i - 1]]/g[xr[i - 1]] // N]

xrplot = Table[xr[i], {i, 0, (Subscript[n, maximum])}];

Absolute relative approximate error

Array[ϵa, (Subscript[n, maximum])];

For[i = 1, 
      i <= (Subscript[n, maximum]), i++, ϵa[i] = 
        Abs[(xr[i] - xr[i - 1])/xr[i]*100]]

ϵa[0] = x0;

ϵaplot = 
        Table[ϵa[i], {i, 0, (Subscript[n, maximum]) - 1}];

ListPlot[ϵaplot,PlotJoined -> True, PlotRange -> All, AxesOrigin -> {1, Min[ϵaplot]}, PlotLabel -> "Absolute relative approximate error as a \
function of number of iterations"];