2.6 Numerical Methods: Linear Systems, Interpolation, Curve Fitting, and ODE Solvers

Key Takeaways

  • Gaussian elimination reduces a linear system to upper-triangular form and then solves it by back substitution.

  • Gauss-Seidel iteration converges reliably when the coefficient matrix is diagonally dominant.

  • A Lagrange or Newton polynomial through n + 1 data points has degree at most n and reproduces every point exactly.

  • The central difference [f(x+h) − f(x−h)]/(2h) has error of order h², better than the order-h forward difference.

  • The classical fourth-order Runge-Kutta method has global error of order h⁴, while Euler's method is only first order.

Last updated: October 2026

2.6 Numerical Methods: Linear Systems, Interpolation, Curve Fitting, and ODE Solvers

The AMSTHC TOS area "Numerical Methods for Engineers" has five competencies:

  1. Recall linear algebra and the physical meaning of derivatives and integrals.
  2. Solve systems of linear equations.
  3. Use curve fitting and interpolation.
  4. Apply numerical differentiation and integration.
  5. Evaluate ordinary differential equations and boundary-value problems.

Root finding and Simpson's rules are in Section 2.4. This section covers the rest. Most items can be done on an allowed scientific calculator, many of which solve 2×2 and 3×3 systems directly. You must still know the method behind the answer.


Matrix Essentials

OperationRule
Product ABABDefined when columns of AA = rows of BB; (AB)ij=∑kaikbkj(AB)_{ij} = \sum_k a_{ik} b_{kj}
Determinant (2×2)det⁡[abcd]=ad−bc\det\begin{bmatrix} a & b \\ c & d \end{bmatrix} = ad - bc
Inverse (2×2)A−1=1ad−bc[d−b−ca]A^{-1} = \dfrac{1}{ad - bc}\begin{bmatrix} d & -b \\ -c & a \end{bmatrix}
Singular matrixdet⁡A=0\det A = 0: no unique solution
Transpose(AB)T=BTAT(AB)^T = B^T A^T

A 3×3 determinant is found by cofactor expansion or by the diagonal rule (Sarrus).


Solving Simultaneous Linear Equations

Cramer's rule. For Ax=bA\mathbf{x} = \mathbf{b}, xi=det⁡Ai/det⁡Ax_i = \det A_i / \det A, where AiA_i is AA with column ii replaced by b\mathbf{b}. It is practical for 2 or 3 unknowns.

Gaussian elimination. Use row operations to make the matrix upper-triangular, then back-substitute. Partial pivoting, which swaps rows to put the largest coefficient on the diagonal, reduces round-off error.

Example. Solve 2x+y−z=32x + y - z = 3, x+3y+2z=13x + 3y + 2z = 13, 3x+y+3z=143x + y + 3z = 14.

  • Eliminate xx: R2 − ½R1 gives 2.5y+2.5z=11.52.5y + 2.5z = 11.5. R3 − 1.5R1 gives −0.5y+4.5z=9.5-0.5y + 4.5z = 9.5.
  • Eliminate yy: R3 + 0.2R2 gives 5z=11.85z = 11.8, so z=2.36z = 2.36.
  • Back-substitute: y=(11.5−2.5×2.36)/2.5=2.24y = (11.5 - 2.5 \times 2.36)/2.5 = 2.24, and x=(3−2.24+2.36)/2=1.56x = (3 - 2.24 + 2.36)/2 = 1.56.

Check in equation 3: 3(1.56)+2.24+3(2.36)=4.68+2.24+7.08=14.003(1.56) + 2.24 + 3(2.36) = 4.68 + 2.24 + 7.08 = 14.00.

Iterative methods. Jacobi updates every unknown from the previous iteration's values. Gauss-Seidel uses each new value as soon as it is available, so it usually converges faster. Both converge when the matrix is diagonally dominant, meaning each diagonal coefficient exceeds the sum of the other coefficients in its row. Large structural stiffness and pipe-network systems are solved this way.


Interpolation

Lagrange form through (x0,y0),…,(xn,yn)(x_0, y_0), \dots, (x_n, y_n):

P(x)=∑i=0nyi∏j≠ix−xjxi−xjP(x) = \sum_{i=0}^{n} y_i \prod_{j \ne i} \frac{x - x_j}{x_i - x_j}

Newton divided differences build the same polynomial incrementally:

P(x)=f[x0]+f[x0,x1](x−x0)+f[x0,x1,x2](x−x0)(x−x1)+⋯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) + \cdots

The benefit is that adding a new data point only adds one more term.

Example. A rating curve gives Q=2.0Q = 2.0, 5.05.0 and 10.0 m3/s10.0\text{ m}^3/\text{s} at stages 1.01.0, 2.02.0 and 3.0 m3.0\text{ m}. Estimate QQ at 2.5 m2.5\text{ m}.

  • Divided differences: f[x0,x1]=3.0f[x_0,x_1] = 3.0, f[x1,x2]=5.0f[x_1,x_2] = 5.0, f[x0,x1,x2]=(5.0−3.0)/2=1.0f[x_0,x_1,x_2] = (5.0 - 3.0)/2 = 1.0.
  • P(2.5)=2.0+3.0(1.5)+1.0(1.5)(0.5)=2.0+4.5+0.75=7.25 m3/sP(2.5) = 2.0 + 3.0(1.5) + 1.0(1.5)(0.5) = 2.0 + 4.5 + 0.75 = 7.25\text{ m}^3/\text{s}.
  • Linear interpolation between the last two points would give 7.57.5, so the curvature matters.

