Define f(x,y), initial condition, and step settings. After Submit, the results show above this form.
Example with f(x,y)=x+y, x₀=0, y₀=1, h=0.1, n=3 using Heun.
| Step | xᵢ | yᵢ | k₁ | ŷ | k₂ | xᵢ₊₁ | yᵢ₊₁ |
|---|---|---|---|---|---|---|---|
| 1 | 0.0 | 1.0 | 1.0 | 1.1 | 1.2 | 0.1 | 1.11 |
| 2 | 0.1 | 1.11 | 1.21 | 1.231 | 1.331 | 0.2 | 1.23705 |
| 3 | 0.2 | 1.23705 | 1.43705 | 1.380755 | 1.580755 | 0.3 | 1.38844025 |
For y' = f(x,y) with step h, the method estimates the next value by correcting a predicted slope.
ŷ = yᵢ + h·k₁
k₂ = f(xᵢ + h, ŷ)
yᵢ₊₁ = yᵢ + (h/2)·(k₁ + k₂)
xₘ = xᵢ + h/2
yₘ = yᵢ + (h/2)·k₁
k₂ = f(xₘ, yₘ)
yᵢ₊₁ = yᵢ + h·k₂
These variants typically reduce error compared to basic Euler at the same step size.
- Type the derivative in the Derivative field using x and y.
- Enter x₀ and y₀ from your initial condition.
- Pick h and n to control the interval length.
- Select the variant required by your class notes.
- Optional: add exact y(x) to compute absolute error.
- Click Submit. The table appears above the form.
Why improved Euler improves accuracy
Basic Euler uses one slope at xᵢ, so the local truncation error is O(h²). Improved Euler evaluates a second slope and averages them, giving O(h³) local error and usually O(h²) global error. In practice, halving h often reduces the total error by about four times for smooth problems.
Heun variant step statistics
Heun uses a predictor ŷ = yᵢ + h·k₁ and a corrector yᵢ₊₁ = yᵢ + (h/2)(k₁+k₂). This calculator reports k₁, ŷ, k₂, and yᵢ₊₁ per step. For monotone f, the corrected value typically lies between the predictor and the forward Euler value.
Midpoint variant stability notes
The midpoint form evaluates the derivative at (xᵢ+h/2, yᵢ+(h/2)k₁). For many nonstiff models, midpoint produces slightly smaller phase error than Heun. On test problems like y' = -10y, both methods behave better than Euler, yet still require small h to avoid oscillations.
Choosing h and n with targets
If your target is x_end, pick n = (x_end − x₀)/h as an integer so the grid lands exactly. When exact y(x) is available, compare |error| across steps and reduce h until the maximum error meets your tolerance. A common classroom target is 10⁻³ to 10⁻⁵ depending on units. For example, with h=0.1 and n=10 you advance one unit in x. If the curve is steep, reduce h and rerun until k₁ and k₂ stay comparable.
Exported tables for reporting
The CSV export preserves every computed column for spreadsheets and lab notes. The PDF export captures the same table for quick submission. Rounding is controlled by “Display digits” so the table matches required precision, while internal computations remain in full floating-point. Many instructors require intermediate slopes; the k₁ and k₂ columns justify each correction and support quick checking in a spreadsheet. PDF output is useful when submission formats are strict.
Interpreting the interactive curve
The Plotly graph plots (xᵢ, yᵢ) points joined by lines, making step-to-step behavior visible. With an exact function entered, both curves overlay to show deviation. Use zoom to inspect early transient regions and hover tooltips to read values precisely at each step. If the plotted gap widens, error is accumulating; decrease h, increase digits for review, or shorten the interval to keep updates stable.
1) What problems does this calculator solve?
It approximates solutions to first‑order initial value problems y' = f(x,y) with y(x₀)=y₀, advancing a fixed step size for n steps.
2) When should I choose Heun instead of midpoint?
Choose Heun when you want the average of start and end slopes. Choose midpoint when your notes emphasize midpoint sampling and you want strong behavior on smooth curves.
3) How do I enter powers and functions?
Use ^ for powers, like x^2. Supported functions include sin, cos, exp, log, sqrt, and abs.
4) Why does my result change when I reduce h?
Numerical updates approximate the true curve on a grid. Smaller h reduces truncation error, so corrected steps track the exact solution more closely when f changes rapidly.
5) What does the optional exact y(x) do?
If you provide an exact solution, it is evaluated at each xᵢ₊₁ and absolute error |y_exact − y_approx| is shown. This helps validate h and compare variants.
6) Are there limits on n?
Yes. For performance and responsiveness, n is limited to 2000 steps. If you need a longer interval, increase h carefully or split the run into segments.