Differential Equation Solver
Solve first-order ODEs numerically using Runge-Kutta 4.
Number
Counts
About this topic
What is an ODE? An equation involving a function and its derivatives.
An Ordinary Differential Equation (ODE) relates a function to its derivatives with respect to a single variable. Solving it means finding the function that satisfies the equation.
Key formulas & rules
- •Order = highest derivative present
- •Linear if no products of y and its derivatives
- •Homogeneous if RHS = 0
- •General solution has arbitrary constants
- •Particular solution requires initial conditions
- •Existence & uniqueness guaranteed under mild conditions
Examples
| Input | Output | Note |
|---|---|---|
| dy/dx = y | y = Ce^x | First order |
| y″ + y = 0 | y = A·sin x + B·cos x | Second order |
| dy/dx = −y, y(0)=5 | y = 5e^(−x) | With IC |
| dy/dx = 2x | y = x² + C | Simple integration |
Real-world uses
Euler Method Simplest numerical method — one step at a time.
Euler's method approximates the solution by following the tangent line at each step. It's easy to implement but has limited accuracy.
Key formulas & rules
- •y_{n+1} = y_n + h·f(x_n, y_n)
- •First-order accuracy: error ∝ h
- •Small h → higher accuracy
- •Unstable for stiff equations
- •Fast but imprecise
- •Basis for more advanced methods
Examples
| Input | Output | Note |
|---|---|---|
| dy/dx = y, y(0)=1, h=0.1 | y(1) ≈ 2.59 | vs exact e ≈ 2.718 |
| h = 0.01 | y(1) ≈ 2.70 | Better with smaller h |
| h = 1 | y(1) = 2 | Very rough |
| dy/dx = x, y(0)=0 | Parabola | Approximation |
Real-world uses
Runge-Kutta 4 (RK4) Industry-standard numerical ODE solver.
RK4 takes four slope estimates per step and combines them with weighted averages. It achieves fourth-order accuracy with only four function evaluations per step.
Key formulas & rules
- •k₁ = f(x, y)
- •k₂ = f(x + h/2, y + h·k₁/2)
- •k₃ = f(x + h/2, y + h·k₂/2)
- •k₄ = f(x + h, y + h·k₃)
- •y_{n+1} = y_n + (h/6)(k₁ + 2k₂ + 2k₃ + k₄)
- •Fourth-order accuracy: error ∝ h⁴
Examples
| Input | Output | Note |
|---|---|---|
| dy/dx = y, y(0)=1, h=0.1 | y(1) ≈ 2.718 | Matches e |
| dy/dx = y², y(0)=1, h=0.1 | Blow-up near x=1 | Finite-time blow-up |
| RK4 vs Euler at h=0.1 | RK4 much closer | Superior accuracy |
| dy/dx = -y, y(0)=10 | Decay curve | Exponential decay |
Real-world uses
Applications of ODEs ODEs model change in almost every science.
Anything that changes over time can be modeled by an ODE. From bacteria growth to planetary orbits to electrical circuits, ODEs are the workhorse of applied mathematics.
Key formulas & rules
- •Physics: F = ma → m·x″ = F(x)
- •Biology: dP/dt = rP(1 − P/K)
- •Chemistry: rate laws d[A]/dt = −k[A]
- •Economics: Solow growth model
- •Epidemiology: SIR model
- •Circuits: L·I″ + R·I′ + I/C = V(t)
Examples
| Input | Output | Note |
|---|---|---|
| Bacteria growth | dP/dt = rP | Exponential |
| Cooling (Newton) | dT/dt = −k(T − Tₐ) | Approaches ambient |
| SIR epidemic | 3 coupled ODEs | S, I, R compartments |
| Radioactive decay | dN/dt = −λN | Half-life |
Real-world uses
Modes & formulas
RK4 Numerical Solver
RK4 takes four slope estimates per step and combines them with weights (1, 2, 2, 1). The local error is O(h⁵) and the global error is O(h⁴) — fourth-order accuracy.
Backward Integration
Backward integration is useful for finding past states of a system given a current state. The RK4 weights stay the same; only the sign of the step changes.