The Secant Method

The focus of this lecture was on the secant method. In the same style of the bisection method is an m-file to run the secant method in MATLAB :
function [x,fail] = secant(f,x1,x2,eps,N)
%
%  Applies the secant method to the function f, starting
%  at the points x1 and x2.  It produces a sequences of points.
%  Stops when the sequence reaches the point x where 
%  |f(x)| < eps or when two consecutive points in the sequence
%  have distance less than eps apart from each other.
%  Failure is reported (fail = 1) when the accuracy requirement
%  is not satisfied in N steps; otherwise fail = 0 on return.
%
%  Note that the implementation below is inefficient, as it does
%  not store the function evaluations.
%
%  Example : 
%  >> [x,fail] = secant('cos',pi/4,2*pi/3,0.0001,100)
%
fprintf('running the secant method...\n');
for i = 1:N 
   fx2 = feval(f,x2);
   fx1 = feval(f,x1);
   dx =  fx2*(x2 - x1)/(fx2 - fx1);
   x1 = x2;
   x2 = x2 - dx;
   fx2 = feval(f,x2);
   fprintf('  x = %e, dx = %e, f(x) = %e, \n', x2, dx, fx2);
   if (abs(fx2) < eps) | (abs(dx) < eps)
      x = x2; fail = 0;
      fprintf('succeeded after %d steps\n', i);
      return;
   end
end
fprintf('failed requirements after %d steps\n', N);
x = x2; fail = 1;

The output of this algorithm on cos(x) = 0 with x1 = pi/4 and x2 = 2*pi/3] :

>> [x,fail] = secant('cos',pi/4,2*pi/3,0.0001,100);
running the secant method...
  x = 1.552191e+00, dx = 5.422043e-01, f(x) = 1.860444e-02, 
  x = 1.571642e+00, dx = -1.945106e-02, f(x) = -8.455484e-04, 
  x = 1.570796e+00, dx = 8.455951e-04, f(x) = 4.656797e-08, 
succeeded after 3 steps

Note that the bisection method, taking a = x1 and b = x2, requires 13 steps to achieve the same accuracy.

Thus the secant method is faster than the bisection method, but note that it is quite easy (as we did in class) to construct examples where the secant method fails.

Looking at the relations between errors of consecutive steps, we said that the bisection method converges linearly, while the rate of convergence of the secant method (if it converges to a root with nonzero first and second derivatives) is superlinear. We stated the theorem and outlined the proof of "the convergence of the secant method is superlinear". See also the lecture notes of Professor Hanson, in particular the notes on the convergence of the secant method.

As we will see next time, Newton's method can be interpreted as "secant method in the limit". Newton's method converges quadratically, doubling in each step the number of correct decimal places in the approximation for the solution. The superlinear convergence of the secant method comes close to achieving the same rate of quadratic convergence. See the example above: the magnitude of f(x) goes from 10^(-2), to 10^(-4), to 10^(-8).