Search Knowledge

© 2026 LIBREUNI PROJECT

Numerical Root Finding

Numerical Root Finding

Numerical root finding is the process of finding an approximate value xx such that f(x)=0f(x) = 0 for a given continuous function ff.

The Bisection Method

The Bisection method is a robust but slow root-finding algorithm. It works by repeatedly bisecting an interval and then selecting a subinterval in which a root must lie for further processing. It requires that the function values at the endpoints of the interval have opposite signs (Bolzano’s Theorem).

python
1def f(x):
2 return x**3 - x - 2
3 
4def bisection(a, b, tol=1e-5):
5 if f(a) * f(b) >= 0:
6 return "Bisection fails (no sign change)."
7
8 while (b - a) / 2 > tol:
9 midpoint = (a + b) / 2
10 if f(midpoint) == 0:
11 return midpoint
12 elif f(a) * f(midpoint) < 0:
13 b = midpoint
14 else:
15 a = midpoint
16 return (a + b) / 2
17 
18root = bisection(1, 2)
19print(f"Bisection root: {root:.6f}")
20print(f"f(root): {f(root):.6e}")

Newton-Raphson Method

The Newton-Raphson method uses the first two terms of the Taylor series to iteratively improve an estimate. xn+1=xnf(xn)f(xn)x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}

python
1def f(x):
2 return x**3 - x - 2
3 
4def df(x):
5 return 3*x**2 - 1
6 
7def newton(x0, tol=1e-5, max_iter=100):
8 x = x0
9 for i in range(max_iter):
10 delta = f(x) / df(x)
11 x = x - delta
12 if abs(delta) < tol:
13 return x, i
14 return x, max_iter
15 
16root, iterations = newton(1.5)
17print(f"Newton root: {root:.6f} found in {iterations} iterations")

Which method is generally faster if a good initial guess is provided?

Convergence and Stability

Newton’s method converges quadratically (en+1Cen2e_{n+1} \approx C e_n^2), meaning the number of correct digits roughly doubles each iteration. However, it can fail or diverge if f(x)f'(x) is near zero or if the initial guess is far from a root.

What happens to Newton's method if the derivative is zero at the current guess?

Next Module Predicate Logic