Locating a root of an equation
Lesson: use graphical and simple numerical scans to find intervals containing roots.
Exercise 1 – Locate a root by sign changes
Work with the preset function f(x) = x³ − x − 2. Scan an interval and automatically detect subintervals where f changes sign, indicating at least one root.
Discussion
The scan does not give the root directly but identifies where to start more precise methods such as bisection or Newton’s method.
Bisection (dichotomy) method
Lesson: systematically shrink an interval that brackets a root.
Exercise 2 – Bisection on x³ − x − 2
Use the bisection method to approximate a root of f(x) = x³ − x − 2, starting from the default bracket [1, 2], which is known to contain a root. Choose the maximum number of iterations and a tolerance for the interval length.
Algorithm
Given a continuous f and [a, b] with f(a) * f(b) < 0:
for k = 0, 1, 2, ...
c = (a + b) / 2
if f(c) = 0 or (b - a)/2 < tolerance: stop
else if f(a) * f(c) < 0:
b = c
// root in [a, c]
else:
a = c
// root in [c, b]
Newton’s method (Newton–Raphson)
Lesson: use tangent lines to converge rapidly to a root.
Exercise 3 – Newton’s method on cos(x) − x
Consider f(x) = cos(x) − x, which has a root near x ≈ 0.739. Choose an initial guess x₀ and iterate Newton’s method up to a given number of steps, observing the convergence.
Iteration formula
For f(x) = cos(x) − x:
f'(x) = −sin(x) − 1
Newton iteration:
x_{n+1} = x_n − f(x_n) / f'(x_n).
Stop when |x_{n+1} − x_n| is below the chosen tolerance or
when the maximum number of iterations is reached.