Caution

High-degree polynomials through many equally spaced points can oscillate wildly near the ends (Runge's phenomenon). Use piecewise or spline interpolation for long data sets.


Curve Fitting by Least Squares

When data contain scatter, fit a curve that minimizes the sum of squared vertical errors rather than passing through every point. The straight-line case, with slope and intercept formulas, correlation and R2R^2, is treated in Section 3.2.

Nonlinear relationships are often linearized:

ModelTransformLinear form
y=aebxy = a e^{bx}take ln⁡y\ln yln⁡y=ln⁡a+bx\ln y = \ln a + bx
y=axby = a x^btake log⁡\log of both sideslog⁡y=log⁡a+blog⁡x\log y = \log a + b\log x
y=a+b/xy = a + b/xlet u=1/xu = 1/xy=a+buy = a + bu

Fit a line to the transformed data, then convert back.


Numerical Differentiation

FormulaExpressionError order
Forward differencef(x+h)−f(x)h\dfrac{f(x+h) - f(x)}{h}O(h)O(h)
Backward differencef(x)−f(x−h)h\dfrac{f(x) - f(x-h)}{h}O(h)O(h)
Central differencef(x+h)−f(x−h)2h\dfrac{f(x+h) - f(x-h)}{2h}O(h2)O(h^2)
Second derivative (central)f(x+h)−2f(x)+f(x−h)h2\dfrac{f(x+h) - 2f(x) + f(x-h)}{h^2}O(h2)O(h^2)

Example. Water-surface elevations of 10.4010.40, 10.2510.25 and 10.06 m10.06\text{ m} are read at x=0x = 0, 100100 and 200 m200\text{ m}. The central-difference slope at x=100x = 100 is (10.06−10.40)/200=−0.0017(10.06 - 10.40)/200 = -0.0017.

Reducing hh lowers truncation error, but very small hh magnifies round-off error.


Numerical Solution of Ordinary Differential Equations

For y′=f(x,y)y' = f(x, y) with y(x0)=y0y(x_0) = y_0 and step hh:

MethodUpdateGlobal error
Euleryn+1=yn+hf(xn,yn)y_{n+1} = y_n + h f(x_n, y_n)O(h)O(h)
Heun (improved Euler)predictor y∗=yn+hf(xn,yn)y^* = y_n + hf(x_n,y_n); yn+1=yn+h2[f(xn,yn)+f(xn+1,y∗)]y_{n+1} = y_n + \frac{h}{2}[f(x_n,y_n) + f(x_{n+1},y^*)]O(h2)O(h^2)
Runge-Kutta 4yn+1=yn+h6(k1+2k2+2k3+k4)y_{n+1} = y_n + \frac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4)O(h4)O(h^4)

The RK4 slopes are:

k1=f(xn,yn),k2=f ⁣(xn+h2,yn+h2k1),k3=f ⁣(xn+h2,yn+h2k2),k4=f(xn+h,yn+hk3)k_1 = f(x_n, y_n), \quad k_2 = f\!\left(x_n + \tfrac{h}{2}, y_n + \tfrac{h}{2}k_1\right), \quad k_3 = f\!\left(x_n + \tfrac{h}{2}, y_n + \tfrac{h}{2}k_2\right), \quad k_4 = f(x_n + h, y_n + hk_3)

Example. For y′=x+yy' = x + y with y(0)=1y(0) = 1 and h=0.1h = 0.1:

  • Euler gives y(0.1)=1+0.1(0+1)=1.100y(0.1) = 1 + 0.1(0 + 1) = 1.100.
  • Heun: the predictor is 1.1001.100, and f(0.1,1.100)=1.200f(0.1, 1.100) = 1.200. So y=1+0.05(1+1.2)=1.110y = 1 + 0.05(1 + 1.2) = 1.110.
  • The exact solution y=2ex−x−1y = 2e^x - x - 1 gives 1.110341.11034. Heun is much closer than Euler.

Boundary-value problems. These specify conditions at two ends, like a beam's deflection at both supports. There are two common approaches:

  • The shooting method guesses the missing initial slope, integrates, and adjusts the guess until the far-end condition is met.
  • The finite-difference method replaces derivatives with difference formulas at interior nodes, producing a system of linear equations.
Loading diagram...
Picking a Numerical Method
Test Your Knowledge

For y' = x + y with y(0) = 1, what does one step of Euler's method with h = 0.2 give for y(0.2)?

A

1.240

B

1.400

C

1.200

D

1.243

Test Your Knowledge

Which iterative method for solving simultaneous linear equations immediately uses each newly computed unknown within the same iteration?

A

Jacobi iteration

B

Cramer's rule

C

Gauss-Seidel iteration

D

Newton divided differences

Test Your Knowledge

A function is tabulated as f(1.9) = 6.859, f(2.0) = 8.000 and f(2.1) = 9.261. What is the central-difference estimate of f'(2.0)?

A

11.41

B

12.61

C

13.80

D

12.01

Sections you finish are checked off in the contents.