Numerical MethodUnit 810 min read

Numerical ODEs: Euler, Runge-Kutta, Shooting & Systems

Unit 8 of Numerical Method covers solving ordinary differential equations (ODEs) numerically using Euler’s method, Runge-Kutta methods, shooting methods, and systems of ODEs, with applications in physics, finance, and engineering.

TAKEAWAYS:

  • ODEs model real-world change: From population growth to bank interest, ODEs describe dynamic systems where rates depend on variables (e.g., ).
  • Euler’s method is intuitive but limited: It approximates solutions step-by-step with , but errors accumulate for stiff equations.
  • Runge-Kutta improves accuracy: The 4th-order method (RK4) balances precision and computation, using weighted averages of slopes.
  • Shooting methods convert BVPs to IVPs: They guess initial conditions for boundary-value problems (BVPs) and refine iteratively.
  • Systems of ODEs model interactions: Coupled equations (e.g., predator-prey models) require vectorized methods like Euler or RK4.
  • Error control is critical: Local truncation error (LTE) and global error grow with step size ; adaptive methods adjust dynamically.

1. Ordinary Differential Equations (ODEs): Basics and Classification

ODEs describe how a quantity changes with respect to an independent variable . They are classified by:

  • Order: Highest derivative (e.g., is 2nd-order).
  • Linearity: Linear ODEs have and its derivatives to the first power (e.g., ).
  • Initial/Boundary Value Problems (IVP/BVP):
    • IVP: Specifies at a single point (e.g., ).
    • BVP: Specifies at multiple points (e.g., , ).
