Topic : Newton Raphson Method - Roots of Equations
Simulation : Pitfall - Zero Slope
Language : Mathmatica 4.1
Authors : Nathan Collier, Autar Kaw
Date : 11 July 2002
Abstract : This simulation illustrates a pitfall of zero slope in the Newton-Raphson method of finding roots of f(x)=0.

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;
(Subscript[x, end]) = 10;

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

Initial guess

x0 = π/2;

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}];