Topic : Secant Method - Roots of Equations
Simulation : Graphical Simulation of the Method
Language : Mathmatica 4.1
Authors : Nathan Collier, Autar Kaw
Date : 2 July 2002
Abstract : This simulation shows how the secant method for finding roots of an equation f[x] = 0 works.

INPUTS: Enter the Following

Function in f[x] = 0

f[x_] := Sin[x]

Range of 'x' you want to see the function

(Subscript[x, b]) = -10;
(Subscript[x, e]) = 10;

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

Lower initial guess

xguess1 = 3*Pi/4;

Upper initial guess

xguess2 = Pi/4;

SOLUTION

Check first if the lower and upper guesses bracket the root of the equation

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

Iteration 1

Choose two initial guesses of root.

x1' = xguess1;
x0 = xguess2;

Estimate of root

x1 = x0 - (f[x0]*(x1' - x0))/(f[x1'] - f[x0])

Absolute relative approximate error

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

m = (f[x0] - f[x1'])/(x0 - x1');
secantline[x_] = m*x + f[x0] - m*x0;

sline = Plot[secantline[x], {x, (Subscript[x, b]), (Subscript[x, e])}];

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