Document 15040901

advertisement
Matakuliah : METODE NUMERIK I
Tahun
: 2008
HAMPIRAN NUMERIK SOLUSI
PERSAMAAN DIFERENSIAL
(lanjutan)
Pertemuan 12
Runge-Kutta Methods
Runge-Kutta methods are very popular
because of their good efficiency; and are
used in most computer programs for
differential equations. They are single-step
methods, as the Euler methods.
Bina Nusantara
Runge-Kutta Methods
To convey some idea of how the Runge-Kutta
is developed, let’s look at the derivation of
the 2nd order. Two estimates
yn 1  yn  ak1  bk 2
k1  hf xn , yn 
k 2  hf xn  h, yn  k1 
Bina Nusantara
Runge-Kutta Methods
The initial conditions are:
dy
 f  x, y 
dx
yx0   y0
The Taylor series expansion
dy xn , yn  h d y xn , yn 
yxn 1   y xn   h

2
dx
2!
dx
2
Bina Nusantara
2
Runge-Kutta Methods
From the Runge-Kutta
yn 1  yn  ahf  bhf xn  h, yn  hf 
The definition of the function
f xn  h, yn  hf   f  hf x  hf f y
Expand the next step
yn 1  yn  ahf  bh f  hf x  hf f y


 yn  a  bhf  bh 2 f  bh 2 f f y
Bina Nusantara
Runge-Kutta Methods
From the Runge-Kutta
yn 1  yn  a  bhf  bh f  bh f f y
2
Compare with the Taylor series
a  b  1
1
b 
2
1
b 
2
Bina Nusantara
4 Unknowns
2
Runge-Kutta Methods
The Taylor series coefficients (3 equations/4
1
1
unknowns)
a  b  1, b  , b 
2
2
2
1
3
3
If you select “a” as a  , b  ,   ,  
3
3
2
2
If you select “a” as
1
1
a  b  ,    1
2
2
Note:
These coefficient would result in a
modified Euler or
Midpoint Method
Bina Nusantara
Runge-Kutta Method
Example
Consider
Exact Solution
dy
2
 y
