Differential Equation Solver
Solve first-order ODEs numerically using RK4 given dy/dx = f(x,y) and an initial condition.
About Differential Equation Solver
Solves the initial value problem dy/dx = f(x,y), y(x₀) = y₀ using the classical 4th-order Runge-Kutta method (RK4). This method has local error O(h⁵) and global error O(h⁴), making it highly accurate for smooth ODEs. Enter f(x,y) using x and y as variables.
Formula
RK4 method
y(n+1) = y(n) + (h/6)(k1 + 2k2 + 2k3 + k4)
- k1
- h·f(xn, yn)
- k2
- h·f(xn+h/2, yn+k1/2)
- k3
- h·f(xn+h/2, yn+k2/2)
- k4
- h·f(xn+h, yn+k3)
Worked example
With the default values below, Differential Equation Solver returns y(target x) of 3.43656366. Change any input above and every figure here is recalculated in your browser.
Inputs used
- dy/dx = f(x, y)
- x + y
- Initial x₀
- 0
- Initial y₀ = y(x₀)
- 1
- Target x
- 1
- Number of stepsaccepts 10–10,000
- 100
Results
- y(target x)
- 3.43656366
- Steps used
- 100
- Step size h
- 0.01000000
Step by step
- 1Values used
- 2RK4 method
- 3y(target x)= 3.43656366
- 4Steps used= 100
- 5Step size h= 0.01000000
Assumptions and limits
- The result is derived only from the 5 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 8 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
How many steps should I use?
More steps give higher accuracy but take longer. For most problems, 100-1000 steps suffice. If the solution diverges, try more steps (smaller h).
Can this solve higher-order ODEs?
Convert a second-order ODE y'' = g(x,y,y') into a system of first-order ODEs by substituting v = y', then solve iteratively.
