Numerical ODE Solver: Euler’s & Runge-Kutta Methods

Numerical ODE Solver (Euler vs RK4)

Numerical ODE Solver

Solve $y’ = f(t, y)$ using Euler’s Method and Runge-Kutta (RK4) methods.

Problem Setup

Linear Exponential Logistic

Solution Results

Final Value y(T)
RK4: —

Visualization

RK4 (Accurate) Euler (Approx)

Iteration Log (First 8)

tEuler yRK4 y

Numerical Methods for ODEs

Many differential equations cannot be solved analytically. Numerical methods allow us to approximate the solution curve by stepping forward in time.

Euler’s Method

The simplest method. It uses the tangent line at the current point to predict the next point.

y_{n+1} = y_n + h \cdot f(t_n, y_n)

Error is proportional to step size $h$. Requires very small steps for accuracy.

Runge-Kutta (RK4)

The industry standard. It takes a weighted average of four slopes to predict the next point, cancelling out errors.

y_{n+1} = y_n + \frac{h}{6}(k_1 + 2k_2 + 2k_3 + k_4)

Error is proportional to $h^4$. Highly accurate even with larger steps.

FAQ

Why does Euler’s method drift?
Euler’s method assumes the slope is constant over the entire interval $h$. In reality, the slope usually changes. This linear approximation creates a “local truncation error” at every step, which accumulates into a larger “global error” over time.
What is step size (h)?
The step size $h$ determines how far we jump forward in time. A smaller $h$ reduces error but increases computational work. If $h$ is too large, the method may become unstable and produce wild oscillations.

UNDERGRADUATE