10 - lecture note 09 - numerical solution ode.pdf

8
Lecture Note - Dr.Ir. Lilik Eko Widodo, MS 9-1 Lecture Note 9 Ordinary Differential Equation (ODE) 9.1. Solution of ODE using Runge-Kutta method – first order Differentiation is generally expressed as follows : ) y , x ( f ) x ( ' y dx dy = = as well as ) y , t ( f ) t ( ' y dt dy = = (9-1) If dx = h, then eq. (9-1) can be modified as 1 '( ) . (, ) n n n y y dx y x y hf xy + = + = + (9-2) Eq. (9-2) was considered to be the first order Runge-Kutta. Solution can be obtained only if the boundary condition (for x) or the initial condition (for t) is given. The increment of x (i.e. Δx = h) or the increment of time or time step (i.e. Δt = h) can be set based on the nature of the problem, wheter it includes higher accuracy or not. 9.1. Solution of ODE using Runge-Kutta method – higher order The second order of Runge-Kutta method was developed from the first order. Basically, the second order is subject to two corrections, whereas the first order has only one element of correction. The second orde Runge-Kuta was expressed as : y n+1 = y n + ak 1 + bk 2 (9-3) where : k 1 = hf (x n , y n ) k 2 = hf (x n +α h, y n +β k 1 ) k 2 = hf (x n +h, y n + k 1 ) h = x n+1 - x n Algorithm of second order Runge-Kutta method : o For equation : y’ = f(x, y) , y(x o ) = y o a = b = ½ , α = β = 1 o Calculate y n up to y(x o +nh) for constant h and n = 0, 1, 2, … using following equations : y n+1 = y n + ½ (k 1 + k 2 ) with k 1 = hf (x n , y n ) k 2 = hf (x n +h, y n +k 1 )

Upload: salam-vinder-dg-bengo

Post on 20-Nov-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

  • Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

    9-1

    Lecture Note 9 Ordinary Differential Equation (ODE)

    9.1. Solution of ODE using Runge-Kutta method first order Differentiation is generally expressed as follows :

    )y,x(f)x('ydxdy

    == as well as )y,t(f)t('ydtdy

    == (9-1)

    If dx = h, then eq. (9-1) can be modified as

    1 '( ) . ( , )n n ny y dx y x y h f x y+ = + = + (9-2)

    Eq. (9-2) was considered to be the first order Runge-Kutta. Solution can be obtained only if the boundary condition (for x) or the initial condition (for t) is given. The increment of x (i.e. x = h) or the increment of time or time step (i.e. t = h) can be set based on the nature of the problem, wheter it includes higher accuracy or not. 9.1. Solution of ODE using Runge-Kutta method higher order The second order of Runge-Kutta method was developed from the first order. Basically, the second order is subject to two corrections, whereas the first order has only one element of correction. The second orde Runge-Kuta was expressed as : yn+1 = yn + ak1 + bk2 (9-3) where : k1 = hf (xn, yn) k2 = hf (xn+ h, yn+ k1)

    k2 = hf (xn+h, yn+ k1) h = xn+1 - xn Algorithm of second order Runge-Kutta method : o For equation :

    y = f(x, y) , y(xo) = yo a = b = , = = 1

    o Calculate yn up to y(xo+nh) for constant h and n = 0, 1, 2, using following equations :

    yn+1 = yn + (k1 + k2) with k1 = hf (xn, yn) k2 = hf (xn+h, yn+k1)

  • Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

    9-2

    Algoritthm of fourth order Runge-Kutta method : o For equation :

    y = f(x, y) , y(xo) = yo o Calculate yn up to y(xo+nh) for constant h and n = 0, 1, 2, using following

    equations : yn+1 = yn + 1/6 (k1 + 2k2 + 2k3 + k4) with : (9-4) k1 = hf (xn, yn) k2 = hf (xn+ h, yn+ k1) k3 = hf (xn+ h, yn+ k2) k4 = hf (xn+h, yn+k3)

    Example 1: second order Runge-Kutta :

    Given : y

    x)y,x(f'y 1== and y(0) = 1

    Give : solution within interval x = 0 to x = 1 with h = 0.1 Solution was given in the Table 9-1 and correspondingly depicted by Figure 9.1.

    Table 9-1: Solution of example 1

    x yn k1 k2 y yn+1 0 1 -0.1000 -0.1111 -0.1056 0.8944

    0.1 0.8944 -0.1018 -0.1162 -0.1090 0.7855 0.2 0.7855 -0.1073 -0.1275 -0.1174 0.6681 0.3 0.6681 -0.1197 -0.1524 -0.1360 0.5321 0.4 0.5321 -0.1479 -0.2203 -0.1841 0.3479 0.5 0.3479 -0.2374 -0.8551 -0.5462 -0.1983 0.6 -0.1983 0.5642 -0.2133 0.1754 -0.0229 0.7 -0.0229 4.4387 0.0474 2.2430 2.2201 0.8 2.2201 0.0350 0.0357 0.0353 2.2554 0.9 2.2554 0.0457 0.0465 0.0461 2.3015 1 2.3015 0.0566 0.0576 0.0571 2.3586

  • Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

    9-3

    Figure 9.1: Solution of example 1

    9.3. Solution of ODE using Predictor - Corrector method Predictor-corrector method was considered to be likely Runge-Kutta with indefinite correction. The number of correction can be set depending on the accuracy that will be needed. The predictor-corrector method was based on the polynomial interpolation within interval between xn+1 and xn that was expressed as :

    [ ] ......,2,1n)y,x(f)y,x(f2hyy 1n1nnnn1n =++= +++ (9-5)

    x : independent variable y : dependent variable h : xn+1 - xn Eq. (9-5) is the implicit form for yn+1, since yn+1 appears to be an argument at right hand side. If f(x,y) is non-linear, then eq. (9-5) can not be closely solved. Accordingly, yn+1 will be iteratively solved. By introducing the value of xn, the first estimated value ( )0 1ny + on 1ny + will be obtained based on the first order Runge-Kutta method as : ( ) )y,x(hfyy nnn0 1n +=+ (9-6) Subsequenly using ( ) )y,x(f 0 1n1n ++ the first iteration will be performed by means substitution into the eq. (9-5), then will be obtained following equation :

    -0.5

    0

    0.5

    1

    1.5

    2

    2.5

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

    xn

    y n

  • Lecture Note - Dr.Ir. Lilik Eko Widodo, MS

    9-4

    ( ) ( )[ ])y,x(f)y,x(f2hyy 0 1n1nnnn

    11n +++ ++= (9-7)

    Second iteration will be obtained by means of substitution of ( ) )y,x(f 1 1n1n ++ into eq. (9-7). In general the iteration will be resulted in :

    ( ) ( )[ ] ......,2,1k)y,x(f)y,x(f2hyy 1k 1n1nnnn

    k1n =++=

    +++ (9-8)

    The iteration can only be stoped if the level of accuracy has already been achieved. Algorithm of Predictor Corrector : Step 1 : prediction step (outer iteration)

    For n starting from 1 and for equation y' = f(x,y), y(x0) = y0 with h = xn+1 - xn and xn = x0 + nh, calculate ( )0 1ny + using eq. (9-6).

    Step 2 : correction step (inner iteration) For k = 1,2, calculate ( )k 1ny + using eq. (9-9), until following level of accuration is achieved :