Numerical MethodsUnit 78 min read

Numerical ODEs: Euler, RK4, Multistep & Applications

Unit 7 of Numerical Methods covers solving Ordinary Differential Equations (ODEs) numerically—from Euler’s method to Runge-Kutta, multistep techniques, and error analysis—with engineering applications like trajectory modeling, heat transfer, and population growth.

TAKEAWAYS:

  • ODEs in engineering: Real-world problems (e.g., motion, circuits, biology) are modeled by ODEs, which rarely have analytical solutions—numerical methods approximate solutions step-by-step.
  • Euler’s method: The simplest single-step method, but inaccurate for stiff equations due to linear approximation (y_{n+1} = y_n + h·f(x_n, y_n)).
  • Runge-Kutta (RK4): A 4th-order method balancing accuracy and computation (w_1 = h·f(x_n, y_n), w_2 = h·f(x_n + h/2, y_n + w_1/2), etc.), used in finance (option pricing) and physics simulations.
  • Multistep methods (Adams-Bashforth): Use past values (y_{n+1} = y_n + h/24·(55f_n – 59f_{n-1} + 37f_{n-2} – 9f_{n-3})) for efficiency but require initial steps from single-step methods.
  • Error analysis: Local truncation error (LTE) and global error grow with step size h; smaller h improves accuracy but increases computation time.
  • Real-world tie-ins: Pathao’s ride-distance calculator (ODEs for trajectory), NTC’s power-grid stability (ODEs for load dynamics), and Daraz’s inventory forecasting (logistic growth models).

1. Why Numerical ODEs?

ODEs describe dynamic systems (e.g., dy/dx = f(x, y)), but only ~5% have closed-form solutions. Numerical methods approximate solutions by discretizing the domain.

Example: Population Growth

The logistic ODE models limited growth: where:

  • = population at time ,
  • = growth rate,
  • = carrying capacity.
12345678910246810xyExact Solution: P(t)
Comparison: Exact vs. Euler’s Method for logistic growth (first 10 steps)

logistic growth curve**A sigmoid (S-shaped) curve showing exponential growth tapering to . (Image: Qef (talk), Public domain, via Wikimedia Commons)


2. Single-Step Methods

0.020.040.060.080.10.120.140.160.180.211.051.11.151.2yEuler (h=0.1)RK4 (h=0.1)Euler y(0.2)RK4 y(0.2)
Euler vs. RK4 for dy/dx = x + y² over 0 ≤ x ≤ 0.2

(a) Euler’s Method

Definition: Uses tangent-line approximation over small steps h. Worked Example: Solve , for with .

Steps:

Error: Euler’s LTE is ; global error .

(b) Runge-Kutta (RK4)

Definition: A weighted average of slopes at intermediate points for higher accuracy. Worked Example: Same ODE, using RK4.

Comparison Table:

Method Order Steps for Error ()
Euler 1 2 1.2100 (0.0004)
RK4 4 2 1.2104 (0.0000)

3. Multistep Methods

Use past values to compute future steps (e.g., Adams-Bashforth). Adams-Bashforth 4-step: Worked Example: Solve , for with .

flowchart TD
    A["Start: Obtain first 3 values with RK4"] --> B["Store f₀,f₁,f₂"]
    B --> C["Apply Adams‑Bashforth formula"]
    C --> D["Compute yₙ₊₁"]
    D --> E{"More steps?"}
    E -- Yes --> B
    E -- No --> F["Finish"]
Workflow for initializing and iterating an Adams‑Bashforth multistep method

Trace:

  1. Use RK4 to compute (initial steps).
  2. For :

Advantages:

  • Fewer function evaluations per step.
  • Disadvantages: Requires starting values; unstable for stiff equations.

4. Error Analysis

Local Truncation Error (LTE): Error introduced in one step. Global Error: Accumulated over all steps. Stability: Methods like Euler may diverge for stiff ODEs (e.g., , ).


In the Real World

  1. Pathao’s Ride Distance Calculation

    • ODE Used: , where is position and is velocity (from GPS data).
    • Method: RK4 approximates the rider’s trajectory to compute distance and fare.
    • Example: For a ride from Thapathali to Lakshmi Narayan, Pathao’s backend solves this ODE with seconds to estimate the 3.2 km distance.
  2. NTC’s Power Grid Stability

    • ODE Used: Swing equation for generator angles: where is rotor angle, is mechanical power, and P_e \.electrical power. - **Method**: Adams-Bashforth predicts load fluctuations to prevent blackouts. 3. **Daraz’s Inventory Forecasting** - **ODE Used**: Logistic growth for product demand: \[ \frac{dD}{dt} = rD \left(1 - \frac{D}{D_{\text{max}}}\right). \] - **Method**: Euler’s method forecasts stock levels (e.g., for iPhones) to trigger reorders. --- ### **5. Worked Example: Projectile Motion** **Problem**: Find the height of a ball thrown upward at \( v_0 = 20 \, \text{m/s} at , ignoring air resistance. ODE: , , , .

Solution with RK4:

  1. Define , :
  2. Use RK4 with :
    • At , .

6. Choosing a Method

Method Order Stability Use Case
Euler 1 Poor Simple problems, teaching
RK4 4 Good General-purpose (engineering)
Adams-Bashforth 4 Moderate Long simulations (climate models)
Predictor-Corrector 2-4 Better Stiff ODEs (chemical reactions)

Exam Tip

  1. Always show intermediate steps in RK4/Adams-Bashforth (examiners check ).
  2. For stiff ODEs, mention stability conditions (e.g., "Euler fails for ").
  3. Real-world questions: Relate to trajectory (Pathao), heat transfer (NTC grids), or growth models (Daraz inventory).
  4. Error bounds: If asked for accuracy, state LTE/global error orders (e.g., "RK4 has LTE ").
  5. Graphs: Sketch solution curves (e.g., logistic growth) and error plots to visualize convergence.

Key Formula Cheat Sheet:

5101520253035404550200040006000800010000xyLogistic Growth: P(t) = K·P₀·e^(rt)/(K + (P₀-1)·e^(rt))P₀ = 100K = 1000
Sigmoid curve for population growth with K = 1000, r = 0.1, P₀ = 100

In the real world

  • Pathao uses RK4 to integrate GPS‑derived velocity vectors, giving a smooth trajectory and accurate fare calculation.
  • NTC (National Transmission & Dispatch Company) predicts generator rotor‑angle dynamics with a 4‑step Adams‑Bashforth predictor, enabling real‑time stability monitoring.
  • Daraz forecasts product demand using Euler’s method on a logistic growth ODE, automatically triggering inventory re‑orders when the projected stock falls below a threshold.

Based on the PU BE Computer (PU) syllabus for Numerical Methods, unit 7.

Discussion

Loading…