Preface


This tutorial was made solely for the purpose of education and it was designed for students taking Applied Math 0330. It is primarily for students who have very little experience or have never used Mathematica before and would like to learn more of the basics for this computer algebra system. As a friendly reminder, don't forget to clear variables in use and/or the kernel.

Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in normal font. This means that you can copy and paste all commands into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts for your needs to learn the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330
Return to Part III of the course APMA0330

Secant method


In this section, we consider a problem of finding root of the equation \( f(x) =0 \) for sufficiently smooth function f(x). If this equation has a solution, it is called a zero/null of the function f. Every rootfinding problem can be transformed into any number of fixed point problems. Consider the following example.

Example: Let \( f(x) = x^5 -5x+3 \) and we try to find its null, so we need to solve the equation \( x^5 -5x+3 =0 . \) Mathematica provides two real positive roots:

FindRoot[x^5 - 5 x + 3 == 0, {x, 0.5}]
Out[1]= {x -> 0.618034}
FindRoot[x^5 - 5 x + 3 == 0, {x, 1.5}]
Out[2]= {x -> 1.27568}
Solving for x, we convert the original equation into
\[ x = \frac{x^5 +3}{5} \qquad \Longrightarrow \qquad x_{k+1} = \frac{x^5_k +3}{5} , \qquad k=1,2,\ldots . \]
When you try the starting point \( x_0 = 0.5 , \) the fixed point iteration will provide you a very good approximation to the null x = 0.618034. However, when you start with \( x_0 = 1.5 , \) the fixed point iteration will diverge.

Let us add and subtract x from the equation: \( x^5 -5x+3+x =x . \) Expressing x, we derive another fixed point formula

\[ x = x^5 -4x +3 \qquad \Longrightarrow \qquad x_{k+1} = x^5_k -4x_k +3 , \qquad k=1,2,\ldots . \]
Whatever the starting point was chosen, the above fixed point iteration diverges. ■

 

The formula involved in the secant method is very close to the one used in regula falsi:

\[ p_{k+1} = p_k - \frac{f(p_k ) \left( p_k - p_{k-1} \right)}{f (p_k ) - f(p_{k-1} )} , \qquad k=1,2,\ldots . \]
When secant method is applied to find a square root of a positive number A, we get the formula
\[ p_{k+1} = p_k - \frac{p_k^2 -A}{p_k + p_{k-1}} , \qquad k=1,2,\ldots . \]

Example: Let us find a positive square root of 6. To start secant method, we need to pick up two first approximations,which we choose by obvious bracketing: \( x_0 =2, \quad x_1 =3 . \)

\begin{align*} x_2 &= 3 - \frac{9-6}{3+2} = \frac{12}{5} =2.4 , \\ x_3 &= 2.4 - \frac{2.4^2 -6}{2.4+3} = \frac{22}{9} = 2.44444 , \\ x_4 &= \frac{22}{9} - \frac{(22/9)^2 -6}{22/9 + 12/5} = \frac{267}{109} \approx 2.44954 , \\ \vdots & \quad \vdots , \\ x_9 &= \frac{1691303970864713862076027918}{690471954760262617049295761} \approx 2.449489742783178 , \end{align*}
which is a number with 16 correct decimal places.

Example: We consider the function \( f(x) = e^x\, \cos x - x\, \sin x \) that has one root within the interval [0,3]. We define the range of x:

