Exercise

Practice: bisection and regula falsi

Bisection and regula falsi by hand with a table, the usual mistakes, transfer questions and a Python implementation: practice for the lecture on finding where a function crosses zero.

Last updated:


On this practice page we practise how to:

  • run bisection and regula falsi by hand in a table and say how many steps a tolerance needs;
  • explain why regula falsi can improve the estimate without shrinking the bracket;
  • avoid the usual mistakes (a bad bracket, stopping on a small ∣f(c)∣|f(c)|⁠);
  • write bisection in Python and test its edge cases.

This practice follows the three lectures The intermediate value theorem and bisection, Regula falsi and The rate of convergence:
read them or attend them first.

By hand, with a table

Setting. The function f(x)=cos⁡x−xf(x)=\cos x-x on the interval [0,1][0,1]⁠, with the angle in radians (on a calculator, choose RAD mode).
The equation cos⁡x=x\cos x=x has no simple closed-form solution, so we look for the root with the methods of the lecture.
Use the calculator guide of the lecture, or a table on paper.

  1. Show that [0,1][0,1] is a bracket.
  2. Do four bisection steps in a table with the columns aa⁠, bb⁠, cc and f(c)f(c)⁠. Which interval do you have after step 4, and how wide is it?
  3. How many bisection iterations are needed for the bracket width to be at most 0.0010.001⁠?
  4. Do two regula falsi steps from the same bracket. Which end moves and which stays? Compare the estimate of each method after two steps: which is closer to the root?
Hint for question 4

Regula falsi takes c=a f(b)−b f(a)f(b)−f(a)c=\dfrac{a\,f(b)-b\,f(a)}{f(b)-f(a)}⁠‏, the point where the chord between the two ends crosses zero.

Solutions
  1. f(0)=1>0f(0)=1>0 and f(1)=cos⁡1−1≈−0.4597<0f(1)=\cos1-1\approx-0.4597<0⁠‏, and ff is continuous, so [0,1][0,1] is a bracket.
  2. Step 1: c=0.5c=0.5⁠‏, f(c)≈0.378>0f(c)\approx0.378>0⁠‏, keep [0.5,1][0.5,1]⁠‏. Step 2: c=0.75c=0.75⁠‏, f(c)≈−0.018<0f(c)\approx-0.018<0⁠‏, keep [0.5,0.75][0.5,0.75]⁠‏. Step 3: c=0.625c=0.625⁠‏, f(c)≈0.186>0f(c)\approx0.186>0⁠‏, keep [0.625,0.75][0.625,0.75]⁠‏. Step 4: c=0.6875c=0.6875⁠‏, f(c)≈0.085>0f(c)\approx0.085>0⁠‏, keep [0.6875,0.75][0.6875,0.75]⁠‏, of width 0.0625=1160.0625=\tfrac1{16}⁠‏.
  3. N≥log⁡210.001≈9.97N\ge\log_2\dfrac{1}{0.001}\approx9.97⁠‏, so N=10N=10 iterations, with 1210≈0.00098≤0.001\frac{1}{2^{10}}\approx0.00098\le0.001⁠‏.
  4. First step: c≈0.6851c\approx0.6851⁠‏, f(c)≈0.089>0f(c)\approx0.089>0⁠‏, so aa moves to 0.68510.6851⁠‏. Second step: c≈0.7363c\approx0.7363⁠‏, f(c)≈0.0047>0f(c)\approx0.0047>0⁠‏, so aa moves again and b=1b=1 stays. The root is about 0.73910.7391⁠‏: the regula falsi estimate 0.73630.7363 is closer than the bisection estimate c2=0.75c_2=0.75 (errors 0.00280.0028 against 0.01090.0109⁠), although its bracket [0.7363,1][0.7363,1] is much wider. Regula falsi improves the estimate, not the bracket width, so the width is not a stopping test for it.

Regula falsi on the calculator. One chord step of regula falsi for f(x)=x2−2f(x)=x^2-2⁠, using the CALC key to enter AA and BB⁠.
The key to press is highlighted, and you can also press the keys yourself.

