SME
Numerical Methods for Engineers · Problem type
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.”
Chart
RK4, 1 step of h = 0.5: y = 7.7881 at t = 0.5; solid, the exact y = 7.788, off by 0.001003%
This is an example. Type your own values to start a new problem.
y₀
Starting value
example
k
Rate constant
example
h
Step size
example
k₁
Slope at the start
worked out (not typed)
k₂
First middle slope
worked out (not typed)
k₃
Second middle slope
worked out (not typed)
k₄
Slope at the end
worked out (not typed)
y₁
Value by RK4
worked out (not typed)
yexact
Exact value
worked out (not typed)
ε
Error
worked out (not typed) · %
Formulas
k₁
=
k
×
y₀
−5 = −0.5 × 10
k₂
=
k
×
(
y₀
+
h
2
×
k₁
)
−4.375
=
−0.5
×
(10
+
0.5
2
×
(−5))
k₃
=
k
×
(
y₀
+
h
2
×
k₂
)
−4.4531
=
−0.5
×
(10
+
0.5
2
×
(−4.375))
k₄
=
k
×
(
y₀
+
h
×
k₃
)
−3.8867 = −0.5 × (10 + 0.5 × (−4.4531))
y₁
=
y₀
+
h
6
×
(
k₁
+
2
×
k₂
+
2
×
k₃
+
k₄
)
7.7881
=
10
+
0.5
6
×
(−5
+
2
×
(−4.375)
+
2
×
(−4.4531)
+
(−3.8867))
yexact
=
y₀
×
e
k
×
h
7.788
=
10
×
e
−0.5 × 0.5
ε
=
|
y₁
−
yexact|
÷
|yexact|
×
100
0.001003 = |7.7881 − 7.788| ÷ |7.788| × 100
Assumptions
•
dy/dt = f(y) = ky; RK4 samples the slope four times: at the start, twice at the middle, at the end.
•
y₁ = y₀ + (h ÷ 6)(k₁ + 2k₂ + 2k₃ + k₄), a weighted mean slope times h.
•
RK4 is fourth order: halving h cuts its error about 16 times.
Step-by-step
WE KNOW
y₀ = 10, k = −0.5, h = 0.5
FIND
slope at the start (k₁), first middle slope (k₂), second middle slope (k₃), slope at the end (k₄), value by RK4 (y₁), exact value (yexact), error (ε)
Step 1 · Find slope at the start (k₁)
Use k₁ = k × y₀
The slope ky at the start of the step.
k₁
=
−0.5
×
10
k₁
=
−5
Step 2 · Find first middle slope (k₂)
Use k₂ = k × (y₀ + h ÷ 2 × k₁)
Go
half
a
step
along
k₁
,
then
take
the
slope
there.
k₂
=
−0.5
×
(10
+
0.5
2
×
(−5))
k₂
=
−0.5
×
(10
+
0.25
×
(−5))
k₂
=
−0.5
×
(10
+
(−1.25))
k₂
=
−0.5
×
8.75
k₂
=
−4.375
Step 3 · Find second middle slope (k₃)
Use k₃ = k × (y₀ + h ÷ 2 × k₂)
Go
half
a
step
again,
now
along
k₂
,
and
take
the
slope
there.
k₃
=
−0.5
×
(10
+
0.5
2
×
(−4.375))
k₃
=
(−0.5)
×
8.9063
k₃
=
−4.4531
Step 4 · Find slope at the end (k₄)
Use k₄ = k × (y₀ + h × k₃)
Go
a
full
step
along
k₃
and
take
the
slope
at
the
end.
k₄
=
−0.5
×
(10
+
0.5
×
(−4.4531))
k₄
=
(−0.5)
×
7.7734
k₄
=
−3.8867
Step 5 · Find value by RK4 (y₁)
Use y₁ = y₀ + h ÷ 6 × (k₁ + 2 × k₂ + 2 × k₃ + k₄)
The
middle
slopes
count
twice;
step
h
along
the
weighted
mean.
y₁
=
10
+
0.5
6
×
(−5
+
2
×
(−4.375)
+
2
×
(−4.4531)
+
(−3.8867))
y₁
=
10
+
0.5
6
×
((−5)
+
(−8.75)
+
(−8.9062)
+
(−3.8867))
y₁
=
10
+
0.5
6
×
(−26.5429)
y₁
=
10
+
0.08333
×
(−26.5429)
y₁
=
10
+
(−2.212)
y₁
=
7.78809
Step 6 · Find exact value (yexact)
Use yexact = y₀ × ek × h
The exact solution of dy/dt = ky after one step.
yexact
=
10
×
e
−0.5 × 0.5
yexact
=
10
×
e
−0.25
yexact = 10 × 0.7788
yexact = 7.78801
Step 7 · Find error (ε)
Use ε = |y₁ − yexact| ÷ |yexact| × 100
The gap between the step and the exact answer, as a percent of the exact one.
ε
=
|7.78809
−
7.78801|
÷
|7.78801|
×
100
ε
=
|8.0000
×
10
-5
|
÷
|7.788|
×
100
ε
=
8.0000 ×
10
-5
7.788
×
100
ε
=
(1.0272
×
10
-5
)
×
100
ε
=
0.001003%
Check
Put the numbers back in. Both sides should match.
−5 = −0.5 × 10 ✓
−4.375
=
−0.5
×
(10
+
0.5
2
×
(−5))
✓
−4.4531
=
−0.5
×
(10
+
0.5
2
×
(−4.375))
✓
−3.8867 = −0.5 × (10 + 0.5 × (−4.4531)) ✓
7.78809
=
10
+
0.5
6
×
(−5
+
2
×
(−4.375)
+
2
×
(−4.4531)
+
(−3.8867))
✓
7.78801
=
10
×
e
−0.5 × 0.5
✓
0.001003 = |7.78809 − 7.78801| ÷ |7.78801| × 100 ✓
← Previous lesson
Numerical ODE solvers (Euler, Runge–Kutta)
Next lesson →
One Heun step (improved Euler)
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.
Related lessons
Numerical ODE solvers (Euler, Runge–Kutta)
Main lesson
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?”