Quiz: bisection and fixed-point iteration
Short questions to test your understanding of bisection, fixed-point iteration and steady states of population models. Try each on paper first, then open the answer.
Q1. What is a bracket for a root of \(f\), and what does \(f\) need for a bracket to guarantee a root?
Think of drawing the graph of \(f\) from \((a, f(a))\) to \((b, f(b))\) without lifting the pen.
An interval \([a, b]\) where \(f(a)\) and \(f(b)\) have opposite signs. If \(f\) is continuous on \([a, b]\), the intermediate value theorem guarantees a root inside. Without continuity there is no guarantee: \(1/(x - 1)\) changes sign on \([0, 3]\) but has no root.
Q2. You bisect on the bracket \([0, 8]\) until the bracket is narrower than \(10^{-6}\). How many steps does it take, and does the answer depend on \(f\)?
After \(k\) steps the width is \(8/2^k\).
\(8/2^k < 10^{-6}\) needs \(k > \log_2(8\times10^6) = 22.9\), so 23 steps. It does not depend on \(f\) at all (as long as the bracket is valid): bisection only uses the sign of \(f\).
Q3. Your bisection returns \(x = 0.9999999991\), and you find \(f(x) \approx -10^9\). What happened, and how could you have caught it?
What can make a continuous-looking function change sign without passing through zero?
The bracket contained a pole (for example \(f(x) = 1/(x - 1)\)): \(f\) changes sign by jumping through \(\pm\infty\), and bisection closed in on the jump. Always evaluate \(f\) at the returned root (the residual) and plot \(f\) over the bracket before trusting the answer.
Q4. What do these lines do, and why?
uniroot(function(x) (x - 2)^2, c(0, 5))from scipy.optimize import brentq
brentq(lambda x: (x - 2)**2, 0, 5)// rust/examples/bisection_fixedpoint_q4.rs — cargo run --example bisection_fixedpoint_q4
// Q4: a double root has no sign change, so Brent's method (argmin) refuses to start.
use argmin::core::{CostFunction, Error, Executor};
use argmin::solver::brent::BrentRoot;
struct Square;
impl CostFunction for Square {
type Param = f64;
type Output = f64;
fn cost(&self, x: &f64) -> Result<f64, Error> {
Ok((x - 2.0).powi(2)) // (x - 2)^2: root at 2, but never negative
}
}
fn main() {
match Executor::new(Square, BrentRoot::new(0.0, 5.0, 1e-10)).run() {
Ok(res) => println!("{}", res),
Err(e) => println!("{e}"),
}
}
// Output:
// BrentRoot error: f(min) and f(max) must have different signs.What is the sign of \((x - 2)^2\) at 0, at 5, and anywhere else?
All three stop with an error: R says f() values at end points not of opposite sign, Python raises ValueError: f(a) and f(b) must have different signs, and Rust prints BrentRoot error: f(min) and f(max) must have different signs. The function has a double root at 2: it touches zero without changing sign, so no bracketing method can find it. The harvested fish stock at its largest sustainable catch (\(H \approx 14.26\)) is exactly this case.
Q5. A fixed-point iteration has \(g'(x^*) = -0.8\). Describe what the iterates do near \(x^*\), and roughly how many steps it takes to gain one decimal digit.
\(e_{k+1} \approx g'(x^*)\,e_k\). How many factors of 0.8 make 0.1?
The iteration converges, because \(|g'(x^*)| < 1\), but the error changes sign every step: the iterates alternate above and below \(x^*\) (a spiral in the cobweb plot). The error shrinks by 0.8 per step, so one digit takes \(\log 10/\log(1/0.8) \approx 10\) steps.
Q6. The Beverton–Holt model \(N_{t+1} = R N_t/(1 + (R-1)N_t/K)\) has \(g'(K) = 1/R\). With \(R = 4\), how fast does a population return to \(K\)? Can a Beverton–Holt population ever oscillate around \(K\)?
What is the sign and size of \(1/R\) for \(R > 1\)?
Near \(K\) the deviation shrinks by a factor \(1/R = 0.25\) each year. For \(R > 1\), \(0 < 1/R < 1\), so the return is always monotone (a staircase in the cobweb plot): Beverton–Holt populations never overshoot \(K\) and never oscillate, whatever \(R\). Ricker populations can, because \(g'(K) = 1 - r\) becomes negative for \(r > 1\).
Q7. You simulate the Ricker model \(N_{t+1} = N_t e^{r(1 - N_t/K)}\) with \(r = 2.5\) and see the population alternate between two values forever. Does the steady state \(N^* = K\) still exist? Why does the simulation not find it?
Compute \(g(K)\) and \(g'(K) = 1 - r\).
Yes: \(g(K) = K e^{0} = K\) for every \(r\). But \(g'(K) = 1 - 2.5 = -1.5\), so \(|g'(K)| > 1\) and the steady state is repelling: any small deviation grows, alternating in sign, until the population settles on a 2-cycle. A bracketing root finder applied to \(g(N) - N\) still finds \(N^* = K\).
Q8. An iteration’s last three steps were \(0.100\), \(0.090\) and \(0.081\). Estimate the rate and the remaining error. If the stopping rule had been “step below \(10^{-3}\)”, how large would the error be when it stops?
The remaining error after a step \(d\) is about \(d\,L/(1 - L)\).
\(L \approx 0.9\). The remaining error is about \(0.081 \times 0.9/0.1 = 0.73\), much larger than the last step. At a step of \(10^{-3}\) the error is still about \(9\times10^{-3}\): with slow convergence the step underestimates the error by the factor \(L/(1-L) = 9\).
Q9. You simulate the harvested fish stock from 50 different starting sizes, and every run that survives ends at 74.95. A colleague concludes that 74.95 is the only steady state. What is wrong, and why does it matter?
Which steady states can a simulation (a fixed-point iteration) converge to?
A simulation only converges to attracting steady states (\(|g'| < 1\)). The unstable steady state at 20.48 (\(g' = 1.34\)) repels every run, so it never shows up, but it is the collapse threshold: below it the stock dies out even with a sustainable quota. Find it as a root of \(g(N) - N\) with bisection or uniroot on a bracket such as \([0, 50]\).
Q10. uniroot(f, c(50, 100)) returns 74.95244 for the harvested stock. How many correct digits can you expect, and what should you change?
Look up the default of tol in ?uniroot.
The default tolerance is .Machine$double.eps^0.25 \(\approx 1.2\times10^{-4}\); here the error was \(1.2\times10^{-6}\), so about 7 significant digits, and in general you are only promised about 4 decimals. Pass tol = 1e-12 (or a tolerance relative to the size of the root). scipy.optimize.brentq has tight defaults (xtol = 2e-12).
Q11. A root lies near \(x = 10^5\). Why does bisection with the absolute stopping rule \(b - a < 10^{-12}\) never stop?
The gap between neighbouring doubles near \(x\) is \(2^{\lfloor \log_2 x\rfloor - 52}\), and \(2^{16} = 65\,536\).
Near \(10^5\) the gap between doubles is \(2^{16-52} \approx 1.5\times10^{-11}\), larger than \(10^{-12}\). Once \(a\) and \(b\) are neighbouring doubles the midpoint rounds to one of them and the bracket stops shrinking, so the loop runs until maxit (or forever, if there is none). Use a relative tolerance, \(b - a < \text{tol}\cdot|m|\) with tol no smaller than about \(10^{-15}\).