Root finding, cell by cell

Every case is an equation, an interval or a start, and a method.
Check the conditions of the method as you would on paper, then fill the iteration table one cell at a time; every cell is checked against the exact value.
In some cases the method cannot start.

The workout needs JavaScript. Without it, practise with the example above: bisection of x² − 2 on [1, 2] with tolerance 0.1 gives c₁ = 1.5, c₂ = 1.25, c₃ = 1.375, c₄ = 1.4375 and stops at iteration 4.

Transfer practice

  1. You borrow 1000 and repay it with 12 monthly payments of 90. Which monthly rate rr satisfies 1000=∑t=11290(1+r)t1000=\sum_{t=1}^{12}\frac{90}{(1+r)^t}⁠? Write g(r)g(r) for the sum minus 1000, the value of the payments at rate rr minus the amount borrowed, so that we look for the rr with g(r)=0g(r)=0 (positive: at that rate the payments are worth more than the loan). Show that [0,0.1][0,0.1] is a bracket of gg⁠.
  2. How many bisection iterations are needed to find rr in [0,0.1][0,0.1] with a bracket width of at most 10−610^{-6}⁠?
  3. Someone proposes starting bisection on gg with the interval [0.05,0.1][0.05,0.1]⁠‏. Why is that not possible, and how would you fix it?
  4. Do three regula falsi steps on g(r)=∑t=11290(1+r)t−1000g(r)=\sum_{t=1}^{12}\frac{90}{(1+r)^t}-1000 from question 1, from the bracket [0,0.1][0,0.1]⁠‏. Which end stays in place, and by what factor does the error fall at each step? Why is the end that stays in place harmless here but harmful for x10−1x^{10}-1⁠?
Solutions
  1. At r=0r=0 the payments add up to 1080, so g(0)=80>0g(0)=80>0⁠; at r=0.1r=0.1 the sum is about 613, so g(0.1)≈−387<0g(0.1)\approx-387<0⁠. The function is continuous, so [0,0.1][0,0.1] is a bracket. The root is r≈0.012043r\approx0.012043⁠, about 1.2% a month.
  2. N≥log⁡20.110−6≈16.6N\ge\log_2\frac{0.1}{10^{-6}}\approx16.6⁠, so N=17N=17 iterations.
  3. g(0.05)≈−202.31g(0.05)\approx-202.31 and g(0.1)≈−386.77g(0.1)\approx-386.77⁠‏: both are negative, so there is no sign change and no guarantee of a root in the interval (the root r≈0.0120435r\approx0.0120435 does lie outside it). Fix it with an interval whose ends have opposite signs: g(0)=80>0g(0)=80>0⁠, so we can stay with [0,0.1][0,0.1] or shrink to [0,0.05][0,0.05]⁠‏.
  4. c1=0.017139c_1=0.017139⁠‏, c2=0.012321c_2=0.012321 and c3=0.012059c_3=0.012059⁠‏; aa stays at 0 while bb moves, so only one end is updated. The errors relative to the root 0.0120430.012043 are 5.1×10−35.1\times10^{-3}⁠‏, 2.8×10−42.8\times10^{-4} and 1.5×10−51.5\times10^{-5}⁠‏: here the chord points almost exactly at the root every time, so the error falls about 18 times per step, more than a digit. In x10−1x^{10}-1 the curve is so bent that each chord lands far short, and progress crawls.

The error, convexity and the rate: the claims of the lecture on numbers