dx
The initial condition is:
The step size is:
1
y
1 x
y0  1
h  0.1
Use the coefficients
Bina Nusantara
(2nd Order)
1
1
a  b  ,    1
2
2
Runge-Kutta Method (2nd
Order) Example
The values are
k1  hf xi , yi 
k 2  hf xi  h, yi  k1 
1
yi 1  yi  k1  k 2 
2
Bina Nusantara
Runge-Kutta Method (2nd Order)
Example
values are equivalent of Modified Euler
k1
Estimate
Solution
k2
xn
yn
y'n
hy'n
y* n+1
y*' n+1
h(y*'n+1 )
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
1.00000
0.90950
0.83396
0.76997
0.71507
0.66747
0.62579
0.58900
0.55629
0.52702
0.50067
-1.00000
-0.82719
-0.69549
-0.59286
-0.51133
-0.44551
-0.39161
-0.34692
-0.30946
-0.27775
-0.25067
-0.10000
-0.08272
-0.06955
-0.05929
-0.05113
-0.04455
-0.03916
-0.03469
-0.03095
-0.02778
-0.02507
0.90000
0.82678
0.76441
0.71069
0.66394
0.62292
0.58663
0.55431
0.52535
0.49925
0.47560
-0.81000
-0.68357
-0.58433
-0.50507
-0.44082
-0.38802
-0.34413
-0.30726
-0.27599
-0.24925
-0.22620
-0.08100
-0.06836
-0.05843
-0.05051
-0.04408
-0.03880
-0.03441
-0.03073
-0.02760
-0.02492
-0.02262
Bina Nusantara
Exact
Error
1.000000
0.909091
0.833333
0.769231
0.714286
0.666667
0.625000
0.588235
0.555556
0.526316
0.500000
0.000000
-0.000409
-0.000629
-0.000740
-0.000789
-0.000801
-0.000790
-0.000768
-0.000738
-0.000705
-0.000671
Runge-Kutta Method
(2nd
Order) Example [b]
The values are
2
1
3
3
a , b ,   ,  
3
3
2
2
k1  hf xi , yi 
k 2  hf xi  h, yi  k1 
yi 1  yi  ak1  bk 2
Bina Nusantara
Runge-Kutta Method (2nd Order)
Example [b]
The values are
k1
Estimate
Solution
k2
Exact
Error
Exact
1.000000
0.909091
0.833333
0.769231
0.714286
0.666667
0.625000
0.588235
0.555556
0.526316
0.500000
0.000000
-0.000159
-0.000248
-0.000295
-0.000317
-0.000324
-0.000321
-0.000314
-0.000303
-0.000291
-0.000278
xn
yn
y'n
hy'n
y* n+1
y*' n+1
h(y*'n+1 )
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
1.00000
0.90925
0.83358
0.76953
0.71460
0.66699
0.62532
0.58855
0.55586
0.52661
0.50028
-1.00000
-0.82674
-0.69486
-0.59217
-0.51066
-0.44488
-0.39103
-0.34639
-0.30898
-0.27731
-0.25028
-0.10000
-0.08267
-0.06949
-0.05922
-0.05107
-0.04449
-0.03910
-0.03464
-0.03090
-0.02773
-0.02503
0.85000
0.78524
0.72935
0.68070
0.63800
0.60026
0.56667
0.53659
0.50951
0.48501
0.46274
-0.72250
-0.61660
-0.53195
-0.46335
-0.40705
-0.36031
-0.32111
-0.28793
-0.25960
-0.23523
-0.21412
-0.07225
-0.06166
-0.05320
-0.04634
-0.04070
-0.03603
-0.03211
-0.02879
-0.02596
-0.02352
-0.02141
Bina Nusantara
Runge-Kutta Methods
Method
Euler
(Error of the order h2)
Modified Euler
(Error of the order h3)
Equations
y  k1
k1  h f  x, y 
1
y  k1  k 2 
2
k1  h f  x, y 
k 2  h f  x  h, y  k1 
Heun
(Error of the order h4)
1
k1  3k 3 
4
k1  h f  x, y 
y 
 
1
1

k 2  h  f  x  h, y  k1  
3
3

 
4th order Runge Kutta
(Error of the order h5)
Bina Nusantara
 
2
2

k 3  h  f  x  h, y  k 2 
3
3

 
1
y  k1  2k 2  2k 3  k 4 
6
k1  h f  x, y 
 
1
1

k 2  h  f  x  h, y  k1 
2
2

 
 
1
1

k 3  h  f  x  h, y  k 2  
2
2

 
k 4  h f  x  h, y  k 3 
The 4th Order Runge-Kutta
The general
form of the
equations:
1
y  k1  2k 2  2k3  k 4 
6
k1  h f  x, y 
 
1
1 
k 2  h  f  x  h, y  k1 
2
2 
 
 
1
1 
k3  h  f  x  h, y  k 2 
2
2 
 
k 4  h f x  h, y  k3 
Bina Nusantara
The 4th Order Runge-Kutta
This is a fourth order function that
solves an initial value problems using a
four step program to get an estimate of
the Taylor series through the fourth
order.
This will result in a local error of O(Dh5)
and a global error of O(Dh4)
Bina Nusantara
4th-order
Runge-Kutta Method
f2
f4
f3
f1
f
f 
xi
Bina Nusantara
xi + h/2
1
 f1  2 f 2  2 f 3  f 4 
6
xi + h
Runge-Kutta Method
Order) Example
Consider
dy
2
 yx
dx
Exact Solution
y  2  2x  x  e
2
The initial condition is:
The step size is:
Bina Nusantara
(4th
y0  1
h  0.1
x
The 4th Order Runge-Kutta
The example of a single step:


k1  h f  x, y   0.1 f 0,1  0.1 1  0 2  0.1
 
1
1 
k 2  h  f  x  h, y  k1   0.1 f 0.05,1.05  0.10475
2
2 
 
 
1
1 
k3  h  f  x  h, y  k 2   0.1 f 0.05,1.  k 2 / 2   0.104988
2
2 
 
k 4  h f x  h, y  k3   0.1 f 0.1,1.104988  0.109499
1
yn 1  yn  k1  2k 2  2k3  k 4   1.104829
6
Bina Nusantara
0
0
1
-2
Runge-Kutta Method
-4
Example
2
4
(4th3 Order)
-6
-8
The values for the 4th order
Runge-Kutta method
-10
x
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
y
f(x,y)
1
1.104829
1.218597
1.340141
1.468175
1.601278
1.73788
1.876246
2.014458
2.150396
2.281717
1
1.094829
1.178597
1.250141
1.308175
1.351278
1.37788
1.386246
1.374458
1.340396
1.281717
Bina Nusantara
k
1
0.1
0.109483
0.11786
0.125014
0.130817
0.135128
0.137788
0.138625
0.137446
0.13404
0.128172
f2
1.0475
1.13707
1.215027
1.280148
1.331084
1.366342
1.384274
1.383059
1.360681
1.314915
1.243303
k
2
0.10475
0.113707
0.121503
0.128015
0.133108
0.136634
0.138427
0.138306
0.136068
0.131492
0.12433
f3
1.049875
1.139182
1.216848
1.281648
1.332229
1.367095
1.384594
1.382899
1.359992
1.313641
1.241382
k
3
0.104988
0.113918
0.121685
0.128165
0.133223
0.13671
0.138459
0.13829
0.135999
0.131364
0.124138
f4
1.094988
1.178747
1.250282
1.308306
1.351398
1.377988
1.38634
1.374536
1.340457
1.28176
1.195855
k
4
0.109499
0.117875
0.125028
0.130831
0.13514
0.137799
0.138634
0.137454
0.134046
0.128176
0.119586
Change
0.628974
0.682608
0.729263
0.768204
0.79862
0.819614
0.830196
0.82927
0.815626
0.787927
0.744694
Exact
1
1.104829
1.218597
1.340141
1.468175
1.601279
1.737881
1.876247
2.014459
2.150397
2.281718
Runge-Kutta Method
Example
(4th Order)
4th Order Runge-Kutta Method
y(5) = -111.4129 (111.4132)
The error is small
relative to the exact
solution.
Bina Nusantara
4
2
0
0
Y Value
The values are
equivalent to those of
the exact solution. If
we were to go out to
x=5.
1
2
-2
-4
-6
Exact
4th order
-8
-10
X Value
3
4
Runge-Kutta Method
Example
(4th Order)
A comparison between the 2nd order and
the 4th order Runge-Kutta methods show a
slight difference.
Error of the Methods
Runge Kutta Comparison
4
10.00
Error 2nd order method
Y Value
0
-2
0
1
2
-4
-6
-8
Exact
4
8.00
Error 4th order method
6.00
4.00
2.00
2nd order
0.00
4th order
0
-10
X Value
Bina Nusantara
3
Absolute |Error|
2
1
2
3
X Value
4
5
The 4th Order Runge-Kutta
Higher order differential equations can
be treated as if they were a set of
first-order equations. Runge-Kutta type
forward integration solutions can be
obtain. A more direct solution can be
obtained by repeating the whole process
used in first-order cases.
Bina Nusantara
The 4th Order Runge-Kutta
The general form of the 2nd order
equations:
y  f x, y, y
k1  h 2  f x, y, y
 h 2   
1
h
1
1 
  f  x  h, y 
k 2  
y  k1 , y 
k1 
2
2
4
h 
 2  
 h 2   
1
h
1
1 




k3  
f  x  h, y 
y  k2 , y 
k 2 


2
2
4
h 
 2  
 h 2   
2 
  f  x  h, y  hy  k3 , y 
k 4  
k3 
h 
 2  
Bina Nusantara
The step sizes are:
1
y  k1  k 2  k3 
3
1
k1  2k2  2k3  k4 
y 
3h
The next step would be:
y  x  h   y x   h y x   y
yx  h   y x   y
Bina Nusantara
Bina Nusantara
Soal Latihan
Gunakan Metode Runge-Kutta orde 2 dan orde
4 untuk menyelesaikan PDB berikut:
1. y’= -½ x2y, pada 0≤x≤1, y(0)=4, dan h=0,2
2. y’= x + y pada 0≤x≤1, y(0)=0, dan h=0,25
3. y’= y sin2(x) pada 0≤x≤3, y(0)=1, dan h=0,1
Bina Nusantara
Download