Numerical Analysis

Ordinary Differential Equations (ODEs)

Numerical methods for solving initial value problems: Euler, Heun's, and Runge-Kutta

Initial Value Problem

y=2ty,y(0)=1,t[0,2]y' = -2ty, \quad y(0) = 1, \quad t \in [0, 2]

Exact solution: y(t)=et2y(t) = e^{-t^2}

11 steps

Step-by-Step Visualization

Step 0 / 10
Exact (dashed) Euler Slope field

Numerical Results

nt_ny_n (Euler)y(t_n) (Exact)Error
00.0001.0000001.0000000.00000000

Practice Problem

Use Euler's method with h=0.5h = 0.5 to approximate y(1)y(1) for the IVP:

y=y,y(0)=1y' = y, \quad y(0) = 1

Hint: Compute y(0.5) first, then use it to find y(1).

Implementation

INPUT: f(t, y), t0, y0, h, n_steps
OUTPUT: arrays t[], y[]

t[0] = t0
y[0] = y0
for i = 0, 1, ..., n_steps - 1:
    y[i+1] = y[i] + h * f(t[i], y[i])
    t[i+1] = t[i] + h

RETURN t, y