VKCMVI
COMPUTATIONAL MATHEMATICS

Sweep method (Thomas algorithm)

Solve linear second-order boundary-value problems with finite differences, Robin conditions and tridiagonal sweep tables.

Calculator

Load the problem, then select Solve to view the steps. Some advanced examples intentionally fail or do not converge.

Method and applicability

Sweep method (Thomas algorithm)

liyi−1+diyi+uiyi+1=ri

The discretized tridiagonal system must admit nonzero sweep pivots. Boundary derivatives use first-order one-sided differences.

Results

Worked examples

Basic 1

y″ = −2; y(0) = y(1) = 0

Expected result: y = (0, 1/4, 0)

Calculation steps
  1. n = 2; h = 1/2; y₀ = y₂ = 0
  2. 4y₀ − 8y₁ + 4y₂ = −2
  3. y₁ = 1/4; (y₀, y₁, y₂) = (0, 1/4, 0)
  4. y(x) = x(1 − x); y″ = −2

Source: Original exercise

Academic 2

T″ − 166(T − 293) = 0; T(0) = 473; T(0.1) = 293; n = 5

Expected result: T ≈ (473, 424.455861, 384.640390, 350.909842, 321.024507, 293) K

Calculation steps
  1. h = 0.02; 2500Tᵢ₋₁ − 5166Tᵢ + 2500Tᵢ₊₁ = −48638
  2. T₀ = 473; T₅ = 293

The problem is from TU Delft; reference node values were independently computed for this discretization.

Source: TU Delft · MUDE §2.9

Advanced 3

y″ = 0; y′(0) + 2y(0) = 1; y(1) = 0; n = 2

Expected result: y(x) = 1 − x; d₀ = 0

Calculation steps
  1. y(x) = 1 − x → y′(0) + 2y(0) = 1
  2. d₀ = 2 − 1/h = 0

The boundary problem is solvable but unpivoted Thomas elimination cannot proceed.

Source: Original exercise

Accuracy and common pitfalls

A zero sweep pivot can occur even for a solvable boundary-value problem. Discrete residuals and mesh differences measure different aspects of accuracy.

Recommended reading