f[x_] := Exp[x]*Cos[x] - x*Sin[x]
xa = 0; xb = 3;
and then plot the function:
curve = Plot[f[x], {x, xa, xb},
PlotLabel -> "Function on given interval", PlotStyle -> {FontSize -> 11, Blue}]
Graph of the function \( f(x) = e^x\, \cos x - x\, \sin x . \)
We make lower initial guess and upper initial guess:
xguess1 = 1.0; xguess2 = 2.0;
and then plot the function along with two guess bounds:
Show[Graphics[Line[{{xguess2, maxi}, {xguess2, mini}}]], curve,
Graphics[Line[{{xguess1, maxi}, {xguess1, mini}}]], Axes -> True,
PlotLabel -> "Function with upper and lower guesses",
PlotStyle -> {FontSize -> 10}, PlotRange -> {{0.7, 2}, {-0.2, 0.4}}]
We make the first iteration:
x1 = xguess2 - (f[xguess2]*(xguess1 - xguess2))/(f[xguess1] - f[xguess2])
1.11361
Plot of the line through two guess points:
m = (f[xguess2] - f[xguess1])/(xguess2 - xguess1);
secantline[x_] = m*x + f[xguess2] - m*xguess2;
sline = Plot[secantline[x], {x, xa, x1}, PlotStyle -> {Orange}]
Show[Graphics[Line[{{xguess2, maxi}, {xguess2, mini}}]],
Graphics[Line[{{x1, maxi}, {x1, mini}}]], curve,
Graphics[Line[{{xguess1, maxi}, {xguess1, mini}}]], sline,
Axes -> True, PlotLabel -> "Function with upper and lower guesses and estimated root",
PlotStyle -> {FontSize -> 10}, PlotRange -> {{0.5, 2}, {-0.25, 0.9}}]
Graph of the function f(x) and root bounds after the first iteration.
It should be noted that these two guesses do not have to bracket the root. We have called the two initial guesses in the way which we have because that will be the format for subsequent iterations. It does not matter which guess is which. Try switching the two initial guesses to see what happens. One should converge faster than the other.

We make the second iteration.

x2 = x1 - (f[x1]*(xguess2 - x1))/(f[xguess2] - f[x1])
1.17199
Then we plot bounds.
m = (f[x1] - f[xguess2])/(x1 - xguess2);
secantline[x_] = m*x + f[x1] - m*x1;
sline = Plot[secantline[x], {x, 1, 1.3}, PlotStyle -> {Orange}]
Show[Graphics[Line[{{xguess2, maxi}, {xguess2, mini}}]],
Graphics[Line[{{x1, maxi}, {x1, mini}}]], curve,
Graphics[Line[{{xguess1, maxi}, {xguess1, mini}}]], sline,
Axes -> True, PlotLabel -> "Function with upper and lower guesses and estimated root",
PlotStyle -> {FontSize -> 10}, PlotRange -> {{0.5, 2}, {-0.25, 0.9}}]
Graph of the function f(x) and root bounds after the second iteration.
Third iteration gives.
x3=x2-(f[x2]*(x1-x2))/(f[x1]-f[x2])
1.23113

 

II. Newton’s Method or Newton--Raphson Method


