Root-finding algorithms, interpolation, numerical integration, ODE solvers, and error analysis — the complete applied mathematics reference.
Root-finding methods solve f(x) = 0. They differ in convergence speed, reliability, and what information they require about f.
Guaranteed to converge when f(a) and f(b) have opposite signs. Halves the interval each step. Error after n steps: |b - a| / 2^n. Reliable but slow.
Requires f'(x). Iterates x_{n+1} = x_n - f(x_n)/f'(x_n). Converges quadratically near simple roots — digits double each step. Can diverge with bad initial guess.
Approximates f'(x) using a secant line through two previous iterates. No derivative required. Converges faster than bisection, slightly slower than Newton-Raphson.
Rewrites f(x) = 0 as x = g(x) and iterates. Converges when |g'(p)| less than 1 at the fixed point p. Choice of g(x) determines whether the method converges.
Prerequisites
f must be continuous on [a, b] and f(a) and f(b) must have opposite signs. The Intermediate Value Theorem guarantees at least one root in [a, b].
Algorithm
Number of Iterations for Desired Accuracy
Example: interval [1, 2], tolerance 10^(-6) requires n ≥ log2(10^6) ≈ 20 iterations.
Iteration Formula
Geometrically: draw the tangent line to f at the current approximation x_n, then take the x-intercept of that tangent line as the next approximation.
Convergence Order
Quadratic near a simple root: e_(n+1) ≈ (f''(p) / (2 f'(p))) * e_n^2 where e_n is the error at step n. The ratio |e_(n+1)| / |e_n|^2 approaches a constant.
When Newton-Raphson Fails
The secant method replaces the derivative f'(x_n) in Newton-Raphson with a finite difference approximation using the two most recent iterates.
Order of convergence
Superlinear, order p = (1 + sqrt(5))/2 ≈ 1.618 (the golden ratio)
Starting requirements
Needs two initial points x_0 and x_1. Does not need f'(x).
Vs. Newton-Raphson
Slightly slower per root but each step costs only one function evaluation vs. two.
Setup
Rewrite f(x) = 0 as x = g(x). Choose a starting point x_0 and iterate x_(n+1) = g(x_n). A fixed point p satisfies g(p) = p, which is a root of f.
Convergence Theorem
If g is continuous on [a, b], g maps [a, b] into itself, and |g'(x)| ≤ k less than 1 for all x in [a, b], then iteration converges to a unique fixed point in [a, b].
Example: Solving x^3 - x - 2 = 0
Given n+1 data points (x_0, y_0), ..., (x_n, y_n) with distinct nodes, there exists a unique polynomial of degree at most n passing through all points.
Writes the interpolating polynomial as a sum of Lagrange basis polynomials L_i(x):
L_i(x) equals 1 at x_i and 0 at every other node. Easy to write but expensive to update when new data points are added.
Builds the polynomial incrementally using divided difference coefficients. Define:
f[x_i] = y_i
f[x_i, x_(i+1)] = (f[x_(i+1)] - f[x_i]) / (x_(i+1) - x_i)
f[x_i,...,x_(i+k)] = (f[x_(i+1),...,x_(i+k)] - f[x_i,...,x_(i+k-1)]) / (x_(i+k) - x_i)
Adding a new point only requires computing one new diagonal of the divided difference table — preferred for incremental computation.
On each subinterval [x_i, x_(i+1)] a cubic spline S(x) uses a separate cubic polynomial S_i(x). The conditions enforced at interior knots are:
Smoothness Conditions
Boundary Conditions
Splines avoid Runge's phenomenon — the wild oscillations seen in high-degree polynomial interpolation at equally spaced points.
Newton-Cotes formulas approximate the integral of f on [a, b] using equally spaced evaluation points. Gaussian quadrature chooses both nodes and weights optimally.
Step size
h = (b - a) / n
Global error
O(h^2)
Exact for
Polynomials deg ≤ 1
Requires n to be even. Uses parabolas over pairs of subintervals.
Weights pattern
1, 4, 2, 4, 2, ..., 4, 1
Global error
O(h^4)
Exact for
Polynomials deg ≤ 3
Chooses both nodes and weights to maximize accuracy. An n-point Gauss-Legendre rule is exact for polynomials up to degree 2n - 1, compared to n for Newton-Cotes.
| n (points) | Nodes | Weights w_i |
|---|---|---|
| 1 | 0 | 2 |
| 2 | ±1/sqrt(3) ≈ ±0.5774 | 1, 1 |
| 3 | 0, ±0.7746 | 8/9, 5/9, 5/9 |
| 5 | 0, ±0.5385, ±0.9062 | 0.5689, 0.4786, 0.4786, 0.2370, 0.2370 |
For integrals on [a, b], transform via x = ((b-a)t + (b+a)) / 2 and multiply by (b-a)/2.
For the initial value problem y' = f(t, y), y(t_0) = y_0, numerical methods march the solution forward in time steps of size h.
The simplest one-step method. Uses the slope at the current point to step forward.
Local truncation error
O(h^2)
Global error
O(h)
Function evaluations
1 per step
Euler's method is rarely used in practice due to its low accuracy, but it is the conceptual foundation for understanding all higher-order methods.
Computes four slope estimates and takes a weighted average for the step.
k1 = f(t_n, y_n)
k2 = f(t_n + h/2, y_n + (h/2)*k1)
k3 = f(t_n + h/2, y_n + (h/2)*k2)
k4 = f(t_n + h, y_n + h*k3)
y_(n+1) = y_n + (h/6)(k1 + 2*k2 + 2*k3 + k4)
Local truncation error
O(h^5)
Global error
O(h^4)
Function evaluations
4 per step
Halving h reduces global error by a factor of 16. RK4 is the standard method for non-stiff ODEs and is the first solver to try for any new problem.
Error from replacing an exact mathematical operation with a finite approximation. Examples: truncating a Taylor series, using a finite difference for a derivative.
Error from finite-precision floating-point arithmetic. Double precision has about 15-16 significant decimal digits. Catastrophic cancellation occurs when subtracting nearly equal numbers.
Total error = truncation error + round-off error. As h decreases, truncation error falls but round-off error rises. The optimal step size minimizes total error:
For the forward difference derivative approximation (error O(h)) with double precision, h_opt ≈ sqrt(eps) ≈ 10^(-8). Using h smaller than this degrades accuracy.
The condition number kappa measures intrinsic sensitivity of a problem to input perturbations. It is a property of the problem, not the algorithm.
For a Matrix A
For symmetric positive definite matrices: kappa = lambda_max / lambda_min (ratio of largest to smallest eigenvalue).
Interpretation
Key Insight
An ill-conditioned problem (large kappa) cannot be solved accurately with any algorithm because tiny errors in the data get amplified. Pivoting and preconditioning can improve numerical behavior but cannot overcome inherent ill-conditioning.
Root-Finding Methods
| Method | Order | Needs f' | Guaranteed? |
|---|---|---|---|
| Bisection | 1 (linear) | No | Yes (if IVT holds) |
| Newton-Raphson | 2 (quadratic) | Yes | No |
| Secant | 1.618 | No | No |
| Fixed-point | 1 (linear) | No | If |g'| less than 1 |
Numerical Integration Methods
| Method | Global Error | Exact for Degree | Notes |
|---|---|---|---|
| Trapezoidal | O(h^2) | ≤ 1 | Simple, n+1 evals |
| Simpson's 1/3 | O(h^4) | ≤ 3 | n must be even |
| Simpson's 3/8 | O(h^4) | ≤ 3 | n multiple of 3 |
| Gauss-Legendre n-pt | O(h^(2n)) | ≤ 2n-1 | Non-uniform nodes |
f(1) = 1 - 1 - 2 = -2 (negative) f(2) = 8 - 2 - 2 = 4 (positive). Sign change confirmed.
Step 1: c = (1+2)/2 = 1.5. f(1.5) = 3.375 - 1.5 - 2 = -0.125. Negative → new interval [1.5, 2]
Step 2: c = (1.5+2)/2 = 1.75. f(1.75) = 5.359 - 1.75 - 2 = 1.609. Positive → new interval [1.5, 1.75]
Step 3: c = 1.625. f(1.625) ≈ 0.666. Positive → new interval [1.5, 1.625]
Root converging to x ≈ 1.5214. After 20 steps: accuracy to 6 decimal places.
f(x) = x^2 - 2 f'(x) = 2x Iteration: x_(n+1) = x_n - (x_n^2 - 2)/(2*x_n) = (x_n + 2/x_n)/2
x_0 = 1.000000 error = 0.4142
x_1 = 1.500000 error = 0.0858
x_2 = 1.416667 error = 0.00246
x_3 = 1.414216 error = 0.0000021
x_4 = 1.414214 error less than 10^(-12)
Quadratic convergence: errors roughly square at each step. sqrt(2) = 1.41421356...
h = (1-0)/4 = 0.25 Nodes: x_0=0, x_1=0.25, x_2=0.5, x_3=0.75, x_4=1
f(x_0) = e^0 = 1.000000
f(x_1) = e^0.25 = 1.284025
f(x_2) = e^0.5 = 1.648721
f(x_3) = e^0.75 = 2.117000
f(x_4) = e^1 = 2.718282
Integral ≈ (0.25/3)(1 + 4(1.284025) + 2(1.648721) + 4(2.117000) + 2.718282)
= (0.08333)(1 + 5.136100 + 3.297442 + 8.468000 + 2.718282) = (0.08333)(20.619824)
Result: 1.71828 vs exact e - 1 = 1.71828... Error less than 0.000001.
Exact solution: y = e^t. At t = 0.5: y = e^0.5 ≈ 1.648721
f(t, y) = y y_0 = 1 t_0 = 0 h = 0.5
k1 = f(0, 1) = 1
k2 = f(0.25, 1 + 0.25*1) = f(0.25, 1.25) = 1.25
k3 = f(0.25, 1 + 0.25*1.25) = f(0.25, 1.3125) = 1.3125
k4 = f(0.5, 1 + 0.5*1.3125) = f(0.5, 1.65625) = 1.65625
y_1 = 1 + (0.5/6)(1 + 2*1.25 + 2*1.3125 + 1.65625)
= 1 + (0.08333)(8.78125) = 1.648177
RK4 result: 1.648177 Exact: 1.648721 Error: 0.000544 with just one step.
Three points: (x_0,y_0)=(0,1), (x_1,y_1)=(1,3), (x_2,y_2)=(3,2)
L_0(x) = (x-1)(x-3) / ((0-1)(0-3)) = (x-1)(x-3)/3
L_1(x) = (x-0)(x-3) / ((1-0)(1-3)) = x(x-3)/(-2)
L_2(x) = (x-0)(x-1) / ((3-0)(3-1)) = x(x-1)/6
P(x) = 1*L_0 + 3*L_1 + 2*L_2
= (x^2-4x+3)/3 + 3x(x-3)/(-2) + 2x(x-1)/6
= (x^2-4x+3)/3 - (3x^2-9x)/2 + (x^2-x)/3
Simplify: P(x) = (-7/6)x^2 + (17/6)x + 1. Verify: P(0)=1, P(1)=3, P(3)=2 ✓
The bisection method finds a root of f(x) = 0 by repeatedly halving an interval [a, b] where f(a) and f(b) have opposite signs (guaranteed by the Intermediate Value Theorem). At each step you evaluate the midpoint c = (a + b)/2. If f(c) = 0 you found the root; otherwise replace a or b with c depending on which subinterval contains the sign change. It is guaranteed to converge but only linearly — the error halves each iteration. Use it when you need reliability over speed, or as a fallback when other methods fail.
Newton-Raphson converges quadratically near a simple root, meaning the number of correct decimal digits roughly doubles each iteration. The iteration formula is x_{n+1} = x_n - f(x_n)/f'(x_n). Quadratic convergence is extremely fast in practice — starting with 2 correct digits, one step gives ~4, then ~8, then ~16. However, Newton-Raphson requires f'(x) to be computable, requires a good initial guess near the root, can diverge for poorly chosen starting points, and degrades to linear convergence at repeated roots.
Both methods produce the same unique polynomial of degree at most n passing through n+1 data points. Lagrange interpolation writes the polynomial as a sum of basis polynomials L_i(x), each equal to 1 at x_i and 0 at all other nodes. It is easy to write but expensive to update — adding a new data point requires recomputing all basis polynomials. Newton's divided differences builds the polynomial incrementally using a triangular table of divided differences. Adding a new point only requires one new column of the table. For computational work Newton's form is preferred; Lagrange form is better for theoretical analysis.
Simpson's 1/3 rule is much more accurate. The Trapezoidal rule approximates the integrand by straight-line segments (degree-1 polynomials), giving a global error proportional to h^2 where h is the step size. Simpson's 1/3 rule fits parabolas through pairs of subintervals (degree-2 polynomials) and achieves error proportional to h^4. Halving the step size reduces Trapezoidal error by a factor of 4 but reduces Simpson's error by a factor of 16. Simpson's rule is also exact for any polynomial up to degree 3 due to a fortuitous cancellation.
RK4 is a single-step method for solving y' = f(t, y) that computes four slope estimates per step: k1 at the start, k2 and k3 at the midpoint (using k1 and k2 respectively), and k4 at the end. The step is y_{n+1} = y_n + (h/6)(k1 + 2k2 + 2k3 + k4). RK4 has local truncation error proportional to h^5 and global error proportional to h^4, meaning halving h reduces error by a factor of 16. It requires no special starting procedure (unlike multi-step methods), handles most smooth problems well, and is simple to implement — making it the default choice in science and engineering.
Truncation error arises from approximating an infinite mathematical process with a finite one — for example, truncating an infinite Taylor series after a few terms, or replacing a derivative with a finite difference. It decreases as the step size h decreases. Round-off error arises from the finite precision of floating-point arithmetic — every real number is stored with only ~15-16 significant digits in double precision. Round-off error increases as h decreases because subtracting nearly equal numbers amplifies relative error. The optimal step size balances these two competing effects.
The condition number of a problem measures how sensitive the output is to small changes in the input. For a matrix A, the condition number kappa(A) = ||A|| * ||A^{-1}||. A large condition number (ill-conditioned) means small perturbations in data or round-off errors can cause large errors in the solution. For example, solving Ax = b with cond(A) = 10^6 means you can lose up to 6 decimal digits of accuracy compared to a well-conditioned system. Condition number is a property of the problem, not the algorithm — an ill-conditioned problem is inherently hard to solve accurately regardless of the method used.
Fixed-point iteration solves f(x) = 0 by rewriting it as x = g(x) and iterating x_{n+1} = g(x_n). A fixed point is a value p where g(p) = p. The iteration converges to a fixed point p if |g'(p)| < 1 near p — the smaller |g'(p)|, the faster the convergence. If |g'(p)| > 1 the iteration diverges. If |g'(p)| = 0 convergence is superlinear. The choice of how to rearrange f(x) = 0 into x = g(x) is crucial — different rearrangements of the same equation can converge or diverge depending on the value of g' at the fixed point.
High-degree polynomial interpolation through many points suffers from Runge's phenomenon — wild oscillations between data points, especially near the endpoints. Cubic splines avoid this by fitting a separate cubic polynomial on each subinterval between data points, then enforcing that the function, first derivative, and second derivative all match at each interior data point (knot). This produces a smooth curve that passes exactly through all data points without oscillation. Natural splines additionally set the second derivative to zero at the endpoints. Splines are the standard method in CAD, computer graphics, and data smoothing.
Interactive problems with step-by-step solutions and private tutoring — free to try.
Start Practicing Free