Lab · Engineering Mathematics
ODE Solver Lab
Solve one scalar initial-value problem with two explicit fixed-step methods at once, compare them against an optional supplied reference, and refine the step to see the order each method actually achieves on this problem.
Initial-value problem
Variables t and y. Operators + − * / ^, parentheses, pi and e, and sin, cos, tan, asin, acos, atan, exp, sqrt, abs, ln, log, log10. Write 2*y, not 2y.
Negative h integrates backward in time.
1 to 10,000 per solve.
1 to 6. Level k halves h and doubles N.
A function of t only, e.g. exp(-t). Leave empty for no reference: nothing is then called an error.
End time t_end = t₀ + N·h = 2. Every refinement level ends at exactly this time, so the levels answer the same question.
The supplied reference agrees with the initial condition at t₀, so the differences below are reported as error relative to that reference.
Presets
y(0) = 1 with the closed form e^(−t). Smooth, bounded and well scaled: the benchmark on which Euler's first-order and RK4's fourth-order refinement behaviour are easiest to observe.
Trajectories
Endpoint comparison
| Method | y(t_end) | Derivative evaluations | |error| vs reference |
|---|---|---|---|
| Explicit Euler | 0.1215766546 | 20 | 1.376e-2 |
| Classical RK4 | 0.1353355284 | 80 | 2.452e-7 |
Step-size refinement
Explicit Euler
| level | h | N | evaluations | y(t_end) | |error| | observed order |
|---|---|---|---|---|---|---|
| 0 | 0.1 | 20 | 20 | 0.1215766546 | 1.376e-2 | – |
| 1 | 0.05 | 40 | 40 | 0.1285121566 | 6.823e-3 | 1.01 |
| 2 | 0.025 | 80 | 80 | 0.1319378054 | 3.397e-3 | 1.01 |
| 3 | 0.0125 | 160 | 160 | 0.1336400679 | 1.695e-3 | 1.00 |
Classical RK4
| level | h | N | evaluations | y(t_end) | |error| | observed order |
|---|---|---|---|---|---|---|
| 0 | 0.1 | 20 | 80 | 0.1353355284 | 2.452e-7 | – |
| 1 | 0.05 | 40 | 160 | 0.1353352979 | 1.470e-8 | 4.06 |
| 2 | 0.025 | 80 | 320 | 0.1353352841 | 8.996e-10 | 4.03 |
| 3 | 0.0125 | 160 | 640 | 0.1353352833 | 5.564e-11 | 4.02 |
The whole study is priced before it runs: at most 200,000 derivative evaluations and at most 10,000 steps in any single level. An unaffordable study is refused outright rather than run in part.
Nodes
Explicit Euler
| n | tₙ | yₙ | y_ref(tₙ) | |yₙ − y_ref| | relative |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0.000e+0 | 0.000e+0 |
| 1 | 0.1 | 0.9 | 0.904837418 | 4.837e-3 | 5.346e-3 |
| 2 | 0.2 | 0.81 | 0.8187307531 | 8.731e-3 | 1.066e-2 |
| 3 | 0.3 | 0.729 | 0.7408182207 | 1.182e-2 | 1.595e-2 |
| 4 | 0.4 | 0.6561 | 0.670320046 | 1.422e-2 | 2.121e-2 |
| 5 | 0.5 | 0.59049 | 0.6065306597 | 1.604e-2 | 2.645e-2 |
| 6 | 0.6 | 0.531441 | 0.5488116361 | 1.737e-2 | 3.165e-2 |
| 7 | 0.7 | 0.4782969 | 0.4965853038 | 1.829e-2 | 3.683e-2 |
| 8 | 0.8 | 0.43046721 | 0.4493289641 | 1.886e-2 | 4.198e-2 |
| 9 | 0.9 | 0.387420489 | 0.4065696597 | 1.915e-2 | 4.710e-2 |
| 10 | 1 | 0.3486784401 | 0.3678794412 | 1.920e-2 | 5.219e-2 |
| 11 | 1.1 | 0.3138105961 | 0.3328710837 | 1.906e-2 | 5.726e-2 |
| 12 | 1.2 | 0.2824295365 | 0.3011942119 | 1.876e-2 | 6.230e-2 |
| 13 | 1.3 | 0.2541865828 | 0.272531793 | 1.835e-2 | 6.731e-2 |
| 14 | 1.4 | 0.2287679245 | 0.2465969639 | 1.783e-2 | 7.230e-2 |
| 15 | 1.5 | 0.2058911321 | 0.2231301601 | 1.724e-2 | 7.726e-2 |
| 16 | 1.6 | 0.1853020189 | 0.201896518 | 1.659e-2 | 8.219e-2 |
| 17 | 1.7 | 0.166771817 | 0.1826835241 | 1.591e-2 | 8.710e-2 |
| 18 | 1.8 | 0.1500946353 | 0.1652988882 | 1.520e-2 | 9.198e-2 |
| 19 | 1.9 | 0.1350851718 | 0.1495686192 | 1.448e-2 | 9.683e-2 |
| 20 | 2 | 0.1215766546 | 0.1353352832 | 1.376e-2 | 1.017e-1 |
Classical RK4
| n | tₙ | yₙ | y_ref(tₙ) | |yₙ − y_ref| | relative |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0.000e+0 | 0.000e+0 |
| 1 | 0.1 | 0.9048375 | 0.904837418 | 8.196e-8 | 9.058e-8 |
| 2 | 0.2 | 0.8187309014 | 0.8187307531 | 1.483e-7 | 1.812e-7 |
| 3 | 0.3 | 0.740818422 | 0.7408182207 | 2.013e-7 | 2.718e-7 |
| 4 | 0.4 | 0.6703202889 | 0.670320046 | 2.429e-7 | 3.623e-7 |
| 5 | 0.5 | 0.6065309344 | 0.6065306597 | 2.747e-7 | 4.529e-7 |
| 6 | 0.6 | 0.5488119344 | 0.5488116361 | 2.983e-7 | 5.435e-7 |
| 7 | 0.7 | 0.4965856187 | 0.4965853038 | 3.149e-7 | 6.341e-7 |
| 8 | 0.8 | 0.4493292897 | 0.4493289641 | 3.256e-7 | 7.247e-7 |
| 9 | 0.9 | 0.4065699912 | 0.4065696597 | 3.315e-7 | 8.153e-7 |
| 10 | 1 | 0.3678797744 | 0.3678794412 | 3.332e-7 | 9.058e-7 |
| 11 | 1.1 | 0.3328714154 | 0.3328710837 | 3.317e-7 | 9.964e-7 |
| 12 | 1.2 | 0.3011945393 | 0.3011942119 | 3.274e-7 | 1.087e-6 |
| 13 | 1.3 | 0.272532114 | 0.272531793 | 3.209e-7 | 1.178e-6 |
| 14 | 1.4 | 0.2465972767 | 0.2465969639 | 3.127e-7 | 1.268e-6 |
| 15 | 1.5 | 0.2231304633 | 0.2231301601 | 3.032e-7 | 1.359e-6 |
| 16 | 1.6 | 0.2018968106 | 0.201896518 | 2.926e-7 | 1.449e-6 |
| 17 | 1.7 | 0.1826838054 | 0.1826835241 | 2.813e-7 | 1.540e-6 |
| 18 | 1.8 | 0.1652991577 | 0.1652988882 | 2.695e-7 | 1.631e-6 |
| 19 | 1.9 | 0.1495688766 | 0.1495686192 | 2.574e-7 | 1.721e-6 |
| 20 | 2 | 0.1353355284 | 0.1353352832 | 2.452e-7 | 1.812e-6 |
What this Lab models
One scalar first-order initial-value problem y′ = f(t, y) with y(t₀) = y₀, marched with explicit FIXED-step methods. The step never adapts, no error estimate is produced by the methods themselves, and the end time is always the derived t₀ + N·h. Systems of equations, adaptive RK45, event detection and implicit or stiff solvers are outside this Lab.
Model scope
- · Explicit Euler costs one derivative evaluation per step; classical RK4 costs four. Compare methods at equal COST, not at equal step count.
- · A supplied reference is used for error only when it agrees with the initial condition at t₀. Otherwise it describes a different problem.
- · Without a usable reference, only self-convergence is reported: successive answers settling is not the same as being correct.
- · An observed order close to 1 for Euler or 4 for RK4 is evidence consistent with the theory on THIS problem; it is never a proof of accuracy.