Heun Method Calculator
Enter the differential equation with x and y. Supported functions include sin, cos, tan, exp, log, ln, sqrt, abs, pow, floor, ceil, and round.
Formula Used
Heun method is a second order predictor corrector scheme for first order ordinary differential equations.
Step 1: k1 = f(xn, yn)
Step 2: Predictor = yn + h × k1
Step 3: k2 = f(xn + h, Predictor)
Step 4: yn+1 = yn + (h / 2) × (k1 + k2)
Correction term: yn+1 − Predictor
Heun method has local truncation error O(h3) and global error O(h2), so smaller steps usually improve accuracy.
How to Use This Calculator
- Enter the derivative function in terms of x and y.
- Provide the initial point x0 and y0.
- Set the step size and target x value.
- Optionally enter the exact solution for error analysis.
- Select the number of displayed decimals.
- Press Calculate to generate the table, graph, and summary metrics.
- Use the CSV and PDF buttons to save the computed report.
Example Data Table
Example problem: y' = x + y, y(0) = 1, h = 0.2, target x = 1, exact solution = 2ex - x - 1.
| Step | x | Heun Approximation | Exact Value | Absolute Error |
|---|---|---|---|---|
| 1 | 0.200000 | 1.240000 | 1.242806 | 0.002806 |
| 2 | 0.400000 | 1.576800 | 1.583649 | 0.006849 |
| 3 | 0.600000 | 2.031696 | 2.044238 | 0.012542 |
| 4 | 0.800000 | 2.630669 | 2.651082 | 0.020413 |
| 5 | 1.000000 | 3.405416 | 3.436564 | 0.031147 |
FAQs
1. What does Heun method compute?
It approximates solutions of first order initial value problems by averaging the slope at the current point with the slope at a predicted next point.
2. Why is an exact solution field included?
The optional exact solution lets you compare the numerical approximation against a known analytical answer, so the calculator can display absolute errors and accuracy trends.
3. Which functions can I use inside the equation?
You can use x, y, parentheses, powers, and common functions such as sin, cos, tan, exp, log, ln, sqrt, abs, pow, floor, ceil, and round.
4. Is Heun method more accurate than Euler method?
Yes. Heun method usually improves accuracy because it uses a predictor and a corrected average slope, while standard Euler relies on only one slope estimate.
5. Why does the last step sometimes differ slightly?
If the interval length is not an exact multiple of the step size, the final step is automatically shortened so the computation lands exactly on the target x.
6. What does the correction column show?
It shows the difference between the corrected value and the simple predictor. Larger corrections suggest stronger local curvature or a step size that may be too large.
7. How should I choose the step size?
Start with a moderate step, then reduce it and compare results. When the solution stabilizes and errors shrink, the chosen step is usually reasonable.
8. Can this handle backward integration?
Yes. If the target x is smaller than the initial x, the calculator automatically integrates backward while keeping the Heun correction process consistent.