Applied Mathematics / Engineering Math

Numerical Methods

Root-finding algorithms, interpolation, numerical integration, ODE solvers, and error analysis — the complete applied mathematics reference.

Root-Finding Methods

Root-finding methods solve f(x) = 0. They differ in convergence speed, reliability, and what information they require about f.

Bisection Method

Linear convergence

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.

Newton-Raphson

Quadratic convergence

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.

Secant Method

Superlinear (order ~1.618)

Approximates f'(x) using a secant line through two previous iterates. No derivative required. Converges faster than bisection, slightly slower than Newton-Raphson.

Fixed-Point Iteration

Linear convergence

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.

Bisection Method — Algorithm and Analysis

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

  1. Compute midpoint c = (a + b) / 2
  2. If f(c) = 0 or (b - a)/2 is less than tolerance, return c
  3. If sign(f(c)) = sign(f(a)), set a = c; otherwise set b = c
  4. Repeat from step 1

Number of Iterations for Desired Accuracy

n ≥ log2((b - a) / tolerance)

Example: interval [1, 2], tolerance 10^(-6) requires n ≥ log2(10^6) ≈ 20 iterations.

Newton-Raphson Method

Iteration Formula

x_(n+1) = x_n - f(x_n) / f'(x_n)

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

  • f'(x_n) = 0 — tangent is horizontal, method undefined
  • Poor initial guess — can cycle or diverge
  • Repeated root — degrades to linear convergence
  • f' unavailable or expensive to compute

Secant Method

The secant method replaces the derivative f'(x_n) in Newton-Raphson with a finite difference approximation using the two most recent iterates.

x_(n+1) = x_n - f(x_n) * (x_n - x_(n-1)) / (f(x_n) - f(x_(n-1)))

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.

Fixed-Point Iteration

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

Rearrangement 1: x = (x^3 - 2) — g'(x) = 3x^2 ≈ 3 near root. DIVERGES.
Rearrangement 2: x = (x + 2)^(1/3) — g'(x) = 1/(3(x+2)^(2/3)) ≈ 0.23 near root. CONVERGES.

Interpolation

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.

Lagrange Interpolation

Writes the interpolating polynomial as a sum of Lagrange basis polynomials L_i(x):

P(x) = sum_i y_i * L_i(x)   where   L_i(x) = prod_(j≠i) (x - x_j) / (x_i - x_j)

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.

Newton's Divided Differences

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)

P(x) = f[x_0] + f[x_0,x_1](x-x_0) + f[x_0,x_1,x_2](x-x_0)(x-x_1) + ...

Adding a new point only requires computing one new diagonal of the divided difference table — preferred for incremental computation.

Cubic Splines

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

  • S_i(x_(i+1)) = S_(i+1)(x_(i+1)) — continuity
  • S_i'(x_(i+1)) = S_(i+1)'(x_(i+1)) — smooth joints
  • S_i''(x_(i+1)) = S_(i+1)''(x_(i+1)) — no kinks

Boundary Conditions

  • Natural spline: S''(x_0) = S''(x_n) = 0
  • Clamped: specify S'(x_0) and S'(x_n)
  • Not-a-knot: third derivative is continuous at x_1 and x_(n-1)

Splines avoid Runge's phenomenon — the wild oscillations seen in high-degree polynomial interpolation at equally spaced points.

Numerical Integration (Quadrature)

Newton-Cotes formulas approximate the integral of f on [a, b] using equally spaced evaluation points. Gaussian quadrature chooses both nodes and weights optimally.

Trapezoidal Rule

integral_a^b f(x) dx ≈ (h/2)(f(x_0) + 2f(x_1) + 2f(x_2) + ... + 2f(x_(n-1)) + f(x_n))

Step size

h = (b - a) / n

Global error

O(h^2)

Exact for

Polynomials deg ≤ 1

Simpson's 1/3 Rule

Requires n to be even. Uses parabolas over pairs of subintervals.

integral_a^b f(x) dx ≈ (h/3)(f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + ... + 4f(x_(n-1)) + f(x_n))