1st-order linear ODE: \( y' + p(x)y = q(x) \)
2nd-order linear ODE: \( y'' + a y' + b y = f(x) \)
Nonlinear ODE: \( y' = x^2 + y^2 \)
IVP example: \( y' = 3x^2 + 1 \), \( y(1) = 2 \)
BVP example: \( y'' + xy' - xy = 2x \), \( y(0)=1 \), \( y(2)=10 \)

Real-World Example 1: Bank Loan Interest (IVP)

A bank calculates loan repayment using the ODE for compound interest: where is the loan amount, is the interest rate, and is time. For a loan of Rs. 100,000 at 5% annual interest (), the exact solution is . Numerically solving this with Euler’s method approximates the loan balance over time.


2. Euler’s Method: The Simplest Numerical Approach

Euler’s method approximates solutions by linearizing the ODE over small steps : where .

Worked Example 1: Euler’s Method for , ,

Goal: Estimate . Steps:

  1. Start at , .
  2. Compute .
  3. Update:
  4. Repeat for , :
  5. Continue to :
x: [1.0, 1.2, 1.4, 1.6, 1.8, 2.0]
y: [2.0, 2.8, 3.824, 5.072, 6.566, 5.296] (approximate)
Exact solution at x=2: y(2) ≈ 5.333 (from integrating \( y = x^3 + x + C \))
Error: |5.296 - 5.333| ≈ 0.037

Advantages/Disadvantages of Euler’s Method

Advantages Disadvantages
Simple to implement Large errors for stiff equations
Low computational cost Requires very small for accuracy
Works for any Not suitable for BVPs without modification

3. Runge-Kutta Methods: Higher Accuracy

Euler’s method has local truncation error (LTE) . Runge-Kutta methods reduce this error by averaging slopes at intermediate points. The 4th-order Runge-Kutta (RK4) is widely used:

Worked Example 2: RK4 for , ,

Goal: Compare RK4 to Euler’s method. Steps:

  1. At , :
  2. Repeat for , :
  3. Continue to :
x: [1.0, 1.2, 1.4, 1.6, 1.8, 2.0]
Euler y: [2.0, 2.8, 3.824, 5.072, 6.566, 5.296]
RK4 y:   [2.0, 2.8827, 3.9366, 5.1606, 6.5556, 5.3330]
Exact y: [2.0, 2.88, 3.936, 5.16, 6.556, 5.333]

Comparison: Euler vs. RK4

Method Error at Order Computational Cost
Euler 0.037 Low
RK4 ~0 Higher

4. Shooting Method for Boundary Value Problems (BVPs)

BVPs specify conditions at multiple points (e.g., , ). The shooting method converts a BVP into an IVP by guessing an initial slope and adjusting iteratively.

Worked Example 3: Shooting Method for , ,

Steps:

  1. Rewrite as a system of 1st-order ODEs:
  2. Guess (initial slope). Use Euler’s method to solve the system from to .
  3. Compare to the target (10). Adjust using regula falsi or Newton’s method until .
flowchart TD
    A["Guess \( v(0) = c_0 \)"] --> B["Solve IVP using Euler/RK4"]
    B --> C["Check \( y(2) \) vs. 10"]
    C -->|"If  y(2) < 10 "| D["Increase \( c \)"]
    C -->|"If  y(2) > 10 "| E["Decrease \( c \)"]
    D --> A
    E --> A

Real-World Example 2: Daraz Order Fulfillment (BVP)

Daraz’s warehouse uses BVPs to model inventory levels across regions. The ODE for inventory at a warehouse satisfies: with boundary conditions:

  • ,
  • . The shooting method helps optimize restocking schedules.

5. Systems of ODEs: Modeling Interacting Variables

Systems of ODEs describe coupled dynamics (e.g., predator-prey models, electrical circuits). The general form is: where .

Worked Example 4: Euler’s Method for a System

Solve: Steps:

  1. At , :
  2. At , :
  3. Continue to :
x: [0.0, 0.1, 0.2]
y: [1.0000, 1.0500, 1.1025, 1.1607]

Real-World Example 3: Kathmandu Traffic Flow (System of ODEs)

Traffic engineers model vehicle flow and density using: Euler’s method simulates congestion patterns to optimize signal timings.


6. Error Analysis and Step Size Control

  • Local Truncation Error (LTE): Error per step (e.g., for Euler).
  • Global Error: Accumulated over all steps (e.g., for Euler).
  • Adaptive Methods: Adjust dynamically (e.g., Runge-Kutta-Fehlberg (RKF45)).
Step size (h): [0.1, 0.05, 0.01]
Global Error:  [0.05, 0.025, 0.005]

In the Real World

  1. eSewa/Khalti Transactions (ODEs for Fraud Detection)

    • Banks use ODEs to model transaction rates , where is transaction volume. Anomalies (e.g., sudden spikes) trigger fraud alerts. Euler’s method approximates to detect unusual patterns.
  2. Pathao Driver Routing (Shooting Method for BVPs)

    • Pathao’s algorithm solves BVPs to find optimal routes between pickup/drop points. The ODE for distance satisfies: The shooting method guesses initial acceleration to minimize travel time.
  3. NTC Electricity Demand Forecasting (Systems of ODEs)

    • NTC models demand and supply using: Euler’s method predicts blackout risks during peak hours.

Exam Tip

  1. For IVPs:

    • Always show the Euler/RK4 update formula explicitly.
    • Compare numerical results to exact solutions (if possible) to highlight errors.
    • Example: In the exam, if asked to solve with Euler, write: and compute at least 3 steps.
  2. For BVPs:

    • Explain the shooting method’s iteration process (guess, solve IVP, adjust).
    • Use regula falsi or Newton’s method for adjustment (mention convergence criteria).
  3. For Systems of ODEs:

    • Rewrite higher-order ODEs as 1st-order systems (e.g., becomes , ).
    • Apply Euler/RK4 component-wise.
  4. Common Pitfalls:

    • Forgetting to update in each step ().
    • Misapplying boundary conditions in BVPs (e.g., mixing IVP/BVP setups).
    • Ignoring units in real-world examples (e.g., in years for population models).
  5. High-Score Strategies:

    • Draw diagrams: Sketch the ODE’s slope field and numerical solution trajectory.
    • Label clearly: In RK4, write with their formulas.
    • Discuss limitations: For Euler, mention "large errors for stiff equations" or "requires small ".

Visual Summary of Methods:

mindmap
  root((Numerical ODEs))
    Euler
      Formula: y_{n+1} = y_n + h*f(x_n, y_n)
      Error: O(h)
      Use: Simple problems
    RK4
      Formula: Weighted avg of 4 slopes
      Error: O(h^4)
      Use: High accuracy needed
    Shooting Method
      Steps: Guess -> Solve IVP -> Adjust
      Use: BVPs
    Systems
      Form: dy/dx = f(x, y1, y2, ...)
      Method: Apply Euler/RK4 to each component

Based on the TU BIT syllabus for Numerical Method (BIT203), unit 8.

Discussion

Loading…