The following iterative method, named after the English mathematicians Isaac Newton (1642--1726) and Joseph Raphson (1648--1715), used for solving the equation f(x) = 0:
\[ p_{k+1} = p_k - \frac{f(p_k)}{f' (p_k )} , \qquad k=0,1,2,\ldots . \]
The basic idea behind Newton's method is quite straightforward. Let pn denote the most recent approximation to zero, p, of the function f. Replace f by its tangent line approximation that goes through the point pn and takes the x-intercept of the tangent line as the next approximation pn+1 to the root. ■

Newton's method can be realized with the aid of FixedPoint command:

NewtonZero[f_, x0_] := FixedPoint[# - f[#]/f'[#] &, x0]

Example: Suppose we want to find a square root of 4.5. First, we apply NewtonZero command:

NewtonZero[#^2 - 4.5 &, 2.0] (* to solve quadratic equation *)
Out[1]= 2.12132
which is actually 2.1213203435596424 ■

When Newton's method is applied to find a square root of a positive number A, we get the Babylonian formula
\[ p_{k+1} = \frac{1}{2} \left( p_k + \frac{A}{p_k} \right) , \qquad k=0,1,2,\ldots . \]
Ancient Mesopotamia was a civilization that existed in the area of modern Turkey, Syria, Iraq and Iran, between the Mediterranean Sea and the Persian Gulf. In the period 1900--1600 BC, Babylon was the capital city of Mesopotamia and the mathematics recorded at this time came to be known as Babylonian Mathematics. It turns out that Babylonian mathematicians discovered Pythagorean theorem about 1000 years before the ancient Greek mathematician Pythagoras (570--495 BC).

The Babylonians had an accurate and simple method for finding the square roots of numbers. This method is also known as Heron's method, after the Greek mathematician who lived in the first century AD. Indian mathematicians also used a similar method as early as 800 BC. The Babylonians are credited with having first invented this square root method, possibly as early as 1900 BC.

Example: We use Newton's method to find a positive square root of 6. Starting with one of the two initial positions, we get

\begin{align*} p_0 &=2, \quad &p_0 =3.5 , \\ p_1 & = \frac{5}{2} = 2.5, \quad &p_1 = 2.60714, \\ p_2 &= \frac{49}{20} ={\bf 2.4}5 , \quad &p_2 = {\bf 2.4}5426 , \\ p_3 &= \frac{4801}{1960} \approx {\bf 2.4494897}, \quad &p_3 = {\bf 2.4494}943716069653 , \\ p_4 &= \frac{46099201}{18819920} \approx {\bf 2.44948974278317}9 , &p_4 = {\bf 2.44948974278}75517, \\ p_5 &= \frac{4250272665676801}{1735166549767840} \approx {\bf 2.449489742783178} , & p_5 = {\bf 2.449489742783178}. \end{align*}
As we see it converges pretty fast. In fact, this method converges quadratically---the number of correct decimal places approximately doubles with every step!
p[0] = 2
Do[Print["k= ", k, " " , "p= " , p[k] = (p[k - 1] + 6/p[k - 1])/2], {k, 1, 5}]
We can convert the square root problem to a fixed point iteration:
\[ p_{k+1} = \frac{p_k +6}{p_k +1} , \qquad k=0,1,2,\ldots ; \]
which converges to \( \sqrt{6} = 2.449489742783178\ldots , \) but very slowly. However, another suggested iteration
\[ p_{k+1} = 3\,\frac{p_k^2 -1}{2\,p_k} , \qquad k=0,1,2,\ldots ; \]
diverges.

Theorem: Let f be twice continuously differentiable function on the interval [a,b] with \( p \in \left( a, b \right) \quad\mbox{and} \quad f(p) =0 . \) Suppose that \( f' (p) \ne 0. \) Then there exists a positive number δ such that for any \( p_0 \in \left[ p - \delta , p+\delta \right] , \) the sequence \( \left\{ p_n \right\} \) generated by Newton's algorithm converges to p. ■

Sometimes Newton’s method does not converge; the above theorem guarantees that δ exists under certain conditions, but it could be very small. Newton's method is a good way of approximating solutions, but applying it requires some intelligence. You must beware of getting an unexpected result or no result at all. So why would Newton’s method fail? Well, the derivative may be zero at the root (so when the function at one of the iterated points will have zero slope); the function may fail to be continuously differentiable; one of the iterated points xn is a local minimum/maximum of f; and you may have chosen a bad starting point, one that lies outside the range of guaranteed convergence. It may happen that in the Newton--Raphson method, an initial guess close to one root can jump to a location several roots away. Depending on the context, each one of these may be more or less likely. Degenerate roots (those where the derivative is 0) are "rare" in general and we do not consider this case.

Finally, there is a chance that Newton's method will cycle back and forth between two value and never converge at all. This failure is illustrated in Figure below.

a1 = {Arrowheads[Medium], Arrow[{{2.5, 6.875}, {3.5, 4}}]}
a2 = {Arrowheads[Medium], Arrow[{{3.5, 7.125}, {2.5, 4}}]}
b1 = Graphics[{Dashed, Red, a1}]
b2 = Graphics[{Dashed, Blue, a2}]
f[x_] = x^3 - 5*x^2 + 3.05*x + 15
graph = Plot[f[x], {x, 0.5, 4}, PlotRange -> {4, 16}, PlotStyle -> Thick]
v1 = {Arrowheads[Medium], Arrow[{{2.5, 4}, {2.5, 6.875}}]}
v2 = {Arrowheads[Medium], Arrow[{{3.5, 4}, {3.5, 7.125}}]}
b11 = Graphics[{Dashed, Red, v1}]
b22 = Graphics[{Dashed, Blue, v2}]
Show[graph, b1, b2, b11, b22]
For example, take a function \( f(x) = x^2 -2x +1 \) and let start with x0 =0. The first iteration produces 1 and the second iteration returns back to 0, so the sequence will oscillate between the two without converging to a root.

Example: Consider the function \( f(x) = x\,e^{-x^2} \) that obviously has a root at x = 0. However, if your starting point exceeds the root of the equation \( f'(x) = 0 , \) which is \( x_0 = 1/\sqrt{2} \approx 0.707107 , \) than Newton's algorithm diverges.

f[x_]= x*Exp[-x^2]
D[x*Exp[-x^2], x]
FindRoot[E^-x^2 - 2 E^-x^2 x^2 == 0, {x, 1}]
Plot[x*Exp[-x^2], {x, -3, 3}, PlotStyle -> Thick, PlotLabel -> x*Exp[-x^2]]
p[0] = 0.8
Do[Print["k= ", k, " " , "p= " , p[k] = p[k - 1] - p[k - 1]/(1 - 2*p[k - 1])], {k, 1, 15}]
Newton's method diverges for the cube root, which is continuous and infinitely differentiable, except for x = 0, where its derivative is undefined:
\[ x_{k+1} = x_k - \frac{x_k^{1/3}}{(1/3)\,x_k^{-2/3}} = -2\,x_k , \qquad k=0,1,2,\ldots ; \]

Example: Consider the cubic function \( f(x) = x^3 - 0.926\,x^2 + 0.0371\,x + 0.043 . \) First we plot the function, and then define the range of 'x' you want to see its null.

f[x_] := x^3 - 0.926*x^2 + 0.0371*x + 0.043
Plot[f[x], {x, 0, 1}, PlotStyle -> {Thick, Blue}]
xbegin = 0; xend = 0.5;
curve = Plot[f[x], {x, xbegin, xend}, PlotLabel ->
"Function on given interval", PlotStyle -> {Thick, FontSize -> 11}]
   
Taking initial guess
x0 = 0.3
we start Newton's iteration. 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]
maxi = f[xend]; mini = f[xbegin];
step = (xend - xbegin)/10;
Do[ If[f[i] > maxi, maxi = f[i]];
If[f[i] < mini, mini = f[i]], {i, xbegin, xend, step}];
tot = maxi - mini
mini = mini - 0.1*tot; maxi = maxi + 0.1*tot;
We begin with first Newton's iteration.
x1 = x0 - f[x0]/g[x0]
Out[23]= 0.291107
Then we plot tangent line along with given function and bounds for the root.
ea = Abs[(x1 - x0)/x1*100]
Out[24]= 3.05502
tanline[x_]:=f[x0]+((0-f[x0])/(x1-x0))*(x-x0)
tline = Plot[tanline[x], {x, xbegin, xend}, PlotStyle -> {Thick, Orange}]
Show[Graphics[Line[{{x0, maxi}, {x0, mini}}]], curve,
Graphics[Line[{{x1, maxi}, {x1, mini}}]], tline, Axes -> True,
PlotLabel -> "Function with upper and lower guesses and estimated root", PlotStyle -> {FontSize -> 10}]
   
Now we make the second iteration.
x2=x1-f[x1]/g[x1]
Out[25]= 0.291096
Then we compare its value with the actual root obtained with standard Mathematica command.
s = FindRoot[f[x] == 0, {x, 0.3}]
NumberForm[N[s], 20]
Out[26]= {x -> 0.291096}
which is an approximation to more accurate root: 0.291095502695723. Indeed,
f[0.291095502695723]
Out[28]= 0.
This is zero within Mathmatica accuracy. So we see that two iterations are enough to get at least six accurate decimal places. For instance, the third iteration yields
x3=x2-f[x2]/g[x2]
Out[29]= 0.291095502695723

Example: We reconsider the function \( f(x) = e^x\, \cos x - x\, \sin x \) that has one root within the interval [0,3]. We define the range of x:

xa = 0; xb = 3;
We break the guess interval [0,3] into 10 uniform parts and calculate the values of the given function at each end point of these subintervals.
maxi = f[xa]; mini = f[xb];
step = (xb - xa)/10;
x[0] = xa;
Do[ x[i] = x[i - 1] + step; If[f[x[i]] > maxi, maxi = f[x[i]]; If[f[x[i]] < mini, mini = f[x[i]]]];
Print["i= ", i, ", x[i]= ", x[i], ", f[x[i]]= ", N[f[x[i]]]]; , {i, 1, 10}]
So we see that the first root is within the interval [6/5, 3/2]. Let us take the middle of the interval as out first guess:
x0 = (6/5 + 3/2)/2
Out[2]= 27/20
which is 1.35. We set the maximum number of iterations to be 4:
nmaximum = 4
Then we define the derivative of the function f(x) which we denote by g(x).
f[x_] := Exp[x]*Cos[x] - x*Sin[x]
g[x_] := f'[x]
Now we find the actual solution using Mathematica (this is an approximation as well, but with good accuracy)
s = FindRoot[f[x] == 0, {x, 1.35}]
actual = x /. s
NumberForm[N[actual], 20]
Out[7]= 1.2253937841236207
We apply the Newton--Raphson method to generate the values of the roots, true 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, nmaximum];
We generate the sequence of root approximations.
For[i = 1; xr[0] = N[x0], i <= nmaximum, i++,
xr[i] = xr[i - 1] - f[xr[i - 1]]/g[xr[i - 1]]]
Absolute true error:
Array[Et, nmaximum];
For[i = 1, i <= nmaximum, i++, Et[i] = Abs[actual - xr[i]]]
Absolute relative true error:
Array[et, nmaximum];
For[i = 1, i <= nmaximum, i++, et[i] = Abs[Et[i]/actual*100]]
Absolute approximate error:
Array[Ea, nmaximum];
For[i = 1, i <= nmaximum, i++,
If[i <= 1, Ea[i] = Abs[xr[i] - x0], Ea[i] = Abs[xr[i] - xr[i - 1]]]]
Absolute relative approximate error:
Array[ea, nmaximum];
For[i = 1, i <= nmaximum, i++, ea[i] = Abs[Ea[i]/xr[i]*100]]
Significant digits at least correct.
Array[sigdig, nmaximum];
For[i = 1, i <= nmaximum, i++,
If[(ea[i] >= 5) || (i <= 1), sigdig[i] = 0,
sigdig[i] = Floor[(2 - Log[10, Abs[ea[i]/0.5]])]]]
Graphs:
xrplot = Table[xr[i], {i, 1, nmaximum}];
ListPlot[xrplot, Joined -> True, PlotRange -> All,
AxesOrigin -> {1, Min[xrplot]},
PlotLabel -> "Estimated root as a function of number of iterations"]
Root as a number of iterations.

Example: This example shows that Newton's method may converge slowly due to an inflection point occurring in the vicinity of the root. Let us consider the function \( f(x) = (x-0.5)^3 . \) First we define the function and its derivative:

f[x_] := (x-0.5)^3
g[x_] := f'[x]
Then we plot the function:
xbegin = -2; xend = 3;
curve = Plot[f[x], {x, xbegin, xend},
PlotLabel -> "Function on given interval", PlotStyle -> {FontSize -> 11, Blue}]
Graph of the function \( f(x) = (x-0.5)^3 . \)
Next we define the initial guess and maximum number of iterations.
x0 = -1; nmaximum = 10;
First iteration.
x1 = x0 - f[x0]/g[x0]
Out[16]= -0.5
ea = Abs[(x1 - x0)/x1*100]
Out[17]= 100
tanline[x_] := f[x0] + ((0 - f[x0])/(x1 - x0))*(x - x0)
tline = Plot[tanline[x], {x, -1.5, 0.0}, PlotStyle -> {Orange}];
Show[curve, tline, Graphics[Line[{{x0, 2}, {x0, -15}}]],
Graphics[Line[{{x1, 2}, {x1, -15}}]], Axes -> True, PlotRange -> All,
PlotLabel -> "Function with upper and lower guesses and estimated root", PlotStyle -> {FontSize -> 10}]
Tangent to the function f(x) and two bounds.
We start the second iteration.
x2 = x1 - f[x1]/g[x1]
Out[24]= -0.166667
ea = Abs[(x2 - x1)/x2*100]
Out[25]= 200
Then we plot tangent line.
tanline[x_]:=f[x1]+((0-f[x1])/(x2-x1))*(x-x1)
tline = Plot[tanline[x], {x, -1, 1}, PlotStyle -> {Orange}];
Show[Graphics[Line[{{x1, 0.6}, {x1, -1}}]], curve,
Graphics[Line[{{x2, 0.6}, {x2, -1}}]], tline, Axes -> True,
PlotLabel -> "Second iteration and estimated root", PlotStyle -> {FontSize -> 10}, PlotRange -> {{-1, 1}, {-1, 0.7}}]
Second iteration and two bounds.
Third iteration,
x3 = x2 - f[x2]/g[x2]
Out[38]= 0.0555556
ea = Abs[(x3 - x2)/x3*100]
Out[39]= 400
and then fourth iteration.
x4=x3-f[x3]/g[x3]
Out[40]= 0.203704
ea = Abs[(x4 - x3)/x4*100]
Out[41]= 72.7273
So we see that convergence is very slow. ■

 

III. Chebyshev Iteration Scheme


The Chebyshev iteration is an iterative method for determining the solutions of a system of linear equations \( f(x) =0. \) The method is named after Russian mathematician Pafnuty Chebyshev (1821--1894), who discoved it in 1838 as a student project (but not published until 1951).
\[ x_{k+1} = x_k - \frac{f( x_k )}{f' (x_k )} - \frac{f(x_k ) \, f'' (x_k )}{2\left( f' (x_k ) \right)^3} , \qquad k=0,1,2,\ldots . \]
When Chebyshev iteration scheme is applied to solve a quadratic equation \( x^2 -A =0, \) it leads to
\[ p_{k+1} = \frac{1}{2} \left( p_k + \frac{A}{p_k} \right) - \frac{\left( p_k^2 -A \right)^2}{8\,p_k^3} , \qquad k=0,1,2,\ldots . \]

Example: Let us reconsider the problem of determination of a positive square root of 6 using Chebyshev iteration scheme:

\[ p_{k+1} = \frac{1}{2} \left( p_k + \frac{6}{p_k} \right) - \frac{\left( p_k^2 -6 \right)^2}{8\,p_k^3} , \qquad k=0,1,2,\ldots . \]
\begin{align*} p_0 &=2, \qquad &p_0 =3, \\ p_1 &= \frac{39}{16} = 2.4375 , \quad &p_1 = \frac{59}{24} \approx 2.4583\overline{3} , \\ p_2 &= \frac{2066507}{843648} \approx {\bf 2.449489}597557 , \quad & p_2 = \frac{32196721}{13144256} \approx {\bf 2.4494897}999 , \\ p_3 &= \frac{48631344989193667537677361}{19853663454796665627720704} \approx {\bf 2.449489742783178}, \quad &p_3 = \frac{8596794666982120560353042061123}{3509626726264305284645257635328} \approx {\bf 2.449489742783178} . \end{align*}
p[0] = 2
Do[Print["k= ", k, " " , "p= " , p[k] = (p[k - 1] + 6/p[k - 1])/ 2 - (p[k - 1]^2 - 6)^2/(8*p[k - 1]^3)], {k, 1, 5}]
So we see that the third iteration gives an approximation with 16 correct decimal places.

 

IV. Halley's Method


The English astronomer, geophysicist, mathematician, meteorologist, and physicist Edmund/Edmond Halley (1656--1741) discovered the following iteration algorithm
\[ x_{k+1} = x_k - \frac{f( x_k )}{f' (x_k ) - \frac{f(x_k ) \, f'' (x_k )}{2\, f' (x_k )}} , \qquad k=0,1,2,\ldots ; \]
in 1694. He is well known for first predicting the orbit of the comet that bears his name. Usually Halley's formula makes the convergence of the process of iteration extremely rapid when the first approximation is fairly close to the null. For example, application of Halley's method to solving the quadratic equation \( x^2 -A =0 \) leads to the recurrence
\[ x_{k+1} = x_k - \frac{2x_k \left( x_k^2 -A \right)}{3x_k^2 +A} , \qquad k=0,1,2,\ldots ; \]

Example: Let us find a few iterations for determination of a square root of 6:

\begin{align*} p_0 &=2, \qquad &p_0 =3, \\ p_1 &= \frac{22}{9} \approx 2.4\overline{4} , \quad &p_1 = \frac{27}{11} \approx 2.45\overline{45} , \\ p_2 &= \frac{21362}{8721} \approx {\bf 2.4494897}37 , \quad & p_2 = \frac{26163}{10681} \approx {\bf 2.44948974}81 , \\ p_3 &= \frac{19496458483942}{7959395846169} \approx {\bf 2.449489742783178}, \quad &p_3 = \frac{23878187538507}{9748229241971} \approx {\bf 2.449489742783178} . \end{align*}
p[0] = 2
Do[Print["k= ", k, " " , "p= " , p[k] = p[k - 1] - 2*p[k - 1]*(p[k - 1]^2 - 6)/(3*p[k - 1]^2 + 6)], {k, 1, 5}]
So we see that the third iteration gives an approximation with 16 correct decimal places.

 

V. Dekker's Method


Brent's method is a root-finding algorithm combining the bisection method, the secant method and inverse quadratic interpolation. It has the reliability of bisection but it can be as quick as some of the less reliable methods. The algorithm tries to use the potentially fast-converging secant method or inverse quadratic interpolation if possible, but it falls back to the more robust bisection method if necessary. Brent's method was discovered in 1973 by Richard Peirce Brent (born in 1946, Melbourne). He is an Australian mathematician and computer scientist. Richard is an emeritus professor at the Australian National University and a conjoint professor at the University of Newcastle (Australia). Brent's method is based on an earlier algorithm of 1969 proposed by Theodorus Jozef Dekker (born in 1927). Theodorus is a Dutch mathematician who completed his Ph.D degree from the University of Amsterdam in 1958. Consequently, the method is also known as the Brent--Dekker method.

The idea to combine the bisection method with the secant method goes back to Dekker (1969). Suppose that we want to solve the equation f(x) = 0

. As with the bisection method, we need to initialize Dekker's method with two points, say a0 and b0, such that \( f \left( a_0 \right) \quad\mbox{and} \quad f \left( b_0 \right) \) have opposite signs. If f is continuous on \( \left[ a_0 , b_0 \right] , \) the intermediate value theorem guarantees the existence of a solution between a0 and b0.

Three points are involved in every iteration:

Two provisional values for the next iterate are computed. The first one is given by linear interpolation, also known as the secant method:
\[ s = \begin{cases} b_k - \frac{b_k - b_{k-1}}{f\left( b_k \right) - f\left( b_{k-1} \right)} \, f\left( b_k \right) , & \quad \mbox{if} \quad f\left( b_k \right) \ne f\left( b_{k-1} \right) , \\ m , & \quad \mbox{otherwise} \end{cases} \]
and the second one is given by the bisection method
\[ m = \frac{a_k -b_k }{2} . \]
If the result of the secant method, s, lies strictly between bk and m, then it becomes the next iterate (bk+1 = s), otherwise the midpoint is used (bk+1 = m).

Then, the value of the new contrapoint is chosen such that \( f \left( a_{k+1} \right) \quad\mbox{and} \quad f \left( b_{k+1} \right) \) have opposite signs. If \( f \left( a_k \right) \quad\mbox{and} \quad f \left( b_{k+1} \right) \) have opposite signs, then the contrapoint remains the same: ak+1 = ak. Otherwise, \( f \left( b_{k+1} \right) \quad\mbox{and} \quad f \left( b_{k} \right) \) have opposite signs, so the new contrapoint becomes ak+1 = bk.

Finally, if \( \left\vert f \left( a_{k+1} \right) \right\vert < \left\vert f \left( b_{k+1} \right) \right\vert , \) then ak+1 is probably a better guess for the solution than bk+1, and hence the values of ak+1 and bk+1 are exchanged.

This ends the description of a single iteration of Dekker's method. ■

Dekker's method performs well if the function f is reasonably well-behaved. However, there are circumstances in which every iteration employs the secant method, but the iterates bk converge very slowly (in particular, \( \left\vert b_k - b_{k-1} \right\vert \) may be arbitrarily small). Dekker's method requires far more iterations than the bisection method in this case.

 

VI. Brent's Method


Brent (1973) proposed a small modification to avoid this problem. He inserted an additional test which must be satisfied before the result of the secant method is accepted as the next iterate. Therefore, Brent's method is a hybrid method which combines the reliability of bracketing method and the speed of open methods.

Two inequalities must be simultaneously satisfied: Given a specific numerical tolerance δ if the previous step used the bisection method, the inequality

\[ |\delta | < \left\vert b_k - b_{k-1} \right\vert \]
must hold to perform interpolation, otherwise the bisection method is performed and its result used for the next iteration.

If the previous step performed interpolation, then the inequality

\[ |\delta | < \left\vert b_{k-1} - b_{k-2} \right\vert \]
is used instead to perform the next action (to choose) interpolation (when inequality is true) or bisection method (when inequality is not true).

Also, if the previous step used the bisection method, the inequality

\[ \left\vert s- b_k \right\vert < \frac{1}{2} \left\vert b_k - b_{k-1} \right\vert \]
must hold, otherwise the bisection method is performed and its result used for the next iteration. If the previous step performed interpolation, then the inequality
\[ \left\vert s- b_k \right\vert < \frac{1}{2} \left\vert b_{k-1} - b_{k-2} \right\vert \]
is used instead.

Brent proved that his method requires at most N2 iterations, where N denotes the number of iterations for the bisection method. If the function f is well-behaved, then Brent's method will usually proceed by either inverse quadratic or linear interpolation, in which case it will converge superlinearly.

Furthermore, Brent's method uses inverse quadratic interpolation instead of linear interpolation (as used by the secant method). If \( f(b_k ), \ f(a_k ) , \mbox{ and } f(b_{k-1}) \) are distinct, it slightly increases the efficiency. As a consequence, the condition for accepting s (the value proposed by either linear interpolation or inverse quadratic interpolation) has to be changed: s has to lie between \( \left( 3 a_k + b_k \right) /4 \) and bk.

 

 

Return to Mathematica page

Return to the main page (APMA0330)
Return to the Part 1 (Plotting)
Return to the Part 2 (First Order ODEs)
Return to the Part 3 (Numerical Methods)
Return to the Part 4 (Second and Higher Order ODEs)
Return to the Part 5 (Series and Recurrences)
Return to the Part 6 (Laplace Transform)
Return to the Part 7 (Boundary Value Problems)