Questions about g(r)=∑t=11290(1+r)t−1000g(r)=\sum_{t=1}^{12}\frac{90}{(1+r)^t}-1000 (monthly rate rr⁠, a loan of 1000 repaid in 12 payments of 90, question 1 of the transfer practice), on the interval [0,0.1][0,0.1]⁠, that use the claims proved in the three lectures.
The root of gg is r≈0.0120435r\approx0.0120435⁠, and its slope at the root is g′(r)≈−6281.7g'(r)\approx-6281.7⁠.

  1. Compute the ε5\varepsilon_5 of bisection on gg⁠. How far from rr can c5c_5 be?
  2. gg is convex (each term 90(1+r)t\dfrac{90}{(1+r)^t} is convex). Explain with Claim 4 why a=0a=0 stays in place, and what the sign of g(c)g(c) is at every step.
  3. Compute the ρ=1−g′(r)g[0,r]\rho=1-\dfrac{g'(r)}{g[0,r]} of regula falsi on gg⁠, where the fixed end is a=0a=0⁠, and how many digits it gains per step. Compare it with the errors of the three steps in question 4 of the transfer practice: 5.1×10−35.1\times10^{-3}⁠, 2.8×10−42.8\times10^{-4} and 1.5×10−51.5\times10^{-5}⁠.
  4. For the three points c1≈0.017139c_1\approx0.017139⁠, c2≈0.012321c_2\approx0.012321 and c3≈0.012059c_3\approx0.012059 of the three regula falsi steps on gg from [0,0.1][0,0.1] (question 4 of the transfer practice), compute the ratio of the steps ∣c3−c2∣∣c2−c1∣\dfrac{|c_3-c_2|}{|c_2-c_1|}⁠, and with it estimate the error of c3c_3 without knowing rr⁠. How much smaller is it than the last step? Compare it with the real error 1.5×10−51.5\times10^{-5}⁠.
Solutions
  1. ε5=0.125=0.003125\varepsilon_5=\dfrac{0.1}{2^5}=0.003125⁠: c5c_5 is at most 0.0031250.003125 from rr⁠. This is a maximal error, not an exact one: the real error can be much smaller.
  2. g(0)=80>0g(0)=80>0⁠, so the end a=0a=0 stays in place. By Claim 4 g(c)≤0g(c)\le0 at every step (all three values g(c1)g(c_1)⁠, g(c2)g(c_2) and g(c3)g(c_3) are negative), and the right end comes down to rr from the right: 0.0171390.017139⁠, 0.0123210.012321⁠, 0.0120590.012059⁠.
  3. The slope from the fixed end is g[0,r]=g(r)−g(0)r−0=0−800.012043≈−6642.6g[0,r]=\dfrac{g(r)-g(0)}{r-0}=\dfrac{0-80}{0.012043}\approx-6642.6⁠, so ρ=1−−6281.7−6642.6≈0.0543\rho=1-\dfrac{-6281.7}{-6642.6}\approx0.0543⁠, that is, −log⁡10ρ≈1.26-\log_{10}\rho\approx1.26 digits per step. In the three steps of question 4, 2.8×10−45.1×10−3≈0.055\dfrac{2.8\times10^{-4}}{5.1\times10^{-3}}\approx0.055 and 1.5×10−52.8×10−4≈0.054\dfrac{1.5\times10^{-5}}{2.8\times10^{-4}}\approx0.054⁠: the measured ratio agrees with the formula, and the error falls about 18 times per step.
  4. ∣c3−c2∣≈2.63×10−4|c_3-c_2|\approx2.63\times10^{-4} and ∣c2−c1∣≈4.82×10−3|c_2-c_1|\approx4.82\times10^{-3}⁠, so the ratio of the steps is about 0.05460.0546⁠, close to ρ=0.0543\rho=0.0543⁠. The error is estimated as 2.63×10−4⋅0.05461−0.0546≈1.5×10−52.63\times10^{-4}\cdot\dfrac{0.0546}{1-0.0546}\approx1.5\times10^{-5}⁠, about 17 times smaller than the last step, and it matches the real error.

A US Treasury note: the same problem in a real market

A US Treasury note (a government bond) pays 2 every half-year, 4 a year per 100 of face value, until 15 February 2034, and returns the 100 at the end.
On Friday 16 October 2026 its market price was 93.936 (the middle of the bid 93.9306 and the ask 93.9414).
Which yearly rate yy makes these payments, discounted at yy⁠, worth exactly what a buyer pays today?
A payment of 2 received tt half-years from now is worth 2(1+y/2)t\dfrac{2}{(1+y/2)^{t}} today, and this rate yy is the yield of the bond.
Bond traders quote yields rather than prices, so trading systems translate a price into a yield again and again, for every quote, and without a numerical method they have no way to do it.
Write w=119184w=\tfrac{119}{184} for the fraction of a half-year until the first payment.
That is the equation

f(y)=∑k=014ck(1+y2)w+k−94.6425=2(1+y2)w+2(1+y2)w+1+⋯+102(1+y2)w+14−94.6425=0,\begin{aligned} f(y)&=\sum_{k=0}^{14}\frac{c_k}{\left(1+\frac y2\right)^{w+k}}-94.6425\\ &=\frac{2}{\left(1+\frac y2\right)^{w}}+\frac{2}{\left(1+\frac y2\right)^{w+1}}+\cdots+\frac{102}{\left(1+\frac y2\right)^{w+14}}\\ &\quad-94.6425=0, \end{aligned}

with ck=2c_k=2 for k=0,…,13k=0,\dots,13 and c14=102c_{14}=102⁠.

The finance in 20 seconds

A bond is a loan you buy: you pay today and receive the payments.
The rate yy that makes the discounted payments equal the price is the bond’s yield:
the annual return you earn if you hold it to the end, with interest credited twice a year.
The buyer also pays the interest accrued since the last payment on 15 August, 0.7065, so the price in the equation is 93.936+0.7065=94.642593.936+0.7065=94.6425⁠.
Settlement is on Monday 19 October, 119 of the 184 days before the next payment.
The prices are Interactive Brokers quotes (delayed, frozen), the note is CUSIP 91282CJZ5.
The quotes are from 16 October 2026.

  1. Compute f(0)f(0) and f(0.2)f(0.2) and show that [0,0.2][0,0.2] is a bracket.
  2. How many bisection iterations guarantee a bracket width of at most 10−610^{-6}⁠?
  3. Do two bisection steps and two regula falsi steps from [0,0.2][0,0.2]⁠. Which end moves in regula falsi, and which method is closer to the root?
Hint for question 1

At y=0y=0 nothing is discounted.

Solutions
  1. The payments add up to 14⋅2+102=13014\cdot2+102=130⁠, so f(0)=130−94.6425=35.3575>0f(0)=130-94.6425=35.3575>0⁠. At y=0.2y=0.2 we get f(0.2)≈−54.15<0f(0.2)\approx-54.15<0⁠. The function is continuous, so [0,0.2][0,0.2] is a bracket.
  2. N≥log⁡20.210−6≈17.6N\ge\log_2\dfrac{0.2}{10^{-6}}\approx17.6⁠, so N=18N=18 iterations.
  3. In bisection c1=0.1c_1=0.1 with f(c1)≈−24.58f(c_1)\approx-24.58⁠, and the kept bracket is [0,0.1][0,0.1]⁠; c2=0.05c_2=0.05 with f(c2)≈−0.01132f(c_2)\approx-0.01132⁠, and the kept bracket is [0,0.05][0,0.05]⁠. In regula falsi c1≈0.07900c_1\approx0.07900 with f(c1)≈−15.32f(c_1)\approx-15.32⁠, and c2≈0.05512c_2\approx0.05512 with f(c2)≈−2.951f(c_2)\approx-2.951⁠. The left end stays at 0 and the right end moves. The true yield is 0.049980660.04998066⁠, so after two steps the error is about 1.9×10−51.9\times10^{-5} in bisection and 5.1×10−35.1\times10^{-3} in regula falsi. Bisection is closer here by chance: the root is very near the midpoint 0.050.05 of [0,0.1][0,0.1]⁠. After six steps the error of regula falsi is about 4.6×10−64.6\times10^{-6} (about six times smaller at each step) and that of bisection about 3.1×10−33.1\times10^{-3}⁠.

A run in the explorer on the bond: to reach 10−1010^{-10} regula falsi needs 16 steps and bisection 39, by the stopping rule of the explorer (εn\varepsilon_n and also δn\delta_n⁠).
With the tolerance of the explorer, εtol=δtol=10−8\varepsilon_{\text{tol}}=\delta_{\text{tol}}=10^{-8}⁠, bisection stops at row n=31n=31 with c31≈0.04998066c_{31}\approx0.04998066⁠, and the yield of the bond is 4.998066%4.998066\%⁠.
Near the root the slope is about −585-585 per unit of yy⁠, so the condition on the residual is stricter than the condition on the width:
by the width alone 25 rows would be enough (ε25≈6.0×10−9\varepsilon_{25}\approx6.0\times10^{-9}⁠), but at row 25 the residual is still 2.8×10−62.8\times10^{-6}⁠.

In the real world: a voltage converter and libraries that solve the same problem

An analog-to-digital converter. According to the description of the algorithm in Wikipedia (a secondary source), a successive-approximation (SAR) converter finds a code for the input voltage by a binary search through the possible voltage levels:
one comparison per bit. An 8-bit converter with a reference voltage of 5 volts measures an input of 3.3 volts.
In each comparison it checks whether the input is higher than the voltage in the middle of the remaining interval:
if so the bit is 1 and the upper half stays, if not the bit is 0 and the lower half stays.

  1. Write the eight voltages the converter compares with, and the code that results.
  2. How many comparisons does an nn-bit converter need, and how does this relate to the logarithm?
Solutions
  1. The starting interval is [0,5][0,5]⁠. The voltages compared with: 2.52.5⁠, 3.753.75⁠, 3.1253.125⁠, 3.43753.4375⁠, 3.281253.28125⁠, 3.3593753.359375⁠, 3.32031253.3203125⁠, 3.300781253.30078125⁠. The answers: yes, no, yes, no, yes, no, no, no. The code is 101010002=16810101000_2=168⁠, and it equals ⌊3.3/5⋅256⌋\lfloor 3.3/5\cdot256\rfloor⁠.
  2. nn comparisons, because each one halves the interval and there are 2n2^n levels: n=log⁡2(2n)n=\log_2(2^n) halvings, like the bound N≥log⁡2b−aεtolN\ge\log_2\frac{b-a}{\varepsilon_{\text{tol}}} of the lecture.

Libraries. This is how the code of libraries solves the problems of the course (what the code calls, not what a particular system runs):

  • In QuantLib the generic implied-volatility function solves “price(σ) minus the target price equals zero” on the interval [σmin⁡,σmax⁡][\sigma_{\min},\sigma_{\max}] with Brent’s method, which includes bisection steps.
  • In Boost.Math computing the quantile of a discrete distribution first walks in steps until it reaches an interval where the sign changes, and only then solves cdf(x)−p=0\text{cdf}(x)-p=0 with a safe method (toms748): the same principle of a bracket before the solver.
  • In Kurbo, a geometry library for curves, the parameter that matches a given arc length is found with the ITP method, which by its documentation is “as robust as bisection but typically converges faster”.

Common mistakes

“I can start bisection on any two points.”

Why this is wrong

The method works only when f(a)f(a) and f(b)f(b) have opposite signs.
For f(x)=x2−1f(x)=x^2-1 on [−2,2][-2,2] both values are 3, although there are two roots:
the signs cannot tell us where to look. The explorer says so when you drag aa and bb to a place with no sign change.

“If f(a) f(b)f(a)\,f(b) is not negative, there is no root in the interval.”

Why this is wrong

A zero at an end of the bracket is a root already found. The rule “f(a)f(a) and f(b)f(b) have opposite signs” is a sufficient test for a root inside, not a necessary one:
if f(a)=0f(a)=0 or f(b)=0f(b)=0⁠, report that end as the root straight away.
The explorer does exactly this; a program that only checks f(a) f(b)<0f(a)\,f(b)<0 would wrongly reject the bracket.

“Stop as soon as ∣f(c)∣|f(c)| is tiny.”

Why this is wrong

A small value of ff does not mean a small error in cc⁠.
For f(x)=x10f(x)=x^{10} the root is 0, yet f(0.1)=10−10f(0.1)=10^{-10}⁠: the value is tiny while cc is still 0.1 away.
That is why we check both the bracket width and ∣f(c)∣|f(c)|⁠.

“Regula falsi is always faster than bisection.”

Why this is wrong

On the monthly payments of the lecture on regula falsi it needed 11 steps against 40, but on x10−1x^{10}-1 it needed 104 against 36.
It uses more information, which helps when ff is nearly linear and hurts when one end stays fixed.
Bisection is slower on average but its worst case is known.

Implement it yourself

Complete the function below: one decision is missing, which half of the bracket to keep.
The program then tests it on three cases, including the two edge cases from “Common mistakes”.
Press Run; if a line says FAIL, find out why before opening the solution.

Python in this task. It asks you to write code, one decision inside a function that is already written.
def defines a function; if runs the indented lines below it only when the condition is true; for _ in range(200) repeats at most 200 times; lambda x: x * x - 2 is a one-line function, here f(x)=x2−2f(x)=x^2-2⁠; math.sqrt(2) is 2\sqrt2⁠; abs(x) is the absolute value ∣x∣|x|⁠; None means “no answer”; b, fb = c, fc sets two names at once.

def bisection(f, a, b, tol=1e-10):
    """Return a root of f in [a, b], or None when the signs at
    the ends do not differ."""
    fa, fb = f(a), f(b)
    if fa == 0:
        return a
    if fb == 0:
        return b
    if fa * fb > 0:
        return None
    for _ in range(200):
        if b - a <= tol:
            break
        c = (a + b) / 2
        fc = f(c)
        # TODO: keep the half of the bracket where the sign
        # changes (update a and fa, or b and fb)
    return (a + b) / 2


import math
checks = [
    (
        "sqrt(2) on [1, 2]",
        bisection(lambda x: x * x - 2, 1, 2), math.sqrt(2)
    ),
    (
        "root at the left end",
        bisection(lambda x: x - 2, 2, 5), 2
    ),
    (
        "no sign change",
        bisection(lambda x: x * x - 1, -2, 2), None
    ),
]
for name, got, want in checks:
    good = (
        got is None if want is None
        else got is not None and abs(got - want) < 1e-9
    )
    print("ok  " if good else "FAIL", name, got)
ok   sqrt(2) on [1, 2] 1.414213562355144
ok   root at the left end 2
ok   no sign change None
Solution

Replace the TODO line by

        if fa * fc <= 0:
            b, fb = c, fc
        else:
            a, fa = c, fc

If f(a)f(a) and f(c)f(c) have opposite signs or f(c)=0f(c)=0⁠, there is a root in [a,c][a,c]⁠, so cc becomes the new right end; otherwise it is in [c,b][c,b]⁠.
The function returns (a+b)/2(a+b)/2⁠, the midpoint of the final bracket, which is cN+1c_{N+1}⁠:
a free better approximation than the cNc_N of the lecture. Then compare with what the explorer does on the same function.
As a further step, change the stopping rule so that it also checks ∣f(c)∣|f(c)| against a separate tolerance, and see when the two rules disagree.

One more run: how narrow can a bracket be? The bracket [1,2][1,2] of x2−2x^2-2 halves at every step, and the formula N=⌈log⁡2b−aεtol⌉N=\left\lceil\log_2\dfrac{b-a}{\varepsilon_{\text{tol}}}\right\rceil gives 57 iterations for εtol=10−17\varepsilon_{\text{tol}}=10^{-17}⁠.
The gap between stored binary64 numbers in [1,2)[1,2) is 2e−p=20−52=2−522^{e-p}=2^{0-52}=2^{-52} (see the formula for the gap).
After how many halvings is the bracket one gap wide, and what does the program do from then on?
Work it out. Then run the complete function below (before its return it prints the last bracket) and compare with your answer:

def bisection(f, a, b, tol=1e-10):
    fa, fb = f(a), f(b)
    if fa == 0:
        return a
    if fb == 0:
        return b
    if fa * fb > 0:
        return None
    for _ in range(200):
        if b - a <= tol:
            break
        c = (a + b) / 2
        fc = f(c)
        if fa * fc <= 0:
            b, fb = c, fc
        else:
            a, fa = c, fc
    print(a, b, b - a)
    return (a + b) / 2


print(bisection(lambda x: x * x - 2, 1, 2, 1e-17))
1.414213562373095 1.4142135623730951 2.220446049250313e-16
1.414213562373095
Solution

After n=52n=52 halvings the width is 2−522^{-52}⁠: the two ends are neighbouring stored numbers.
The program prints two lines. The first, printed inside bisection after the loop, is a, b and b - a:
1.414213562373095 1.4142135623730951 2.220446049250313e-16; the second is the result, 1.414213562373095.
The midpoint of two neighbours lies exactly halfway between them, so it is rounded to one of the two:
a or b is replaced by itself and the bracket never changes again.
Its width, 2.2×10−162.2\times10^{-16}⁠, is larger than the tolerance, so the test b - a <= tol never holds and the loop ends only at its limit of 200 repetitions.
The formula counts steps in exact arithmetic; it cannot promise a bracket narrower than the gap.
In binary32, with 23 fraction bits, the bracket of the same problem stops shrinking after 23 halvings, at width 2−23≈1.2×10−72^{-23}\approx1.2\times10^{-7}⁠.

Now regula falsi. Write the one missing line yourself: the point c=a f(b)−b f(a)f(b)−f(a)c=\dfrac{a\,f(b)-b\,f(a)}{f(b)-f(a)} where the chord crosses zero.
The program runs your function on x10−1x^{10}-1 in [0,1.3][0,1.3] and prints the number of steps until ∣f(c)∣≤10−10|f(c)|\le10^{-10}⁠, the right end, and the ratio of the last two steps.
Compare with the lecture: 104 steps, a right end that never moves from 1.3, and a ratio near ρ≈0.765\rho\approx0.765⁠.
In the code, points.append(c) adds the value c to the end of the list points.

Hint

The formula is in the lecture on regula falsi; in the code a, b are the ends and fa, fb their values.

def regula_falsi(f, a, b, tol=1e-10, max_steps=1000):
    fa, fb = f(a), f(b)
    points = []
    for _ in range(max_steps):
        # TODO: c is the point where the chord through
        # (a, fa) and (b, fb) crosses zero
        c = None
        fc = f(c)
        points.append(c)
        if abs(fc) <= tol:
            break
        if fa * fc <= 0:
            b, fb = c, fc
        else:
            a, fa = c, fc
    return points, a, b


points, a, b = regula_falsi(lambda x: x**10 - 1, 0, 1.3)
steps = [abs(points[i] - points[i - 1]) for i in range(1, len(points))]
print("steps:", len(points))
print("right end:", b)
print("step ratio at the end:", round(steps[-1] / steps[-2], 3))
steps: 104
right end: 1.3
step ratio at the end: 0.765
Solution

Replace the line c = None by

        c = (a * fb - b * fa) / (fb - fa)

The program prints 104 steps, the right end stays at 1.3 (so only the left end moves, as Claim 4 says for a convex function) and the ratio of the last steps is 0.7650.765⁠:
the ρ\rho of the lecture on the rate of convergence, computed here from the points alone, without knowing the root.
As a further step, run the same function on the monthly payments, lambda r: sum(220 / (1 + r) ** t for t in range(1, 7)) - 1200 in [0,0.05][0,0.05]⁠:
it needs 11 steps, and the ratio is about 0.0710.071⁠.

Continue learning

Back to the lectures The intermediate value theorem and bisection, Regula falsi and The rate of convergence.
The glossary has the terms: glossary.