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.

MethodsA method that is switched off is never executed and never appears in any comparison.

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

Explicit EulerClassical RK4y_ref(t) = exp(-t) (supplied reference)
y′ = -y from t₀ = 0 with h = 0.1 and N = 20. Markers are computed nodes; the segments between them are a reading aid only.

Endpoint comparison

Methody(t_end)Derivative evaluations|error| vs reference
Explicit Euler0.1215766546201.376e-2
Classical RK40.1353355284802.452e-7

Step-size refinement

Explicit Euler

levelhNevaluationsy(t_end)|error|observed order
00.120200.12157665461.376e-2–
10.0540400.12851215666.823e-31.01
20.02580800.13193780543.397e-31.01
30.01251601600.13364006791.695e-31.00

Classical RK4

levelhNevaluationsy(t_end)|error|observed order
00.120800.13533552842.452e-7–
10.05401600.13533529791.470e-84.06
20.025803200.13533528418.996e-104.03
30.01251606400.13533528335.564e-114.02
Explicit EulerClassical RK4
Endpoint error against the supplied reference as the step is halved. On logarithmic axes a straight line of slope p indicates observed order p; it is evidence about this problem, not a guarantee.

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

Explicit Euler: every computed node of the fixed-step march.
ntₙyₙy_ref(tₙ)|yₙ − y_ref|relative
00110.000e+00.000e+0
10.10.90.9048374184.837e-35.346e-3
20.20.810.81873075318.731e-31.066e-2
30.30.7290.74081822071.182e-21.595e-2
40.40.65610.6703200461.422e-22.121e-2
50.50.590490.60653065971.604e-22.645e-2
60.60.5314410.54881163611.737e-23.165e-2
70.70.47829690.49658530381.829e-23.683e-2
80.80.430467210.44932896411.886e-24.198e-2
90.90.3874204890.40656965971.915e-24.710e-2
1010.34867844010.36787944121.920e-25.219e-2
111.10.31381059610.33287108371.906e-25.726e-2
121.20.28242953650.30119421191.876e-26.230e-2
131.30.25418658280.2725317931.835e-26.731e-2
141.40.22876792450.24659696391.783e-27.230e-2
151.50.20589113210.22313016011.724e-27.726e-2
161.60.18530201890.2018965181.659e-28.219e-2
171.70.1667718170.18268352411.591e-28.710e-2
181.80.15009463530.16529888821.520e-29.198e-2
191.90.13508517180.14956861921.448e-29.683e-2
2020.12157665460.13533528321.376e-21.017e-1

Classical RK4

Classical RK4: every computed node of the fixed-step march.
ntₙyₙy_ref(tₙ)|yₙ − y_ref|relative
00110.000e+00.000e+0
10.10.90483750.9048374188.196e-89.058e-8
20.20.81873090140.81873075311.483e-71.812e-7
30.30.7408184220.74081822072.013e-72.718e-7
40.40.67032028890.6703200462.429e-73.623e-7
50.50.60653093440.60653065972.747e-74.529e-7
60.60.54881193440.54881163612.983e-75.435e-7
70.70.49658561870.49658530383.149e-76.341e-7
80.80.44932928970.44932896413.256e-77.247e-7
90.90.40656999120.40656965973.315e-78.153e-7
1010.36787977440.36787944123.332e-79.058e-7
111.10.33287141540.33287108373.317e-79.964e-7
121.20.30119453930.30119421193.274e-71.087e-6
131.30.2725321140.2725317933.209e-71.178e-6
141.40.24659727670.24659696393.127e-71.268e-6
151.50.22313046330.22313016013.032e-71.359e-6
161.60.20189681060.2018965182.926e-71.449e-6
171.70.18268380540.18268352412.813e-71.540e-6
181.80.16529915770.16529888822.695e-71.631e-6
191.90.14956887660.14956861922.574e-71.721e-6
2020.13533552840.13533528322.452e-71.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.

Related calculations