UNIHIVE

Study Hub UNIPORT MTH 492

MTH 492 · Numerical Methods

Finite differences for linear boundary value problems

Replacing derivatives by differences, the tridiagonal system, and the Thomas algorithm.

Our notes

2 min read

The problem

A linear two-point boundary value problem (BVP):
y″ + p(x)y′ + q(x)y = r(x), a ≤ x ≤ b, with y(a) = α, y(b) = β.
Examples: deflection of a beam, steady temperature in a rod, the shape of a cable.

Difference formulas

On a grid xᵢ = a + ih, i = 0, ..., N, h = (b − a)/N:

  • y″(xᵢ) ≈ (yᵢ₋₁ − 2yᵢ + yᵢ₊₁)/h²
  • y′(xᵢ) ≈ (yᵢ₊₁ − yᵢ₋₁)/(2h)

Both are second order: error O(h²).

The system

Substituting at each interior node gives one linear equation per node, linking yᵢ₋₁, yᵢ, yᵢ₊₁: a tridiagonal system. The boundary values move to the right-hand side.

Worked example

y″ = 4(y − x), y(0) = 0, y(1) = 2, h = 0.25 (exact y = x + sinh 2x / sinh 2).
At node i: (yᵢ₋₁ − 2yᵢ + yᵢ₊₁)/0.0625 = 4(yᵢ − xᵢ), so
yᵢ₋₁ − 2.25yᵢ + yᵢ₊₁ = −0.25xᵢ

  • i = 1 (x = 0.25): 0 − 2.25y₁ + y₂ = −0.0625
  • i = 2 (x = 0.5): y₁ − 2.25y₂ + y₃ = −0.125
  • i = 3 (x = 0.75): y₂ − 2.25y₃ + 2 = −0.1875, so y₂ − 2.25y₃ = −2.1875

Solving:

xFinite differenceExact
0.250.395120.39368
0.50.826530.82403
0.751.339571.33709

The error (about 0.0025) falls by about 4 when h is halved, as O(h²) predicts.

Check by substitution at i = 2: 0.39512 − 2.25(0.82653) + 1.33957 = −0.12500. ✓

The Thomas algorithm

A tridiagonal system aᵢyᵢ₋₁ + bᵢyᵢ + cᵢyᵢ₊₁ = dᵢ is solved in O(N) operations:

  1. Forward sweep: c′₁ = c₁/b₁, d′₁ = d₁/b₁; then for i = 2...N: m = bᵢ − aᵢc′ᵢ₋₁, c′ᵢ = cᵢ/m, d′ᵢ = (dᵢ − aᵢd′ᵢ₋₁)/m.
  2. Back substitution: y_N = d′_N, then yᵢ = d′ᵢ − c′ᵢyᵢ₊₁.

It is Gaussian elimination that skips all the zeros. It is stable when the matrix is diagonally dominant (|bᵢ| ≥ |aᵢ| + |cᵢ|), as here.

Derivative boundary conditions

For y′(b) = γ, add a "ghost" node y_{N+1} and use (y_{N+1} − y_{N−1})/(2h) = γ to eliminate it.

Exams usually ask

  • Set up and solve the finite difference equations for a BVP with h = 0.25 or 0.2.
  • Describe the Thomas algorithm.

Common mistake

Forgetting to move the known boundary values to the right-hand side of the first and last equations.

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All MTH 492 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.