
How to Use the Differential Equation Calculator

- Choose a first-order initial value problem or a second-order linear equation.
- Type f(x, y) for y′ = f(x, y), such as x + y.
- Set the step size and how far in x to solve.
- Pick Runge-Kutta 4, Heun, midpoint or Euler to compare methods.
- Read y at the end, the error estimate and the slope field, then the full table.
For a first-order initial value problem, type the right-hand side f(x, y) of y′ = f(x, y), the starting point x₀ and y(x₀), the step size h and the x value to solve up to. Choose Runge-Kutta 4 for accuracy, or Heun, midpoint or Euler to compare methods. If you know the exact solution, enter it to see the true error at every step.
The result panel gives the approximate value at the end, an error estimate from repeating the calculation with half the step size, and a graph of the slope field with the solution curve. The table below lists every step and can be downloaded as a CSV file. For a second-order equation ay″ + by′ + cy = 0, enter a, b and c, and optionally y(0) and y′(0), to get the exact general and particular solutions.
The Runge-Kutta 4 Method
k₃ = f(xn + h/2, yn + h·k₂/2) k₄ = f(xn + h, yn + h·k₃)
yn+1 = yn + h(k₁ + 2k₂ + 2k₃ + k₄) ÷ 6
RK4 samples the slope four times per step and takes a weighted average. Its error shrinks like h4, so halving the step size cuts the error by about 16. Euler's method, yn+1 = yn + h·f(xn, yn), uses one slope and has error proportional to h. Heun and midpoint are second-order methods in between.
Worked Example
Solve y′ = x + y with y(0) = 1 up to x = 1 with h = 0.1. For the first step, k₁ = 1, k₂ = f(0.05, 1.05) = 1.1, k₃ = f(0.05, 1.055) = 1.105 and k₄ = f(0.1, 1.1105) = 1.2105, so y₁ = 1 + 0.1 × (1 + 2.2 + 2.21 + 1.2105) ÷ 6 = 1.11034167. After ten steps, RK4 gives y(1) ≈ 3.436559488. The exact solution is y = 2ex − x − 1, so y(1) = 2e − 2 ≈ 3.436563657, an error of about 4.2 × 10−6.
| Method, h = 0.1 | y(1) | Error |
|---|---|---|
| Euler | 3.187485 | 0.249 |
| Heun | 3.428162 | 0.0084 |
| Runge-Kutta 4 | 3.436559 | 0.0000042 |
Second-Order Equations With Constant Coefficients
For ay″ + by′ + cy = 0, substituting y = erx gives the characteristic equation ar² + br + c = 0. Its roots decide the form of the solution:
Repeated root r: y = (C₁ + C₂x)erx
Complex roots α ± βi: y = eαx(C₁cos βx + C₂sin βx)
For example, y″ + y′ − 6y = 0 has r² + r − 6 = (r + 3)(r − 2) = 0, so r = 2 and r = −3. With y(0) = 1 and y′(0) = 0, the equations C₁ + C₂ = 1 and 2C₁ − 3C₂ = 0 give C₁ = 3/5 and C₂ = 2/5, so y = (3/5)e2x + (2/5)e−3x.
Choosing a Step Size
A smaller step size gives a more accurate answer but needs more calculation. For the worked example, RK4 with h = 0.05 gives y(1) ≈ 3.436563385, an error of about 2.7 × 10−7, which is roughly 15 times smaller than with h = 0.1, close to the factor of 16 that fourth-order accuracy predicts. If halving h changes the answer only in digits you do not need, the step is small enough.
Tips and Limits
- The distance from x₀ to the end must be a whole number of steps. Solving backwards, with an end value below x₀, is allowed.
- The error estimate compares the result with a run at h/2. It is reliable for smooth problems but cannot detect every difficulty, such as stiff equations or solutions that blow up.
- Second-order mode covers homogeneous equations with constant coefficients. Forcing terms and variable coefficients are not included.
- Up to 20,000 steps are computed in your browser.
Frequently asked questions
What is the Runge-Kutta method?
A numerical method for initial value problems. RK4 evaluates the slope four times per step, at the start, twice at the midpoint and at the end, and combines them with weights 1, 2, 2, 1. It is accurate to fourth order.
How accurate is Euler's method compared with RK4?
Euler's error is proportional to the step size h, while RK4's is proportional to h⁴. For y′ = x + y from 0 to 1 with h = 0.1, Euler is off by about 0.25 and RK4 by about 0.000004.
What is a slope field?
A grid of short line segments whose slopes equal f(x, y) at each point. Solution curves of y′ = f(x, y) follow the direction of the segments, so the field shows how all solutions behave.
How do you solve ay″ + by′ + cy = 0?
Solve the characteristic equation ar² + br + c = 0. Two real roots give exponentials, a repeated root adds a factor of x, and complex roots α ± βi give e^(αx) times cosine and sine of βx.
What are initial conditions?
Values such as y(0) and y′(0) that pick one solution out of the general family. A second-order equation needs two conditions to fix the two constants C₁ and C₂.
How do I choose a step size?
Start with a moderate h, then halve it and compare. If the answer barely changes, the step is small enough. The calculator does this comparison automatically and reports it as the error estimate.