SME
Numerical Methods for Engineers
Numerical ODE solvers (Euler, Runge–Kutta)
Use this for “Solve dy/dt = −0.5y with y(0) = 10 by Euler’s method with h = 0.5 up to t = 2, and compare with the exact answer.”
Chart
Euler, 4 steps of h = 0.5: y = 3.164 at t = 2; solid, the exact y = 3.679, off by 13.99%
This is an example. Type your own values to start a new problem.
y′
=
k
y,
y(0)
=
y₀
yEuler
=
y₀
×
(1
+
(
)
×
)
t
End time
worked out (not typed)
yexact
Exact value
worked out (not typed)
ε
Error
worked out (not typed) · %
Formulas
t
=
n
×
h
2 = 4 × 0.5
yEuler
=
y₀
×
(1 +
k
×
h
)
n
3.1641 = 10 × (1 + (−0.5) × 0.5)⁴
yexact
=
y₀
×
e
k
×
t
3.6788
=
10
×
e
−0.5 × 2
ε
=
|yEuler
−
yexact|
÷
|yexact|
×
100
13.9919 = |3.1641 − 3.6788| ÷ |3.6788| × 100
Assumptions
•
dy/dt = ky with y(0) = y₀, so the exact answer is y₀ekt.
•
Each Euler step multiplies y by (1 + kh), so after n steps y = y₀(1 + kh)ⁿ.
•
Halving h roughly halves the error: Euler’s method is first order.
Step-by-step
WE KNOW
y₀ = 10, k = −0.5, h = 0.5, n = 4
FIND
end time (t), Euler’s value (yEuler), exact value (yexact), error (ε)
Step 1 · Find end time (t)
Use t = n × h
n
steps
of
size
h
.
t
=
4
×
0.5
t
=
2
Step 2 · Find Euler’s value (yEuler)
Use yEuler = y₀ × (1 + k × h)ⁿ
Each
step
adds
h
times
the
slope
ky,
which
multiplies
y
by
1
+
kh.
yEuler = 10 × (1 + (−0.5) × 0.5)⁴
yEuler = 10 × (1 + (−0.25))⁴
yEuler
=
10
×
0.75
4
yEuler = 10 × 0.3164
yEuler = 3.16406
Step 3 · Find exact value (yexact)
Use yexact = y₀ × ek × t
The exact solution of dy/dt = ky at the end time.
yexact
=
10
×
e
−0.5 × 2
yexact
=
10
×
e
-1
yexact = 10 × 0.3679
yexact = 3.67879
Step 4 · Find error (ε)
Use ε = |yEuler − yexact| ÷ |yexact| × 100
The gap between the two answers, as a percent of the exact one.
ε
=
|3.16406
−
3.67879|
÷
|3.67879|
×
100
ε
=
|−0.5147|
÷
|3.6788|
×
100
ε
=
0.5147
3.679
×
100
ε
=
0.1399
×
100
ε
=
13.9919%
Check
Put the numbers back in. Both sides should match.
2 = 4 × 0.5 ✓
3.16406 = 10 × (1 + (−0.5) × 0.5)⁴ ✓
3.67879
=
10
×
e
−0.5 × 2
✓
13.9919 = |3.16406 − 3.67879| ÷ |3.67879| × 100 ✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.
More problem types
One Runge–Kutta (RK4) step
Use this for “Take one RK4 step of h = 0.5 on dy/dt = −0.5y from y = 10, and compare with the exact answer.”
One Heun step (improved Euler)
Use this for “Take one Heun step of h = 0.5 on dy/dt = −0.5y from y = 10, and compare with the exact answer.”
Step size for a stable Euler method
Use this for “For dy/dt = −50y, is Euler’s method with h = 0.05 stable? What step size is?”