Choosing a method: which tool for which problem
A lab session after all the root-finding methods: what each one needs and what it risks, problems with stated assumptions and costs, and the habit of changing method in the middle of a run when the numbers say the plan is not working.
Last updated:
What the choice depends on
The unit gave you bisection and regula falsi, the secant method and Newton–Raphson, and fixed-point iteration.
Each has strengths and weaknesses. Which one fits depends on what you know about the problem and on what each evaluation costs:
is a sign change known, is a derivative available and is it cheap, is the function expensive to evaluate, is the start close to the root?
| Method | What it needs | What it gives | How it fails |
|---|---|---|---|
| Bisection | a bracket (a sign change) and continuity | always closes in; the bracket halves every step | slow; a sign change without a root fools it |
| Regula falsi | a bracket | uses the values, usually faster | one end can stay fixed, and the steps crawl |
| Secant | two starting points, no derivative | fast, one evaluation per step | can jump away, or meet two points of equal height |
| Newton–Raphson | the derivative and a start near the root | the fastest, the error is squared at each step | cycles, flat slopes fling it away, the derivative may be costly |
An assumption can turn out to be wrong, and a start can turn out to be bad.
The habit this session trains is to look at the numbers while a method runs, and to be willing to change method in the middle, instead of locking onto a path that went wrong from the beginning.
When and why to choose each method
The previous table describes each method. This table starts from the side of the problem:
what you know, which method to try first, and why.
| What you know | What to choose first | Why |
|---|---|---|
| There is a bracket, and certainty matters | Bisection | Only a bracket guarantees that the root is inside. It halves at every step, so the number of steps is known in advance. |
| There is a bracket, and is expensive | Regula falsi (or the secant method started from the ends of the bracket, without a guarantee that the root stays inside) | They use the values and not only the signs, and each step costs one evaluation of . When one end stays fixed and (the ratio of the errors, see the convergence rate) regula falsi is slower than bisection. |
| There is a bracket, and you want both speed and certainty | Brent’s method (brentq) | Fast steps inside the bracket, and bisection when the fast step is not good. This is a common choice in libraries, for example brentq in SciPy. |
| No bracket, a cheap derivative, and a start near the root | Newton–Raphson | Order of convergence 2: the correct digits double at every step. |
| No bracket, and no derivative or an expensive one | The secant method | Order of convergence and one evaluation per step. When the derivative costs as much as , the secant method gains more digits per evaluation of ( instead of ). |
| The problem is already written as , and near the solution | Fixed-point iteration | The simplest to code. The error shrinks by a factor at each step, so convergence is linear, and slow when is close to 1. |
Ask in this order:
- Is there a bracket? If so, keep it as a safety net. Without it none of the methods of this unit guarantees that the steps approach the root of every continuous function.
- Does the derivative exist and is it cheap? If so, Newton is the fastest, and it fits when the start is near the root. From far away a nearly flat tangent flings the next point farther.
- If there is no derivative or it is expensive, the secant method.
- And if the numbers do not advance (the step does not shrink, grows, or there is a cycle), change method: go back to the bracket, or move to another method.
The Order and Rate of Convergence of the Four Methods
| Method | Order | The constant in the limit | Speed |
|---|---|---|---|
| Bisection | (for the bound ) | digits per step and per evaluation | |
| Regula falsi (a fixed end, a convex function) | digits per step and per evaluation | ||
| Secant | the digits ×1.618 per step and per evaluation | ||
| Newton–Raphson | the digits ×2 per step, ×1.414 per evaluation |
In the table .
Why is there no rate in all the methods? The rate is the limit of .
When the order is greater than 1 this limit is : the error shrinks faster than any fixed ratio, so it does not describe the method.
What describes it is the order and the constant in the relation .
What is the factor of the digits per evaluation? A method of order multiplies the number of correct digits by at each step.
If a step costs evaluations, the factor per evaluation is .
Newton with two evaluations per step ( and ) gives , and the secant method with one evaluation per step gives .
So when costs as much as , the secant method gains digits faster per evaluation.
For methods of order 1 a fixed number of digits is added per evaluation, and there is no multiplicative factor.
Bisection or regula falsi: the shape of the function decides
Both methods start from a bracket and cost one evaluation of per step, so the number of steps is a fair comparison.
Bisection has the same guaranteed rate for every function: its bound halves at every step (, which is digits per step).
The rate of regula falsi depends on the function. When one end stays fixed it is , where is the slope of the chord from the fixed end to the root (we derived it on the page about the rate of convergence, where the fixed end is called ; here it is the right end).
The data: on , with the root and tolerance .
Here the fixed end is , so . Regula falsi stops when the true error is below , which we can check here because we know the root; in practice we do not know it, and a program stops on the step and the residual.
- : ( digits per step), 8 steps.
- : ( digits per step), 11 steps.
- : ( digits per step), 15 steps.
- : ( digits per step), 24 steps.
- : ( digits per step), 39 steps.
- : ( digits per step), 61 steps.
- : ( digits per step), 605 steps.
Bisection needs steps for every . This is the guaranteed bound on the width of the bracket; the actual error can be smaller than the bound.
The case is the preset Fixed end: x^10 − 1 in the explorer of the lesson on regula falsi; the explorer stops by the rule of the conventions (the step and the residual), so its step counts are not the counts of this list.
The rule: in the long run regula falsi gains more digits per step than bisection when and fewer when .
In this family passes as the function becomes very steep on one side (a high power).
Predict, then play
Work it out before you open the lab. For each situation, which method would you take first, and what would make you switch?
- A bracket is known, costs 10 units to evaluate, and no derivative exists.
- A bracket is known, the derivative has a closed formula and costs almost nothing, and your starting point is far from the root.
- No bracket is known (the function only touches zero), and the derivative is cheap.
Solution
- The secant method or regula falsi: every step costs one evaluation of , and bisection needs 27 evaluations for accuracy on a bracket of width 1, which at 10 units each is expensive. If the secant method starts to jump around, fall back on the bracket.
- Do not start with Newton: from far away the tangents are nearly flat and fling the next point even farther. Use the bracket first (bisection or regula falsi) until the point is close, then switch to Newton, whose derivative is nearly free.
- Bisection and regula falsi are impossible: there is no sign change. Newton or the secant method, and expect a slow, linear approach, because at a double root and vanish together, that is, the slope tends to zero.
The same problem in a smaller format
The bond of the bisection practice was solved in binary64. Suppose the program stores every number in binary32 instead, where .
By the formula for the gap, the gap beside the price 94.6 is and the gap beside the yield 0.05 is .
Near the root falls by about 585 for each unit of .
Here is the annual yield, and is the bond price computed at yield minus the market price 94.6.
The root is the yield that reproduces the market price, about 5%.
Work it out:
- By how much does change when changes by one gap of the price?
- Bisection halves the bracket until it is one gap wide beside the yield. Can we be sure that the true yield lies inside that last bracket?
Solution
- , more than three times the gap beside the yield. This is only a lower bound on the uncertainty of . The sum has 15 terms, each rounded, and every addition is rounded too (accumulation), so the computed can be off by several gaps of the price. In a simulation of binary32 arithmetic that we ran, the computed differed from the true one by up to (about 9 gaps of the price) near the root, which is in .
- No. The last bracket is wide, narrower than the that a single gap of the price corresponds to, so a computed sign of near the root can be wrong and the bracket can close away from the root. The bracket guarantees the root only for the signs the program computes. In the same simulation the bracket ended wide with the yield about outside it, about 26 widths. In binary64 the same happens, but the miss is (about twelve widths of ), about a millionth of the tolerance that the bisection lesson used.
| The bond of the practice, bisection, up to 60 steps (simulation) | binary64 | binary32 |
|---|---|---|
| Gap beside the price 94.6 | ||
| Smallest reached | ||
| Width of the last bracket | ||
| Distance of the yield from it (about) | ||
| Step and both below | after 39 steps | not within 60 steps |
| Step below and below | after 19 steps | after 19 steps |
Procedure: how to run a method
- Check what is known: is there a bracket ( and continuous), is there a derivative, and what does each evaluation cost.
- Choose a method by the table above, set the starting points (two ends, two points or one point), a tolerance and a ceiling on the number of steps.
- Fill in a table after every step: , the estimate, at the estimate, the step and the residual (the course conventions).
- Check at every step: are both the step and small, is the denominator nonzero, and does the estimate stay inside the bracket.
- Stop when both the step and are below the tolerance, or when the ceiling is reached.
- Report the estimate, the number of steps and the estimate of the error, and if a method was changed say when and why.
- If the numbers do not advance, change method: go back to the bracket, or move to another method.
The lab
Choose a problem. The panel on the right lists what you know and what each evaluation costs.
Take a step with the method you chose, and watch the numbers:
the step, , the bracket and the cost. Every third step a checkpoint asks whether to keep your plan.
Switch as often as you like. The run ends when the step and are both small, when the budget runs out, or when you declare that there is no root.
The lab needs JavaScript. The table above lists what each method needs and how it fails.
Discussion: changing course
After a few problems, compare your decisions with those of the person next to you.
- Which signals made you switch (steps that grew, that grew, a flat slope, a cycle, a cost that ran away)?
- Did you ever stay with a method for too long? What would have told you earlier?
- In which problem did a pure method win, and in which did a switch win? What did the switch cost?
- One problem has no root although the sign changes. Which number told you, and which method would not have?
A written task
Write a switching rule for a program that solves when a bracket is known and the derivative is cheap:
when does it use bisection, when Newton, and when does it go back?
Give two signals that make it go back, and say what the program does if neither method makes progress.
Hint
Think of Newton as the fast method and of the bracket as the safety net.
A good program takes the fast step only if it stays inside the bracket, and checks that decreased.
What we take from the unit
- Every method is a bet on an assumption. Bisection bets on continuity and a sign change, Newton on a derivative and a start near the root, the secant method on a smooth function, fixed-point iteration on a factor , Brent’s method on being able to keep a bracket while trying fast steps.
- Speed and safety trade against each other. The ladder runs from bisection (the error is halved each step) through regula falsi (linear) and the secant method (1.62) and inverse quadratic interpolation (1.84) to Newton (the error is squared). The faster the method, the more it asks of the problem.
- A run is a conversation with the numbers. Check the step and together, watch the trends, and be ready to change method: a bracket as a safety net, a fast method inside it.
- The cost is part of the problem. An expensive favours methods with few evaluations; a derivative that comes for free favours Newton; a derivative that costs more than favours methods without one, such as the secant method.
- A claim that was not checked can be false. A sign change without continuity is not a root.
Continue learning
The course conventions fix the two checks that end every run here, the step and .
The practice for unit 2 asks questions on all the methods, to solve on paper.