Solve an initial value problem
Enter an equation, choose a method, and set an interval and step. This tool computes a numerical approximation step by step.
Example data table
Example for first-order y' = x - y, with x₀=0, y₀=1, h=0.5.
| Step | x | y | f(x,y) | h | y(next) |
|---|---|---|---|---|---|
| 0 | 0.000000 | 1.000000 | -1.000000 | 0.500000 | 0.500000 |
| 1 | 0.500000 | 0.500000 | 0.000000 | 0.500000 | 0.500000 |
| 2 | 1.000000 | 0.500000 | 0.500000 | 0.500000 | 0.750000 |
Formula used
The solver advances from (x_n, y_n) to (x_{n+1}, y_{n+1}) using step h.
Euler
y_{n+1} = y_n + h f(x_n, y_n)
Heun (Improved Euler)
y* = y_n + h f(x_n, y_n)
y_{n+1} = y_n + (h/2)[f(x_n,y_n) + f(x_{n+1}, y*)]
y_{n+1} = y_n + (h/2)[f(x_n,y_n) + f(x_{n+1}, y*)]
Midpoint
y_{n+1} = y_n + h f(x_n + h/2, y_n + (h/2) f(x_n,y_n))
RK4
k1 = f(x_n, y_n)
k2 = f(x_n + h/2, y_n + (h/2)k1)
k3 = f(x_n + h/2, y_n + (h/2)k2)
k4 = f(x_n + h, y_n + hk3)
y_{n+1} = y_n + (h/6)(k1 + 2k2 + 2k3 + k4)
k2 = f(x_n + h/2, y_n + (h/2)k1)
k3 = f(x_n + h/2, y_n + (h/2)k2)
k4 = f(x_n + h, y_n + hk3)
y_{n+1} = y_n + (h/6)(k1 + 2k2 + 2k3 + k4)
Second-order conversion
y'' = g(x,y,y') with v = y' becomes: y' = v, v' = g(x,y,v)
How to use this calculator
- Choose Problem type: first-order or second-order.
- Enter the expression: f(x,y) or g(x,y,v).
- Set x₀, x₁, and step size h.
- Provide y₀, and for second-order also y'₀.
- Pick a method (RK4 is a strong default).
- Click Solve ODE to display the table and endpoint values.
- Use downloads to export the full table when needed.
Notes: Smaller h improves accuracy but increases steps. If results blow up, reduce h or change the method.
FAQs
1) What problems does this solver handle?
It solves initial value problems for first-order equations y'=f(x,y) and second-order equations y''=g(x,y,y'). Boundary value problems need different methods.
2) Which method should I choose for accuracy?
RK4 is typically accurate for smooth functions with moderate steps. Heun and Midpoint often improve over Euler at similar cost, but may still need smaller steps.
3) What does the Heun error estimate mean?
Heun computes a predictor and a corrected value. The difference between them is a simple local indicator. It is not a guaranteed global error bound.
4) Why do my results explode or become NaN?
The step may be too large for a stiff or unstable problem, or the expression may create huge values. Reduce h, shorten the interval, or try RK4.
5) What functions and variables can I use in expressions?
Use x, y, and v (for second-order). Common functions include sin, cos, tan, exp, log, sqrt, abs, and pow. Use ^ for powers.
6) Can it solve systems of many equations?
This version supports a scalar first-order equation or a converted two-state second-order form. For larger systems, extend the vector operations similarly.
7) How do I pick a good step size?
Start with a moderate h, then halve it and compare endpoints. If values change noticeably, continue reducing h until results stabilize for your tolerance.
8) What do CSV and PDF exports include?
Exports include your settings and the full step table. The PDF is a compact preview of the first rows, while CSV preserves all rows for analysis.