Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Ordinary Differential Equations

ODEs
Ordinary Differential Equations
• Equations which are composed of an unknown
function and its derivatives are called
differential equations.
dv c v - dependent variable
=g- v
dt m t - independent variable

• Differential equations play a fundamental role in


engineering because many physical phenomena
are best formulated mathematically in terms of
their rate of change.
Ordinary Differential Equations
• When a function involves one independent
variable, the equation is called an ordinary
differential equation (ODE).

•A partial differential equation (PDE) involves


two or more independent variables.
Ordinary Differential Equations

Differential equations are also classified as to


their order:
1. A first order equation includes a first derivative as
its highest derivative.

dy
- Linear 1st order ODE + a × y = f (x )
dx
dy
1st
- Non-Linear order ODE = f ( x, y )
Where f(x,y) is nonlinear
dx
Ordinary Differential Equations

2. A second order equation includes a second


derivative.
d2y dy
- Linear 2nd order ODE 2
+ p + Qy = f (x )
dx dx
- Non-Linear 2nd order ODE
2
d y dy
2
+ p( x, y ) + Q ( x, y ) × y = f ( x )
dx dx
• Higher order equations can be reduced to a system
of first order equations, by redefining a variable.
Ordinary Differential Equations
Runge-Kutta Methods

Euler’s Method

