PERSAMAAN
DIFERENSIAL
(DIFFERENTIAL EQUATION)
M E T O D E E U L E R M E T O D E R U N G E - K U T T A
PERSAMAAN DIFERENSIAL
• Persamaan paling penting dalam bidang rekayasa,
paling bisa menjelaskan apa yang terjadi dalam sistem fisik.
• Menghitung jarak terhadap waktu dengan
kecepatan tertentu, 50 misalnya.
50
dt
dx
PERSAMAAN DIFERENSIAL
• Solusinya, secara analitik dengan integral,
• C adalah konstanta integrasi
• Artinya, solusi analitis tersebut terdiri dari banyak
‘alternatif’
• C hanya bisa dicari jika mengetahui nilai x dan t.
Sehingga, untuk contoh di atas, jika x(0) = (x saat t=0) = 0, maka C = 0
KLASIFIKASI PERSAMAAN
DIFERENSIAL
Persamaan yang mengandung turunan dari satu atau lebih variabel tak bebas, terhadap satu atau lebih variabel bebas.
• Dibedakan menurut:
• Tipe (ordiner/biasa atau parsial)
• Orde (ditentukan oleh turunan tertinggi yang ada) • Liniarity (linier atau non-linier)
SOLUSI PERSAMAAN DIFERENSIAL
• Secara analitik, mencari solusi persamaan
diferensial adalah dengan mencari fungsi integral nya.
• Contoh, untuk fungsi pertumbuhan secara
eksponensial, persamaan umum:
kP
dt
But what you really want to know is…
the sizes of the boxes (or state variables) and how they change through time
That is, you want to know:
the state equations
There are two basic ways of finding the state equations for the state variables based on your known rate equations:
1) Analytical integration 2) Numerical integration
Suatu kultur bakteria tumbuh dengan kecepatan yang proporsional dengan jumlah bakteria yang ada pada setiap waktu. Diketahui bahwa jumlah bakteri bertambah menjadi dua kali lipat setiap 5 jam. Jika kultur tersebut berjumlah satu unit pada saat t = 0, berapa kira-kira jumlah bakteri setelah satu jam?
• Jumlah bakteri menjadi dua kali lipat setiap 5
jam, maka k = (ln 2)/5
• Jika P0 = 1 unit, maka setelah satu jam…
SOLUSI PERSAMAAN DIFERENSIAL
kP
dt
dP
dt
k
P
dP
t t P P
1 0 1 0)
(
ln
0 0t
t
Ck
P
P
kte
P
t
P
(
)
0)
(
1
)
1
(
5 )(1) ) 2 (ln (e
P
1487
.
1
Rate equation (dsolve in Maple) State equation
The Analytical Solution of the Rate
Equation is the State Equation
THERE ARE VERY FEW MODELS IN
ECOLOGY THAT CAN BE SOLVED
SOLUSI NUMERIK
• Numerical integration • Eulers
Numerical integration makes use of this relationship:
Which you’ve seen before…
Relationship between continuous and discrete time models *You used this relationship in Lab 1 to program the logistic rate equation in Visual Basic:
1 where , 1 1 t t K N rN N Nt t t t t dt dy y ytt t
, known
Fundamental Approach of Numerical Integration
y = f(t), unknown t, specified y t yt, known dt dy yt+t, estimated t dt dy y ytt t yt+t, unknown
Euler’s Method:
y
t+ t≈ y
t+
dy/
dt
t
1 where , 1 t t K N rN N N t t t t t dt dN Calculate dN/dt*1 at Nt Add it to Nt to estimate Nt+ tNt+ t becomes the new Nt Calculte dN/dt * 1 at new Nt
Use dN/dt to estimate next Nt+ t Repeat these steps to estimate the state function over your desired time length (here 30 years)
Nt/K with time, lambda = 1.7, time step = 1
0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0 10 20 30 40 50 time (years) Nt /K
EXAMPLE OF NUMERICAL
INTEGRATION
dy
dt
6
y
007
y
2.
Analytical solution to dy/dt
Y0 = 10
t = 0.5
point to estimate
y
Euler’s Method:
y
t+ t≈ y
t+
dy/
dt
t
yt = 10 m1 = dy/dt at yt m1 = 6*10-.007*(10)2 y = m1*t yest=yt + y t = 0.5 y estimated y(t+ t) analytical y(t+ t)dy
dt
6
y
007
y
2.
20
RUNGE-KUTTA
METHODS
MOTIVATION
• We seek accurate methods to solve ODEs that do
not require calculating high order derivatives.
• The approach is to use a formula involving
unknown coefficients then determine these
coefficients to match as many terms of the Taylor series expansion.
SECOND ORDER RUNGE-KUTTA
METHOD
22possible.
as
accurate
as
is
that
such
,
,
,
:
Problem
)
,
(
)
,
(
1 2 1 2 2 1 1 1 1 2 1
i i i i i i iy
w
w
Find
K
w
K
w
y
y
K
y
h
x
f
h
K
y
x
f
h
K
TAYLOR SERIES IN ONE VARIABLE
23h
x
and
x
between
is
x
where
x
f
n
h
x
f
i
h
h
x
f
f(x)
n
n n i n i i
(
)
)!
1
(
)
(
!
)
(
of
expansion
Series
Taylor
order
The
) 1 ( 1 ) ( 0 th Approximation ErrorDERIVATION OF 2
NDORDER
RUNGE-KUTTA METHODS – 1 OF 5
24)
(
)
,
(
'
2
)
,
(
:
as
written
is
which
)
(
2
)
,
(
:
ODE
solve
to
Used
Expansion
Series
Taylor
Order
Second
3 2 1 3 2 2 2 1h
O
y
x
f
h
y
x
f
h
y
y
h
O
dx
y
d
h
dx
dy
h
y
y
y
x
f
dx
dy
i i i i i i i i
DERIVATION OF 2
NDORDER
RUNGE-KUTTA METHODS – 2 OF 5
25)
(
2
)
,
(
)
,
(
:
)
,
(
)
,
(
)
,
(
)
,
(
'
ation
differenti
rule
-chain
by
obtained
is
)
,
(
'
where
3 2 1O
h
h
y
x
f
y
f
x
f
h
y
x
f
y
y
ng
Substituti
y
x
f
y
f
x
f
dx
dy
y
y
x
f
x
y
x
f
y
x
f
y
x
f
i i i i i i
TAYLOR SERIES IN TWO VARIABLES
26 ) , ( and ) , ( between joining line the on is ) , ( ) , ( )! 1 ( 1 ) , ( ! 1 ... 2 ! 2 1 ) , ( ) , ( 1 0 2 2 2 2 2 2 2 k y h x y x y x error ion approximat y x f y k x h n y x f y k x h i y x f hk y f k x f h y f k x f h y x f k y h x f n n i i
DERIVATION OF 2
NDORDER
RUNGE-KUTTA METHODS – 3 OF 5
27)
,
(
)
,
(
:
ng
Substituti
)
,
(
)
,
(
that
such
,
,
,
:
Problem
1 2 1 1 2 2 1 1 1 1 2 1 2 1K
y
h
x
f
h
w
y
x
f
h
w
y
y
K
w
K
w
y
y
K
y
h
x
f
h
K
y
x
f
h
K
w
w
Find
i i i i i i i i i i i i
DERIVATION OF 2
NDORDER
RUNGE-KUTTA METHODS – 4 OF 5
28 ... ) , ( ) , ( ) ( ... ) , ( ) ( ... ) , ( ) , ( : ... ) , ( ) , ( 2 2 2 2 2 1 1 1 2 2 1 1 1 2 1 1 1 1 i i i i i i i i i i i i i i i i i i i i y x f y f h w x f h w y x f h w w y y y f K x f h h w y x f h w w y y y f K x f h y x f h w y x f h w y y ng Substituti y f K x f h y x f K y h x f DERIVATION OF 2
NDORDER
RUNGE-KUTTA METHODS – 5 OF 5
29 2 1 , 1 : solution possible One solutions infinite unknowns 4 with equations 3 2 1 and , 2 1 , 1 : equations three following the obtain we terms, M atching ) ( 2 ) , ( ) , ( ... ) , ( ) , ( ) ( : for expansions two derived We 2 1 2 2 2 1 3 2 1 2 2 2 2 2 1 1 1 w w w w w w h O h y x f y f x f h y x f y y y x f y f h w x f h w y x f h w w y y y i i i i i i i i i i i i i 2
NDORDER RUNGE-KUTTA METHODS
302
1
and
,
2
1
,
1
:
that
such
,
,
,
Choose
)
,
(
)
,
(
2 2 2 1 2 1 2 2 1 1 1 1 2 1
w
w
w
w
w
w
K
w
K
w
y
y
K
y
h
x
f
h
K
y
x
f
h
K
i i i i i iALTERNATIVE FORM
2 2 1 1 1 1 2 1)
,
(
)
,
(
Kutta
e
Order Rung
Second
K
w
K
w
y
y
K
y
h
x
f
h
K
y
x
f
h
K
i i i i i i
31
1 1 2 2
1 1 2 1)
,
(
)
,
(
Form
e
Alternativ
k
w
k
w
h
y
y
k
h
y
h
x
f
k
y
x
f
k
i i i i i i
CHOOSING
,
, W
1AND W
2 32
Corrector
Single
a
with
'
is
This
)
,
(
)
,
(
2
2
1
)
,
(
)
,
(
:
becomes
method
Kutta
-e
Order Rung
Second
2
1
,
1
then
,
1
choosing
example,
For
0 1 1 2 1 1 1 2 1 2 1s Method
Heun
y
x
f
y
x
f
h
y
K
K
y
y
K
y
h
x
f
h
K
y
x
f
h
K
w
w
i i i i i i i i i i i
CHOOSING
,
, W
1AND W
2 33M ethod
M idpoint
the
is
This
)
2
,
2
(
)
2
,
2
(
)
,
(
:
becomes
method
Kutta
-e
Order Rung
Second
1
,
0
,
2
1
then
2
1
Choosing
1 2 1 1 2 1 2 1K
y
h
x
f
h
y
K
y
y
K
y
h
x
f
h
K
y
x
f
h
K
w
w
i i i i i i i i i
2
NDORDER RUNGE-KUTTA METHODS
ALTERNATIVE FORMULAS
34 2 1 1 1 i 2 12
1
2
1
1
)
,
(
)
,
(
)
0
(select
mulas
Kutta For
e
Order Rung
Second
K
K
y
y
K
y
h
x
f
h
K
y
x
f
h
K
i i i i i
2
1
1
,
2
1
,
:
number
nonzero
any
Pick
1
,
2
1
,
2
1
1 2 2 1 2 2
w
w
w
w
w
w
SECOND ORDER RUNGE-KUTTA
METHOD
EXAMPLE CISE301_Topic8 L4&5 35
8269 . 3 2 / ) 1662 . 0 18 . 0 ( 4 2 / ) 1 ( ) 01 . 0 1 ( 1662 . 0 ) ) 01 . ( ) 18 . 0 ( 1 ( 01 . 0 ) , ( 18 . 0 ) 1 ( 01 . 0 ) 4 , 1 ( : 1 STEP 1 , 01 . 0 , 4 ) 1 ( , 1 ) ( RK2 using (1.02) find to system following the Solve 2 1 3 0 2 0 1 0 0 2 3 0 2 0 0 0 1 3 2 K K x x t x K x h t f h K t x x t f h K h x t x t x x
SECOND ORDER RUNGE-KUTTA
METHOD
EXAMPLE 36
6662 . 3 ) 1546 . 0 1668 . 0 ( 2 1 8269 . 3 2 1 ) 01 . 1 ( ) 01 . 0 01 . 1 ( 1546 . 0 ) ) 01 . ( ) 1668 . 0 ( 1 ( 01 . 0 ) , ( 1668 . 0 ) 1 ( 01 . 0 ) 8269 . 3 , 01 . 1 ( 2 STEP 2 1 3 1 2 1 1 1 1 2 3 1 2 1 1 1 1 K K x x t x K x h t f h K t x x t f h K1
RK2,
Using
[1,2]
for t
Solution
,
4
)
1
(
,
)
(
1
)
(
2
3
x
t
t
x
t
x
37
2
NDORDER RUNGE-KUTTA
)
(
is
error
global
and
)
(
is
error
Local
2
)
,
(
)
,
(
corrector
single
a
with
method
s
Heun'
to
Equivalent
RK2
as
Know
1,
of
value
Typical
2 3 2 1 1 1 2 1h
O
h
O
k
k
h
y
y
h
k
y
h
x
f
k
y
x
f
k
i i i i i i
38 RK2HIGHER-ORDER RUNGE-KUTTA
39
Higher order Runge-Kutta methods are available. Derived similar to second-order Runge-Kutta.
Higher order methods are more accurate but require more calculations.
3
RDORDER RUNGE-KUTTA
40 RK3
)
(
is
error
Global
and
)
(
is
error
Local
4
6
)
2
,
(
)
2
1
,
2
(
)
,
(
RK3
as
Know
3 4 3 2 1 1 2 1 3 1 2 1h
O
h
O
k
k
k
h
y
y
h
k
h
k
y
h
x
f
k
h
k
y
h
x
f
k
y
x
f
k
i i i i i i i i
4
THORDER RUNGE-KUTTA
41 RK4
)
(
is
error
global
and
)
(
is
error
Local
2
2
6
)
,
(
)
2
1
,
2
(
)
2
1
,
2
(
)
,
(
4 5 4 3 2 1 1 3 i 4 2 i 3 1 2 1h
O
h
O
k
k
k
k
h
y
y
h
k
y
h
x
f
k
h
k
y
h
x
f
k
h
k
y
h
x
f
k
y
x
f
k
i i i i i i i i
HIGHER-ORDER RUNGE-KUTTA
1 3 4 5 6
1 5 4 3 2 1 6 4 1 5 3 2 4 2 1 3 1 2 1 7 32 12 32 7 90 ) 7 8 7 12 7 12 7 2 7 3 , ( ) 16 9 16 3 , 4 3 ( ) 2 1 , 2 1 ( ) 8 1 8 1 , 4 1 ( ) 4 1 , 4 1 ( ) , ( k k k k k h y y h k h k h k h k h k y h x f k h k h k y h x f k h k h k y h x f k h k h k y h x f k h k y h x f k y x f k i i i i i i i i i i i i i i 42EXAMPLE
4
TH-ORDER RUNGE-KUTTA METHOD
43
)
4
.
0
(
)
2
.
0
(
4
2
.
0
5
.
0
)
0
(
1
2y
and
y
compute
to
RK
Use
h
y
x
y
dx
dy
RK4
EXAMPLE: RK4
) 4 . 0 ( ), 2 . 0 ( 4 5 . 0 ) 0 ( , 1 : Problem 2 y y find to RK Use y x y dx dy 444
THORDER RUNGE-KUTTA
45 RK4
)
(
is
error
global
and
)
(
is
error
Local
2
2
6
)
,
(
)
2
1
,
2
(
)
2
1
,
2
(
)
,
(
4 5 4 3 2 1 1 3 i 4 2 i 3 1 2 1h
O
h
O
k
k
k
k
h
y
y
h
k
y
h
x
f
k
h
k
y
h
x
f
k
h
k
y
h
x
f
k
y
x
f
k
i i i i i i i i
EXAMPLE: RK4
2 2 0.8293 6 7908 . 1 2 . 0 16545 . 0 1 ) , ( 654 . 1 1 . 0 164 . 0 1 ) 2 1 , 2 1 ( 64 . 1 1 . 0 15 . 0 1 ) 2 1 , 2 1 ( 5 . 1 ) 1 ( ) , ( 4 3 2 1 0 1 2 0 0 3 0 0 4 2 0 0 2 0 0 3 2 0 0 1 0 0 2 2 0 0 0 0 1 k k k k h y y x y h k y h x f k x y h k y h x f k x y h k y h x f k x y y x f k ) 4 . 0 ( ), 2 . 0 ( 4 5 . 0 ) 0 ( , 1 : Problem 2 y y find to RK Use y x y dx dy 5 . 0 , 0 1 ) , ( 0.2 0 0 2 y x x y y x f h 46 See RK4 Formula S tep 1
EXAMPLE: RK4
2 2
1.2141 6 2 . 0 0555 . 2 ) , ( 9311 . 1 ) 2 1 , 2 1 ( 9182 . 1 ) 2 1 , 2 1 ( 1.7893 ) , ( 4 3 2 1 1 2 3 1 1 4 2 1 1 3 1 1 1 2 1 1 1 k k k k y y h k y h x f k h k y h x f k h k y h x f k y x f k ) 4 . 0 ( ), 2 . 0 ( 4 5 . 0 ) 0 ( , 1 : Problem 2 y y find to RK Use y x y dx dy 8293 . 0 , 2 . 0 1 ) , ( 0.2 1 1 2 y x x y y x f h 47 S tep 2
EXAMPLE: RK4
) 4 . 0 ( ), 2 . 0 ( 4 5 . 0 ) 0 ( , 1 : Problem 2 y y find to RK Use y x y dx dy xi yi 0.0 0.5 0.2 0.8293 0.4 1.2141 48SUMMARY
• Runge Kutta methods generate an accurate
solution without the need to calculate high order derivatives.
• Second order RK have local truncation error of
order O(h3) and global truncation error of order
O(h2).
• Higher order RK have better local and global
truncation errors.
• N function evaluations are needed in the Nth order
RK method.