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, Newton–Raphson and the secant method, 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.
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 |
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.