!"
= %(#, ")
!#

")*+ − ")
= %(#) , ") )

yi+1 = yi + h.f(xi, yi)


Runge-Kutta Methods

dy
= f ( x, y )
dx
Solution :
dy
yi +1 = y=i +f (fx(,xyi ,)yi ) × h
dx
Solution :
yi +1 = yi + f ( xi , yi ) × h
Obtain a solution between x = 0 to x = 4 with a step size of 0.5
for: dy 3
= -2 x + 12 x - 20 x + 8.5
2

dx Kondisi awal
Initial conditions are: x = 0 to y = 1

on : yi +1 = yi + f ( xi , yi ) × h x y
0 1
0.5
! "# , %# = −2"#) + 12"#, − 20"# + 8.5 1.0
1.5
2.0
2.5
3.0
3.5
4.0
n: yi +1 = yi + f ( xi , yi ) × h
! "# , %#) = −2"#* + 12"#- − 20"# + 8.5

x y
0 1
0.5 5.25
1.0 5.875
1.5
2.0
2.5
3.0
3.5
4.0
Euler’s Method: Example
• Although the computation captures the general trend
solution, the error is considerable.
• This error can be reduced by using a smaller step size.
Improvements of Euler’s method
• A fundamental source of error in Euler’s
method is that the derivative at the beginning
of the interval is assumed to apply across the
entire interval.

• Simple modifications are available:


– Heun’s Method
– The Midpoint Method
– Ralston’s Method
Runge-Kutta Methods y

• Heun’s Method:
Involves the determination
dydy
of two derivatives for the f(xi+h,yi+k1h)
= f ( x , y ) f(xi,yi)
dxdx = fat( xthe
interval , y ) initial point
xi xi+h
x
and the end point.
Solution
Solution ::
11 1 1 y
yiy+1i +1== yyii ++(( k1k+1 + k2 )k× 2h) × h ea
22 2 2
k k1== ff ((xxi ,, yyi ))
1 i i
k 2 = f (( xi + h ), ( yi + k1h ) ) Slope: 0.5(k1+k2)
k 2 = f (( xi + h ), ( yi + k1h ) ) x
xi xi+h
Runge-Kutta Methods y

• Midpoint Method:
dy Euler’s method to predict
Uses
ady = off (yxat
value , ythe
) midpoint of
dx= f ( x, y ) f(xi,yi) f(xi+h/2,yi+k1h/2)
the
dxinterval: x
Solution : xi xi+h/2
Solution
yi +1 = yi: + k 2 × h
y
yki +1== fy(i x+,ky2 ×) h
1 i i
k1 = f ( xi , yi )1 1 ea
k 2 = f ( xi +1 h, yi +1 k1h )
k 2 = f ( xi + 2h, yi + 2k1h )
2 2 Slope: k2
x
Chapter 25 xi xi+h
dy
Runge-Kutta
dy = f ( x, y ) Methods y
dx = f ( x, y )
•dx
Ralston’s Method:
Solution :
Solution :
1 2 f(xi+ 3/4 h,
yi +1 = yi + ( 1k1 + 2k 2 ) × h f(xi,yi) yi+3/4k1h)
yi +1 = yi + (3 k1 +3 k 2 ) × h xi
k1 = f ( xi , yi )3 3 xi+3/4h x
k1 = f ( xi , y3i ) 3 y
k 2 = f ( xi + h, yi + k1h )
43 4 3 ea
k = f ( x + h, y + k h )
2 i i 1
4 4
Slope:
(1/3k1+2/3k2)
Chapter 25 xi xi+h x
Runge-Kutta Methods
• Runge-Kutta methods achieve the accuracy of a Taylor series
approach without requiring the calculation of higher derivatives.
y i +1 = y i + f (x i , y i , h )h
Increment function
f = a1k 1 + a2 k 2 + + an k n
(representative slope
a ' s = constants over the interval)
k 1 = f (x i , y i )
k 2 = f (x i + p1h , y i + q11k 1h )
k 3 = f (x i + p 3h , y i + q 21k 1h + q 22 k 2 h )

k n = f (x i + p n -1h , y i + q n -1k 1h + q n -1,2 k 2 h + + q n -1,n -1k n -1h )


p ' s and q ' s are constants
Runge-Kutta Methods
• Various types of RK methods can be devised by employing
different number of terms in the increment function as
specified by n.
1. First order RK method with n=1 is Euler’s method.
– Error is proportional to O(h)
2. Second order RK methods:
- Error is proportional to O(h2)
yi +1 = yi + (a1k1 + a2 k 2 )h
k1 = f ( x i , yi )
k 2 = f ( xi + p1h, yi + q11k1h)
• Values of a1, a2, p1, and q11 are evaluated by setting the
second order equation to Taylor series expansion to the
second order term.
Runge-Kutta Methods
• Three equations to evaluate the four unknown constants
are derived:

a1 + a2 = 1
1
a 2 p1 = A value is assumed for one of the
2 unknowns to solve for the other
1 three.
a2 q11 =
2
Runge-Kutta Methods
1 1
a1 + a2 = 1, a 2 p1 = , a2 q11 =
2 2

• We can choose an infinite number of values for a2,there


are an infinite number of second-order RK methods.
• Every version would yield exactly the same results if the
solution to ODE were quadratic, linear, or a constant.
• However, they yield different results if the solution is
more complicated (typically the case).
= f ( x, y )
dxSolution :
Runge-KuttaSolution Methods : 1 2
yi + 1 = yi + ( k1 + k 2 ) × h
Three
dy of the most commonly used methods 1 3are: 1 3
= f ( x, y ) yi + 1 = yi + ( k1 + k 2 ) × h
yi +1 = yi + (a1k1 + a2 k 2 )h k1 = f ( xi , 2yi ) 2
dx dy
kSolution
• Huen Method : , y ) with a Single=kCorrector f ( x, y )
1 = f ( x i i dx 1 = f ( xi , y(ai )2=1/2)3 3
dy k = f ( x + h , y + k h )
=: f (( xi + h4), ( yi + k14h ) )
1
ky2i +1==f y(fix(+i x+(, ypk1)1h+ 1
, yi +k 2q)11×Solution 2 i i 1
hk1hk) 2dy
dx 2 2 yi +1 = yi +=k 2f×(hx, y )
k1 = f ( xi , yi ) dx
Solution
• The Midpoint : Method (a k12== 1)
f ( xi , yi )
k 2 = f (( xi + h ), ( yi + k1h ) ) Solution :
1 1
yi +=1 =f ( yx,i y+) k 2 × h
dy k 2 = f ( xi + h, yi 1+ k1h2)
yi +1 =2yi + ( k21 + k 2 ) × h
dx 3 3
k1 = f ( xi , yi )
• Raltson’s
Solution : Method (a2= 2/3) k1 = f ( xi , yi )
1 2 1
k = f ( x +
1 h , y + k h ) 3
yi +21 = yi + (i k1 + k 2i ) × h 1 k 2 = f ( xi + h, yi + k1h )
3
3 2 3 2 4 4
Obtain a solution between x = 0 to x = 4 with a step size of 0.5
for: dy 3
= -2 x + 12 x - 20 x + 8.5
2

dx Kondisi awal
Initial conditions are: x = 0 to y = 1

on : yi +1 = yi + f ( xi , yi ) × h x y
0 1
0.5
! "# , %# = −2"#) + 12"#, − 20"# + 8.5 1.0
1.5
2.0
2.5
3.0
3.5
4.0
Chapter 25 22
Runge-Kutta Methods
3. Third order RK methods
1
yi +1 = yi + ( k1 + 4k 2 + k3 ) h
6
where
k1 = f ( x i , yi )
1 1
k 2 = f ( xi + h, yi + k1h)
2 2
k3 = f ( xi + h, yi - k1h + 2k 2 h)

Chapter 25
Runge-Kutta Methods
4. Fourth order RK methods
1
yi +1 = yi + (k1 + 2k 2 + 2k3 + k 4 )h
6
where
k1 = f ( x i , yi )
1 1
k 2 = f ( xi + h, yi + k1h)
2 2
1 1
k3 = f ( xi + h, yi + k 2 h)
2 2
k3 = f ( xi + h, yi + k3 h)
Chapter 25
Comparison of Runge-Kutta Methods

Dengan menggunakan metode RK orde satu sampai


empat, tentukan harga y untuk x = 0 sampai x = 4
untuk:

f ( x, y ) = 4e 0.8 x
- 0.5 y
Kondisi awal y(0) = 2,
Catatan: jawaban eksaknya y(4) = 75.33896

Chapter 25

You might also like