Course Webpage

Secant method

The secant method can be considered a variant of Newton's method in which the derivative is replaced by an approximation.

We can define the derivative of a function $f$ at a point $a$ as

$$f'(a)=\lim_{h\rightarrow 0}\frac{f(a+h)-f(a)}{h}$$

If $x=a+h$ then $h=x-a$

$$f'(a)=\lim_{x\rightarrow a}\frac{f(x)-f(a)}{x-a}$$

also

$$f'(a)=\lim_{x\rightarrow a}\frac{f(a)-f(x)}{a-x}$$

If $a = x_{k-1}$ and $x = x_{k-2}$

$$f'(x_{k-1})=\lim_{x_{k-2}\rightarrow x_{k-1}}\frac{f(x_{k-1})-f(x_{k-2})}{x_{k-1}-x_{k-2}}$$

Removing the limit we obtain

$$f'(x_{k-1})\approx \frac{f(x_{k-1})-f(x_{k-2})}{x_{k-1}-x_{k-2}}$$

If the iteration formula for Newton's method is

$$x_k=x_{k-1}-\dfrac{f(x_{k-1})}{f'(x_{k-1})}$$

and we substitute the derivative by its approximation

$$x_k=x_{k-1}-f(x_{k-1})\dfrac{x_{k-1}-x_{k-2}}{f(x_{k-1})-f(x_{k-2})}$$

Graphically, the secant method can be explained as an iterative method where

  • The curve is replaced by a straight line that passes through two of its points (secant line)
  • The zero of the curve is approximated with the zero of the straight line.
  • The oldest point is discarded (important!), and a new secant line is drawn with the point that remains and the last calculated point.
  • We repeat until a stop condition is met.

That is, we start with

  • $x_0$ and $x_1$ and we obtain $x_2.$

Next

  • $x_1$ and $x_2$ and we obtain $x_3.$

And so on.

Algorithm

  • Given two initial guesses $x_0$ and $x_1$
  • For $k=2,3\ldots,\mathrm{MaxNumIter}$:
    • Compute $x_k=x_{k-1}-f(x_{k-1})\dfrac{x_{k-1}-x_{k-2}}{f(x_{k-1})-f(x_{k-2})}$
    • If $x_k$ meets the stopping condition, stop.
    • Else, perform another iteration.

Drawbacks

  • We need two initial guesses.
  • In general, it converges more slowly than Newton (but faster than bisection).
  • If we do not select the initial points well, it may not converge.

Advantages

  • We don't need to know the exact derivative, just the value of the function.
  • The speed of convergence is relatively fast. The order of convergence is $p\approx1.6$

Exercise

Approximate, using the secant method $r=\sqrt{3}.$ Use as initial guesses $x_{0}=1$ and $x_{1}=2$. Perform 3 iterations

Our equation is

$$x=\sqrt{3} \quad \Rightarrow \quad x^2=3 \quad \Rightarrow \quad x^2-3=0$$

Therefore $f(x)=x^2-3$

The iteration formula is

$$x_k=x_{k-1}-f(x_{k-1})\dfrac{x_{k-1}-x_{k-2}}{f(x_{k-1})-f(x_{k-2})}$$

In this case

$$x_k=x_{k-1}-(x_{k-1}^2-3)\dfrac{x_{k-1}-x_{k-2}}{(x_{k-1}^2-3)-(x_{k-2}^2-3)}$$

Iterations

  • $x_0=1$, $x_1=2$ $$x_2=x_{1}-(x_{1}^2-3)\dfrac{x_{1}-x_{0}}{(x_{1}^2-3)-(x_{0}^2-3)}=2-(2^2-3)\dfrac{2-1}{(2^2-3)-(1^2-3)}$$
$$x_2=2-(1)\dfrac{1}{(1)-(-2)}=2-\dfrac{1}{3}=1.666667$$
  • $x_1=2$, $x_2=1.666667$, $$x_3=x_{2}-(x_{2}^2-3)\dfrac{x_{2}-x_{1}}{(x_{2}^2-3)-(x_{1}^2-3)}$$
$$x_3=1.666667-(1.666667^2-3)\dfrac{1.666667-2}{(1.666667^2-3)-(2^2-3)}=1.727273$$
  • $x_2=1.666667$, $x_3=1.727273$, $$x_4=x_{3}-(x_{3}^2-3)\dfrac{x_{3}-x_{2}}{(x_{3}^2-3)-(x_{2}^2-3)}$$
$$x_4=1.727273-(1.727273^2-3)\dfrac{1.727273-1.666667}{(1.727273^2-3)-(1.666667^2-3)}=1.732143$$
\begin{array}{|cc|} \hline k & x_k \\ \hline 0 & 1.000000\\ 1 & 2.000000\\ 2 & 1.666667\\ 3 & 1.727273\\ 4 & 1.732143\\ \hline \end{array}

Compute the residual

The value of the function at the root is zero. The value of the function in the approximation is called residual and, if it is a good approximation, it is a small

$$r =|f(x_4)|=|1.732143^2-3|=0.0003$$

Also, the residual in step $k$ is known, while the error is unknown (we need the exact solution, which is what we are looking for).

Use a calculator to estimate the absolute error of the approximation

As $\alpha= 1.732051$ the absolute error is

$$e_a = |x_4-\alpha|=|1.732143-1.732051|=0.000092\approx 0.0001$$