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 );
- 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 on the interval , with the angle in radians (on a calculator, choose RAD mode).
The equation 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.
- Show that is a bracket.
- Do four bisection steps in a table with the columns , , and . Which interval do you have after step 4, and how wide is it?
- How many bisection iterations are needed for the bracket width to be at most ?
- 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 , the point where the chord between the two ends crosses zero.
Solutions
- and , and is continuous, so is a bracket.
- Step 1: , , keep . Step 2: , , keep . Step 3: , , keep . Step 4: , , keep , of width .
- , so iterations, with .
- First step: , , so moves to . Second step: , , so moves again and stays. The root is about : the regula falsi estimate is closer than the bisection estimate (errors against ), although its bracket 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 , using the CALC key to enter and .
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
- You borrow 1000 and repay it with 12 monthly payments of 90. Which monthly rate satisfies ? Write for the sum minus 1000, the value of the payments at rate minus the amount borrowed, so that we look for the with (positive: at that rate the payments are worth more than the loan). Show that is a bracket of .
- How many bisection iterations are needed to find in with a bracket width of at most ?
- Someone proposes starting bisection on with the interval . Why is that not possible, and how would you fix it?
- Do three regula falsi steps on from question 1, from the bracket . 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 ?
Solutions
- At the payments add up to 1080, so ; at the sum is about 613, so . The function is continuous, so is a bracket. The root is , about 1.2% a month.
- , so iterations.
- and : both are negative, so there is no sign change and no guarantee of a root in the interval (the root does lie outside it). Fix it with an interval whose ends have opposite signs: , so we can stay with or shrink to .
- , and ; stays at 0 while moves, so only one end is updated. The errors relative to the root are , and : 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 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 (monthly rate , a loan of 1000 repaid in 12 payments of 90, question 1 of the transfer practice), on the interval , that use the claims proved in the three lectures.
The root of is , and its slope at the root is .
- Compute the of bisection on . How far from can be?
- is convex (each term is convex). Explain with Claim 4 why stays in place, and what the sign of is at every step.
- Compute the of regula falsi on , where the fixed end is , and how many digits it gains per step. Compare it with the errors of the three steps in question 4 of the transfer practice: , and .
- For the three points , and of the three regula falsi steps on from (question 4 of the transfer practice), compute the ratio of the steps , and with it estimate the error of without knowing . How much smaller is it than the last step? Compare it with the real error .
Solutions
- : is at most from . This is a maximal error, not an exact one: the real error can be much smaller.
- , so the end stays in place. By Claim 4 at every step (all three values , and are negative), and the right end comes down to from the right: , , .
- The slope from the fixed end is , so , that is, digits per step. In the three steps of question 4, and : the measured ratio agrees with the formula, and the error falls about 18 times per step.
- and , so the ratio of the steps is about , close to . The error is estimated as , 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 makes these payments, discounted at , worth exactly what a buyer pays today?
A payment of 2 received half-years from now is worth today, and this rate 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 for the fraction of a half-year until the first payment.
That is the equation
with for and .
The finance in 20 seconds
A bond is a loan you buy: you pay today and receive the payments.
The rate 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 .
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.
- Compute and and show that is a bracket.
- How many bisection iterations guarantee a bracket width of at most ?
- Do two bisection steps and two regula falsi steps from . Which end moves in regula falsi, and which method is closer to the root?
Hint for question 1
At nothing is discounted.
Solutions
- The payments add up to , so . At we get . The function is continuous, so is a bracket.
- , so iterations.
- In bisection with , and the kept bracket is ; with , and the kept bracket is . In regula falsi with , and with . The left end stays at 0 and the right end moves. The true yield is , so after two steps the error is about in bisection and in regula falsi. Bisection is closer here by chance: the root is very near the midpoint of . After six steps the error of regula falsi is about (about six times smaller at each step) and that of bisection about .
A run in the explorer on the bond: to reach regula falsi needs 16 steps and bisection 39, by the stopping rule of the explorer ( and also ).
With the tolerance of the explorer, , bisection stops at row with , and the yield of the bond is .
Near the root the slope is about per unit of , so the condition on the residual is stricter than the condition on the width:
by the width alone 25 rows would be enough (), but at row 25 the residual is still .
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.
- Write the eight voltages the converter compares with, and the code that results.
- How many comparisons does an -bit converter need, and how does this relate to the logarithm?
Solutions
- The starting interval is . The voltages compared with: , , , , , , , . The answers: yes, no, yes, no, yes, no, no, no. The code is , and it equals .
- comparisons, because each one halves the interval and there are levels: halvings, like the bound 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 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 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 and have opposite signs.
For on both values are 3, although there are two roots:
the signs cannot tell us where to look. The explorer says so when you drag and to a place with no sign change.
“If 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 “ and have opposite signs” is a sufficient test for a root inside, not a necessary one:
if or , report that end as the root straight away.
The explorer does exactly this; a program that only checks would wrongly reject the bracket.
“Stop as soon as is tiny.”
Why this is wrong
A small value of does not mean a small error in .
For the root is 0, yet : the value is tiny while is still 0.1 away.
That is why we check both the bracket width and .
“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 it needed 104 against 36.
It uses more information, which helps when 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 ; math.sqrt(2) is ; abs(x) is the absolute value ; 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 and have opposite signs or , there is a root in , so becomes the new right end; otherwise it is in .
The function returns , the midpoint of the final bracket, which is :
a free better approximation than the 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 against a separate tolerance, and see when the two rules disagree.
One more run: how narrow can a bracket be? The bracket of halves at every step, and the formula gives 57 iterations for .
The gap between stored binary64 numbers in is (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 halvings the width is : 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, , 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 .
Now regula falsi. Write the one missing line yourself: the point where the chord crosses zero.
The program runs your function on in and prints the number of steps until , 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 .
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 :
the 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 :
it needs 11 steps, and the ratio is about .
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.