Zahri-Edu › Math-Applied › Applied Lab

Applied Lab

Six interactive models: ODE solvers, population growth, predator–prey, epidemics, the heat equation and stochastic differential equations.

Model 1

Euler vs Runge–Kutta

Solve y′ = f(t, y) numerically with step h. Euler's method has error O(h); the classical Runge–Kutta method (RK4) has error O(h⁴).

Halve h: the Euler error halves, the RK4 error drops about 16 times.

exactEulerHeun (RK2)RK4
Model 2

Population Growth

Malthus: P′ = rP gives exponential growth. Verhulst's logistic model P′ = rP(1 − P/K) adds a carrying capacity K.

Discrete version xₙ₊₁ = a xₙ(1 − xₙ): for a > 3 the population oscillates, and from a ≈ 3.57 on it becomes chaotic.

The same simple law produces equilibrium, cycles or chaos, depending on one parameter.

Model 3

Predator–Prey (Lotka–Volterra)

Prey x and predators y:   x′ = αx − βxy,   y′ = δxy − γy.

Populations cycle: many prey feed many predators, which then reduce the prey, and so on. In the phase plane the orbits are closed curves around the equilibrium (γ/δ, α/β).

Click the phase plane to start a new orbit. Integrated with RK4.

Model 4

The SIR Epidemic Model

Susceptible → Infected → Recovered:   S′ = −βSI,   I′ = βSI − γI,   R′ = γI.

The basic reproduction number R₀ = β/γ decides everything: an outbreak grows only if R₀ > 1. Vaccinating a fraction 1 − 1/R₀ gives herd immunity.

SIR
Model 5

The Heat Equation

u_t = D u_xx on [0, 1] with u = 0 at both ends, solved by explicit finite differences:

uᵢⁿ⁺¹ = uᵢⁿ + λ (uᵢ₊₁ⁿ − 2uᵢⁿ + uᵢ₋₁ⁿ),   λ = D Δt / Δx².

Stability (CFL condition): λ ≤ 1/2. Push λ above 0.5 and watch the scheme blow up. Click the plot to add heat.

Model 6

Brownian Motion & Stochastic ODEs

Geometric Brownian motion dX = μX dt + σX dW models stock prices and noisy growth. Euler–Maruyama: Xₙ₊₁ = Xₙ + μXₙΔt + σXₙ ΔWₙ, with ΔWₙ ~ N(0, Δt).

The mean of the paths follows E[X(t)] = X₀ e^{μt} (dashed), although individual paths wander randomly.

This is the setting of the notes on numerical schemes for SDEs: strong and weak convergence of Euler–Maruyama and Milstein.