Weights pattern

1, 4, 2, 4, 2, ..., 4, 1

Global error

O(h^4)

Exact for

Polynomials deg ≤ 3

Gaussian Quadrature

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.

integral(-1 to 1) f(x) dx ≈ sum(i=1 to n) w_i * f(x_i)
n (points)NodesWeights w_i
102
2±1/sqrt(3) ≈ ±0.57741, 1
30, ±0.77468/9, 5/9, 5/9
50, ±0.5385, ±0.90620.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.

Numerical ODE Solvers

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.

Euler's Method

The simplest one-step method. Uses the slope at the current point to step forward.

y_(n+1) = y_n + h * f(t_n, y_n)

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.

Runge-Kutta 4th Order (RK4)

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 Analysis

Truncation Error

Error from replacing an exact mathematical operation with a finite approximation. Examples: truncating a Taylor series, using a finite difference for a derivative.

  • Decreases as step size h decreases
  • Quantified by the leading term of the Taylor remainder
  • Order O(h^p) means error scales with h^p

Round-off Error

Error from finite-precision floating-point arithmetic. Double precision has about 15-16 significant decimal digits. Catastrophic cancellation occurs when subtracting nearly equal numbers.

  • Increases as step size h decreases
  • Independent of the mathematical problem being solved
  • Machine epsilon: eps ≈ 2.22 × 10^(-16) for double precision

Optimal Step Size

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:

h_opt ≈ (round-off magnitude / truncation error coefficient)^(1/(p+1))

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.

Condition Number

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

kappa(A) = ||A|| * ||A^(-1)||

For symmetric positive definite matrices: kappa = lambda_max / lambda_min (ratio of largest to smallest eigenvalue).

Interpretation

  • kappa ≈ 1: well-conditioned, full accuracy
  • kappa = 10^k: lose approximately k digits of accuracy
  • kappa near 1/eps: numerically singular in practice

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.

Method Comparison Tables

Root-Finding Methods

MethodOrderNeeds f'Guaranteed?
Bisection1 (linear)NoYes (if IVT holds)
Newton-Raphson2 (quadratic)YesNo
Secant1.618NoNo
Fixed-point1 (linear)NoIf |g'| less than 1

Numerical Integration Methods

MethodGlobal ErrorExact for DegreeNotes
TrapezoidalO(h^2)≤ 1Simple, n+1 evals
Simpson's 1/3O(h^4)≤ 3n must be even
Simpson's 3/8O(h^4)≤ 3n multiple of 3
Gauss-Legendre n-ptO(h^(2n))≤ 2n-1Non-uniform nodes

Worked Examples

Example 1 — Bisection: Find root of f(x) = x^3 - x - 2 on [1, 2]

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.

Example 2 — Newton-Raphson: Solve f(x) = x^2 - 2 = 0 starting at x_0 = 1

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...

Example 3 — Simpson's 1/3 Rule: Approximate integral of e^x from 0 to 1 with n = 4

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.

Example 4 — RK4: Solve y' = y, y(0) = 1 on [0, 0.5] with h = 0.5

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.

Example 5 — Lagrange Interpolation: Find P(x) through (0,1), (1,3), (3,2)

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 ✓

Frequently Asked Questions

What is the bisection method and when should you use it?

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.

What is the convergence order of Newton-Raphson and why does it matter?

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.

What is the difference between Lagrange interpolation and Newton's divided differences?

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.

How accurate is Simpson's 1/3 rule compared to the Trapezoidal rule?

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.

What is Runge-Kutta 4th order (RK4) and why is it the standard ODE solver?

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.

What is the difference between truncation error and round-off error?

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.

What is the condition number and why does it matter for numerical computations?

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.

What is fixed-point iteration and when does it converge?

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.

How do cubic splines differ from polynomial interpolation for large data sets?

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.

Related Topics

Practice Numerical Methods

Interactive problems with step-by-step solutions and private tutoring — free to try.

Start Practicing Free