ODE Solver (Euler & RK4)
Numerically integrate first-order differential equations from initial conditions
Parameters
Controls
Calculated Values
Examples
Decay N₀=100, λ=0.3, t=5 s
Compare Euler and RK4 to N₀e^(−λt).
- Exact:
- RK4:
Velocity v₀=0, a=2 m/s², t=3 s
Analytic v = at.
- v:
Visualization
Solving Physics ODEs Numerically
Differential equations describe how quantities change: radioactive decay dN/dt = −λN, cooling dT/dt = −k(T−T₀), and velocity dv/dt = a under constant acceleration. When analytic solutions are inconvenient, numerical methods step forward in small time increments Δt.
Euler’s method is the simplest: yₙ₊₁ = yₙ + h·f(tₙ, yₙ), where h is the step size and f is the right-hand side of dy/dt = f. Local truncation error is O(h²); global error is O(h) — accuracy improves by shrinking h.
The fourth-order Runge–Kutta (RK4) method evaluates the slope at four points per step and combines them: yₙ₊₁ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄). It is the workhorse of computational physics for smooth ODEs.
Second-order equations (e.g. SHM d²x/dt² = −ω²x) are written as two first-order equations: v = dx/dt and dv/dt = −ω²x. Compare numerical output to Simple Harmonic Motion or Radioactive Decay analytic formulas.
Stability matters: Euler can diverge if h is too large for oscillatory systems. RK4 allows larger steps but is not a substitute for understanding the physics.
Key Concepts
- Initial value problem: y(t₀) = y₀ given
- Euler: first-order accurate globally
- RK4: fourth-order accurate, much smaller error for same h
- Step size h trades accuracy vs speed
- Second-order ODE → system of two first-order ODEs
Real-World Applications
- Exponential decay and radioactivity
- Constant-acceleration kinematics
- RC circuit charging curves
- Population and cooling models
Explore Further
- All Computational Physics Calculators
Browse every computational physics solver in this category.
- Statistical & Numerical Methods
Probability and ensemble ideas behind stochastic simulation.
- Statistics in Physics
Why averaging random samples recovers physical expectations.
- Bisection Method
Step in Numerical Methods.
- Newton-Raphson
Step in Numerical Methods.
- Monte Carlo Intro
Step in Numerical Methods.
- Physics Constants Reference
SI values for c, G, k_B, ε₀, and more used across solvers.
More computational physics tools
- Gradient Descent
Iteratively minimize f(x) by following the negative gradient with animated path visualization.
- 1D Heat Equation
Finite-difference FTCS solution to the diffusion equation with animated temperature profiles.
- 1D Wave Equation
Leapfrog finite-difference solution to the wave equation with animated wave propagation.
- Numerical Integration
Trapezoidal and Simpson rules to approximate definite integrals with error vs exact solutions.
- Monte Carlo Intro
Estimate π and integrals by random sampling — introduction to stochastic computational physics.
- Newton-Raphson
Solve nonlinear equations f(x) = 0 with tangent-line iterations — fast when the guess is good.
Physics Equations
Step-by-Step Solution
See how the main results are calculated.
Step 1: Write the ODE and initial condition
Exponential decay: rate proportional to current amount.
Equation:
Result:
Step 2: Analytic solution
Separate variables and integrate.
Equation:
Calculation:
Result:
Step 3: Choose numerical step size
Divide interval into N equal steps of size h.
Equation:
Calculation:
Result:
Step 4: Euler iteration
Update: y_{n+1} = y_n + h(−k y_n).
Equation:
Calculation:
Result:
Explanation:
First-order method; error decreases when h is reduced.
Step 5: RK4 iteration
Weighted average of four slope estimates per step.
Equation:
Calculation:
Result:
Explanation:
RK4 is usually much closer to exact for the same h.
Step 6: Compare methods
Result:
Explanation:
Halve h and repeat until Euler and RK4 agree with each other and with exact.
Frequently Asked Questions (FAQ)
When should I use RK4 over Euler?
RK4 is preferred for smooth ODEs when accuracy matters; Euler is simpler but needs smaller h.
What step size h should I choose?
Start with h = (tf−t0)/100, halve h until Euler and RK4 agree with each other and the analytic solution.
Practice MCQs
- Smaller step size h generally:
- For dN/dt = −λN, the exact solution is:
- RK4 is preferred over Euler because:
- Euler’s method is equivalent to:
- Constant acceleration dv/dt = a gives:
Related Calculators
These tools connect to the same physics concepts used in this calculator.