Solution of Ordinary Differential Equations (ODE)
Open in the Padhaiko app5.1 Initial value problems
An initial value problem (IVP) for a first-order ordinary differential equation specifies the derivative and the state at a single starting point :
Numerical methods advance the solution across discrete mesh points with step size , producing approximations .
5.1.1 Solution of first order equations: Taylor’s series method, Euler’s method, Runge-Kutta methods (Second and fourth order)
Taylor's Series Method
Expanding around (or ) by Taylor's theorem gives:
where , and higher derivatives are obtained by repeatedly differentiating via the chain rule:
- Pros / Cons: Very high accuracy for small , but requires tedious symbolic differentiation of at every order.
Euler's Method
Truncating the Taylor series after the linear term produces Euler's method (the simplest -stage, first-order Runge–Kutta method):
Euler's Method
- Local truncation error: per step; Global error: (first-order accurate).
Runge–Kutta Methods (Second and Fourth Order)
Runge–Kutta (RK) methods match the accuracy of higher-order Taylor expansions without computing analytical derivatives, by evaluating at carefully weighted intermediate points inside .
Second-Order (Heun's) and Fourth-Order Runge–Kutta Formulas
- Second-Order Runge–Kutta (RK2 / Heun's Method, global error):
(Equivalently, the RK2 midpoint variant uses and .)
- Classical Fourth-Order Runge–Kutta (RK4, global error):
| Method | Function Evaluations / Step | Local Error | Global Error | Key Trade-off |
|---|---|---|---|---|
| Euler | Simple, requires very small | |||
| RK2 (Heun) | Predictor–corrector slope average | |||
| RK4 | Industry standard for smooth non-stiff ODEs | |||
| Taylor (-th) | (+ derivatives) | Needs symbolic partial derivatives |
5.1.2 Solution of system of first order ODEs via Runge-Kutta methods
Consider a coupled system of two first-order ODEs:
In vector RK4, both and are advanced simultaneously at each sub-stage ( increments , and increments ):
RK4 for a System of Two First-Order ODEs
(Crucial rule: compute both and at stage before computing and .)
5.1.3 Solution of second order ODEs via Runge-Kutta methods
Any second-order IVP
is reduced to a system of two first-order ODEs by introducing the auxiliary variable :
with initial conditions and . This system is then solved directly using the coupled RK2 or RK4 formulas above. (Similarly, an -th order ODE converts into a system of first-order ODEs.)
5.2 Two-point boundary value problems
In a two-point boundary value problem (BVP) over , conditions on (or ) are prescribed at both endpoints rather than at a single initial point:
5.2.1 Shooting method
The shooting method converts the BVP into an IVP by guessing the missing initial slope , integrating forward from to with Euler or Runge–Kutta, and adjusting until the computed endpoint value hits the target (i.e., finding a root of ).
Shooting Method for Linear and Non-Linear BVPs
- For a linear BVP (): Choose two trial slopes and , integrate the IVP twice to obtain and . By linearity, one linear interpolation gives the exact required initial slope:
Re-integrate once with to obtain the full solution.
- For a non-linear BVP: is non-linear in ; apply a root-finding method such as the Secant method (or Bisection / Newton) iteratively on until .
5.2.2 Finite difference method
The finite difference method discretizes the entire domain simultaneously on a uniform grid (, ), replacing derivatives at each interior node () with central finite differences of accuracy:
Substituting these into a linear ODE with and produces a tridiagonal system of linear algebraic equations for the interior values :
Solving this linear system yields all nodal values at once without guessing initial slopes.
| Aspect | Shooting Method | Finite Difference Method |
|---|---|---|
| Core Idea | Converts BVP to IVP by guessing and solving | Replaces derivatives with difference quotients at interior grid points |
| Algebraic Problem | Repeated IVP integration + root-finding on | Single linear (or non-linear) algebraic system in |
| Stability / Sensitivity | Sensitive if the IVP has rapidly growing exponential modes | Globally stable and naturally handles stiff linear BVPs |
Worked Out Examples
5.1
Given with , compute using:
- Euler's method with step size ( steps)
- Fourth-order Runge–Kutta (RK4) method with ( step)
Compare with the exact solution .
Computing by Euler's method (): Using :
- First step ():
- Second step ():
Computing by RK4 (): With , :
Combining the four slopes:
Compared with the exact value :
- Euler (): (error )
- RK4 (): (error )
5.2
Using the fourth-order Runge–Kutta (RK4) method with , find and for the second-order initial value problem:
Converting to a system of two first-order ODEs: Let . Then:
with , and .
Evaluating the four coupled RK4 stages:
- Stage 1:
- Stage 2 (at ):
- Stage 3 (at ):
- Stage 4 (at ):
Updating and :
By RK4 with , and (exact ).
5.3
Solve the two-point boundary value problem
using the finite difference method with step size .
Discretizing the domain with : The grid nodes are , with boundary values and . Replacing by the central difference :
Forming the tridiagonal system:
- For (, ):
- For ():
- For (, ):
In matrix form:
Solving by Gauss elimination: Eliminating from row ():
Eliminating from row ():
Back-substituting for and :
The finite difference approximations at the interior nodes are , , and (exact values from : ).
Exercises
Exercise — Solution of Ordinary Differential Equations (ODE)
Distinguish between an initial value problem (IVP) and a two-point boundary value problem (BVP). Explain how the shooting method solves a non-linear second-order BVP with .
Distinguishing IVPs and BVPs:
- In an IVP, all auxiliary conditions () are given at a single starting point , so single-step solvers (Euler, Taylor, RK2, RK4) can march forward step by step from .
- In a BVP, conditions are split across two boundary points and (e.g., and ), so we do not have enough information at alone to start an IVP integrator.
Shooting method for a non-linear BVP:
- Rewrite as the first-order system , with and an unknown initial slope .
- Pick two initial slope guesses and , integrate the IVP from to using RK4 (or RK2) to obtain endpoint residuals and .
- Because the ODE is non-linear, is non-linear in ; update iteratively using the Secant method:
until .
An IVP specifies all conditions at one point , whereas a BVP specifies conditions at two endpoints and . For a non-linear BVP, the shooting method guesses the missing slope , integrates the resulting IVP to , and iterates with a root-finder (such as the Secant method) until .
Use Taylor's series method (up to the term) to approximate and for the IVP:
Computing derivatives at :
Writing the Taylor polynomial and evaluating at and :
- At :
- At :
Using the th-degree Taylor series, and .
Solve with to find using the second-order Runge–Kutta (Heun's) method with step size .
First step ():
Second step ():
Using Heun's RK2 method with , and .
Solve the system of coupled first-order ODEs
with to find and using the fourth-order Runge–Kutta (RK4) method with .
Computing the four simultaneous RK4 stages ():
- Stage 1:
- Stage 2 (at ):
- Stage 3 (at ):
- Stage 4 (at ):
Updating and :
By RK4 with , and (exact ).
Solve the linear two-point boundary value problem
by the shooting method, using Heun's (RK2) method with and initial slope guesses and . Estimate .
Converting to a first-order system and shooting with : Let , with and . For :
- First interval ():
- Second interval ():
Shooting with and interpolating the exact initial slope: Since the equation is linear and homogeneous with , doubling doubles every value:
Integrating one step () with :
(And the second step yields .)
The required initial slope is , giving (exact ).