Professional Documents
Culture Documents
ece.uwaterloo.ca
dwharder@alumni.uwaterloo.ca
The average of five numbers x1, x2, x3, x4, and x5 is:
x1 x2 x3 x4 x5 1
x 5 x1 15 x2 15 x3 15 x4 15 x5
5
f x dx f x x
a
1 2 x1
a= =b
4th-order Runge Kutta and the Dormand-Prince Methods
8
Integration
f x dx f x x
a
2 3 x1
a= =b
4th-order Runge Kutta and the Dormand-Prince Methods
9
Integration
1
b
1
f x dx f x1 f x2 x2 x1
a 2 2
a= =b
4th-order Runge Kutta and the Dormand-Prince Methods
10
Integration
1
b
1 1
f x dx f x1 f x2 f x3 x3 x1
a 4 2 4
The composite
trapezoidal rule
a= =b
4th-order Runge Kutta and the Dormand-Prince Methods
11
Integration
Simpsons rule
a= =b
4th-order Runge Kutta and the Dormand-Prince Methods
12
Integration
a
8 8 8 8
a= =b
4th-order Runge Kutta and the Dormand-Prince Methods
13
Initial-value Problems
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
16
Initial-value Problems
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
17
Eulers Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
19
Eulers Method
y 0 1 y 0.5 y1 y0 0.5 1
1 0.5 0.5
4th-order Runge Kutta and the Dormand-Prince Methods
20
Eulers Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
21
Heuns Method
y 0 1
K1 1
K 2 f 0.5, 0.5
0.5 1.5 0.5 0.5 1
0.125
4th-order Runge Kutta and the Dormand-Prince Methods
23
Heuns Method
y 0 1
K1 K1 1 0.125
2 2
0.5625
y 0.5
y1 1 0.5 0.5625
0.71875
4th-order Runge Kutta and the Dormand-Prince Methods
24
Heuns Method
y 0 1
K1 K1 1 0.125
2 2
0.5625
4th-order Runge Kutta and the Dormand-Prince Methods
25
Mid-point Method
y 0 1
K1 f 0,1
K 2 f 0.25,1 0.25 1
f 0.25, 0.75
0.421875
4th-order Runge Kutta and the Dormand-Prince Methods
27
Mid-point Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
29
4th-order Runge-Kutta Method
K1 f tk , yk
K 2 f tk 12 h, yk 12 h K1
K3 f tk 12 h, yk 12 h K 2
4th-order Runge Kutta and the Dormand-Prince Methods
31
4th-order Runge-Kutta Method
K1 f tk , yk
K 2 f tk 12 h, yk 12 h K1
K3 f tk 12 h, yk 12 h K 2
K 4 f tk h, yk h K3
4th-order Runge Kutta and the Dormand-Prince Methods
32
4th-order Runge-Kutta Method
K1 f tk , yk
K 2 f tk 12 h, yk 12 h K1
K3 f tk 12 h, yk 12 h K 2
K 4 f tk h, yk h K3
and approximate yk 1 yk h 16 K1 13 K2 13 K3 16 K4
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
34
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
35
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
36
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
37
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
38
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
39
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
40
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
41
4th-order Runge-Kutta Method
y 0 1
y (0.5) 0.7963901345956429
Euler: 0.5
Heun: 0.71875
Mid-point: 0.7890625
4th-order R-K: 0.79620615641666
4th-order Runge Kutta and the Dormand-Prince Methods
42
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
43
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
44
4th-order Runge-Kutta Method
y 0 1
4th-order Runge Kutta and the Dormand-Prince Methods
45
4th-order Runge-Kutta Method
As an example,
>> format long
>> [t2a, y2a] = rk4( @f2a, [0, 1], 0, 2 )
t2a =
0 1
y2a =
0 0.265706380208333
>> [t2a, y2a] = rk4( @f2a, [0, 1], 0, 3 )
t2a =
0 0.500000000000000 1.000000000000000
y2a =
0 0.227653163407674 0.251787629335613
>> [t2a, y2a] = rk4( @f2a, [0, 1], 0, 4 )
t2a =
0 0.333333333333333 0.666666666666667 1.000000000000000
y2a =
0 0.190364751129471 0.243328110416578 0.250335465183716
4th-order Runge Kutta and the Dormand-Prince Methods
46
4th-order Runge-Kutta Method
yk 1 yk h 16 K1 13 K2 13 K3 16 K4
4th-order Runge Kutta and the Dormand-Prince Methods
47
Runge-Kutta Methods
K3 f tk c3h, yk c3h a3,1K1 a3,2 K 2
where a3,1 a3,2 1 defines a weighted average
yk 1 yk h 16 K1 13 K2 13 K3 16 K4 0
1
1
c A 2
1
0 1
b 2
1 0 0 1
1 1 1 1
6 3 3 6
4th-order Runge Kutta and the Dormand-Prince Methods
50
Runge-Kutta Methods
for k = 1:(n - 1)
K = zeros( 1, k_n );
K1 f tk , yk for m = 1:k_n
K 2 f tk 12 h, yk 12 h K1 K(m) = f( t_out(k) + h*c(m), ...
y_out(k) + h*c(m)*K*A(m,:) );
K3 f tk 12 h, yk 12 h K 2 end
yk 1 yk h 16 K1 13 K2 13 K3 16 K4
4th-order Runge Kutta and the Dormand-Prince Methods
51
Butcher Tableau
0
1
2 1
For the 4th-order Runge-Kutta method: 1
2 0 1
1 0 0 1
1 1 1 1
6 3 3 6
4th-order Runge Kutta and the Dormand-Prince Methods
52
Butcher Tableau
1 0 0 1 1 0 0 1
1 1 1 1 1 1 1 1
6 3 3 6 6 3 3 6
4th-order Runge Kutta and the Dormand-Prince Methods
53
Comparison
y 0 0
n = 4;
[t2e, y2e] = euler( @f2a, [0, 1], 0, 4*n+1 );
[t2h, y2h] = heun( @f2a, [0, 1], 0, 2*n+1 );
[t2r, y2r] = rk4( @f2a, [0, 1], 0, n+1 );
t2s = linspace( 0, 1, 101 );
Heun
Euler
Log of Error
Heun
y 0 1
t 13 2 3 13 t 2 3t
y t e 1 d 1 e
0
No antiderivative
4th-order Runge Kutta and the Dormand-Prince Methods
64
The Dormand-Prince Method
y 0 1
ztmp 1 0.1
1 0.9
0.905
2
Heuns method
4th-order Runge Kutta and the Dormand-Prince Methods
69
Adaptive Techniques
t f t0
2 t f t0 2 t f t0
4th-order Runge Kutta and the Dormand-Prince Methods
73
Adaptive Techniques
2 t f t0
e abs h
s Ch 2
2 t f t0
We can now substitute the first equation for Ch2:
e abs h
s ytmp ztmp
2 t f t0
4th-order Runge Kutta and the Dormand-Prince Methods
74
Adaptive Techniques
>> y_out =
1 0.9900 0.9801 0.9702 0.9603 0.9504 0.9405 0.9306 0.9207 0.9108 0.9044
1 9017
3168 355
33
46732
5247
49
176 18656
5103
1 35
384 0 500
113
125
192 2187
6784
11
84
5179
57600 0 7571
16695
393
640 339200
92097 187
2100
1
40
O(h4) approximation
35
384 0 500
1113
125
192 2187
6784
11
84 0 O(h5) approximation
4th-order Runge Kutta and the Dormand-Prince Methods
81
The Dormand-Prince Method
1 9017
3168 355
33
46732
5247
49
176 18656
5103
1 35
384 0 500
113
125
192 2187
6784
11
84
5179
57600 0 7571
16695
393
640 339200
92097 187
2100
1
40
35
384 0 500
1113
125
192 2187
6784
11
84 0
4th-order Runge Kutta and the Dormand-Prince Methods
82
The Dormand-Prince Method
1 9017
3168 355
33
46732
5247
49
176 18656
5103
1 35
384 0 500
113
125
192 2187
6784
11
84
5179
57600 0 7571
16695
393
640 339200
92097 187
2100
1
40
35
384 0 500
1113
125
192 2187
6784
11
84 0
4th-order Runge Kutta and the Dormand-Prince Methods
83
The Dormand-Prince Method
// ...
n_K = 7;
K = zeros( 1, n_K );
for m = 1:n_K
kvec(m) = f( t_out(k) + h*c(m), ...
y_out(k) + h*c(m)*K*A(m,:) );
end
y = y_out(k) + h*K*by;
z = y_out(k) + h*K*bz;
What value of h?
Previously, we specified the interval and the number of points
% else if s >= 1,
% We use y to approximate y_out(k + 1)
% t_out(k + 1) is the previous t-value plus h
% In this case, h is neither too large or too
% small, so only increment k
% else s < 1
% Divide h by two and try again with the smaller
% value of h (just go through the loop again
% without updating t_out, y_out, or k)
% end
%
% We must make one final check before we end the loop:
% if t_out(k) + h > tf, we must reduce the
% size of h so that t_out(k) + h == tf
% end
4th-order Runge Kutta and the Dormand-Prince Methods
89
Runge-Kutta Methods
As an example,
>> format long
>> [t2a_out, y2a_out] = dp45( @f2a, [0, 1], 0, 0.1, 0.001 )
t2a_out =
0 0.100000000000000 0.300000000000000 0.700000000000000 1.000000000000000
y2a_out =
0 0.082849167706690 0.179652764494993 0.244888142029126 0.249985161828570
y (1) t y t 1 t 1
2 2
y 0 0
4th-order Runge Kutta and the Dormand-Prince Methods
90
Runge-Kutta Methods
0.350996539397804
y = 0.179652764494993
z = 0.179654500779400 0.323819720073735
0.329753701664832
s = 1.549154681332583
4th-order Runge Kutta and the Dormand-Prince Methods
92
Runge-Kutta Methods
0.164101192287057
y = 0.225803586411837
z = 0.225804013589520 0.149107161192848
0.149844856343524
s = 2.199621019421089
0.011628711293105
y = 0.249807784433138
z = 0.249809573055606 0.005569794874352
0.005627856766790
s = 1.828638370749953
Note: but 0.9 + 0.4 > 1, so use h = 1 0.9 = 0.1
4th-order Runge Kutta and the Dormand-Prince Methods
94
Runge-Kutta Methods
0.000069445279659
y = 0.249995333556517
z = 0.249995333705456 0
0
s = 13.535998941577226
Remember, we artificially reduced h
4th-order Runge Kutta and the Dormand-Prince Methods
95
The Dormand-Prince Method
[1] Glyn James, Modern Engineering Mathematics, 4th Ed., Prentice Hall,
2007.