Docsity

Computational Methods for ODEs: Runge-Kutta and Multi-Step Methods - Prof. Ramani Duraiswa, Study notes of Computer Science

Partial preview of the text

Download Computational Methods for ODEs: Runge-Kutta and Multi-Step Methods - Prof. Ramani Duraiswa and more Study notes Computer Science in PDF only on Docsity!

Computational Methods CMSC/AMSC/MAPL 460Ordinary differential equationsRamani Duraiswami,Dept. of Computer Science Several slides adapted from Prof. ERIC SANDT, TAMU

ODE: Previous class• Standard form• Examples of converting equations to standard form– Volterra equation• Euler Method (an explicit method)• Backward Euler Method (an implicit/nonlinear method)• A predictor corrector method

Runge-Kutta MethodsExplicit methods: Use known valuesnd^ Derivation of the 2order RK methodLook for a formula of the type^ (^ ) (^

n 1^ n^1

2 , 1 n n , 2 n n^1

y^ y^ ak^ bk k^ hf^ x^ y k^ hf^ x^ h y

k α^ β

=^ +^ ++ = =^ +^ ∆^

Runge-Kutta MethodsThe initial conditions are:The Taylor series expansion including 2

nd^ order

terms is(^ ( )^ (^ )^

(^22) ) (^ )n n n^ n

n 1^ n^

,^ ,^2 2! dy^ x^ y^ d y^

x^ yh y^ x^ y^ x^ h^ dy^ (^ )^ yxy^ =(^ ) yxf ,=^00 dx =^ +^ + + dx^ dx

Runge-Kutta MethodsFrom the Runge-Kutta^ (^ The definition of the functionExpand the next step

)

n 1^ n^

,n n y^ y^ ahf^ bhf^

x^ h y^ hf^ α^ β= + + +^ ++ (^ )n^ n^

x^ y

, f x h y^ hf^ f^ hf

hf f α^ βα

β +^ +^ =^ +

  • ( ) [ ]

n 1^ n^

x^ y 2 2 n y

y^ y^ ahf^ bh^

f^ hf^ hf f^ α^ β= + + +^ ++ y a b hf b^ h f^ b^ h f f α^ β= + + +^ +

Runge-Kutta MethodsFrom the Runge-Kutta^2 [^ ]^ Compare with the Taylor series

n 1^ n^

y

y^ y^ a^ b hf^

b^ h f^ b^ h f f^ α^ β= + + + ++ [ ] (^1) =+ ba (^1) = b α 4 Unknowns (^21) = b β 2

Runge-Kutta Method (

nd^ Order)Example

Consider^

Exact Solution

The initial condition is:The step size is:Use the coefficients

(^1) dy 2 y = (^) y −= x + (^1) dx ( ) 10 = y (^1). (^0) =∆ h 11 1 ,====βα ba (^22)

Runge-Kutta Method

nd^ (2Order)Example The values are^ (^

, k hf x y =) 1 i i , k hf x h y^ k = +^ + ( ) 2 i i^11 y y k^ k = + +[^ ]i 1 i (^1 2) +^2

Runge-Kutta Method

nd (2 Order) Example [b] The values are^ (^

(^3312) ,,,====βα ba (^2233) , k hf x y =) 1 i i , k hf x h y k = + + α β ( ) 2 i i (^1) y y ak bk = + +i 1 i (^1 2) +

Runge-Kutta Method

xn^ y^ n^ y'n^ hy'n^ y*

  • • The values are similar to that of the Modified Euler• also a second order method k Estimate nd (2 Order) Example
    • k Solution Exact Error
      • 0 1.00000 -1.00000 -0.10000 0. n+1 y' n+1 h(y'n+1 )
      • -0.81000 -0.08100 1.000000 0.
        • 0.1 0.90950 -0.82719 -0.08272 0.
        • -0.68357 -0.06836 0.909091 -0.
          • 0.2 0.83396 -0.69549 -0.06955 0.
          • -0.58433 -0.05843 0.833333 -0.
            • 0.3 0.76997 -0.59286 -0.05929 0.
            • -0.50507 -0.05051 0.769231 -0.
              • 0.4 0.71507 -0.51133 -0.05113 0.
              • -0.44082 -0.04408 0.714286 -0.
                • 0.5 0.66747 -0.44551 -0.04455 0.
                • -0.38802 -0.03880 0.666667 -0.
                  • 0.6 0.62579 -0.39161 -0.03916 0.
                  • -0.34413 -0.03441 0.625000 -0.
                    • 0.7 0.58900 -0.34692 -0.03469 0. - -0.30726 -0.03073 0.588235 -0. - 0.8 0.55629 -0.30946 -0.03095 0. - -0.27599 -0.02760 0.555556 -0. - 0.9 0.52702 -0.27775 -0.02778 0. - -0.24925 -0.02492 0.526316 -0. - 1 0.50067 -0.25067 -0.02507 0. - -0.22620 -0.02262 0.500000 -0. - The values are k Estimate nd (2 Order) Example [b] - k Solution Exact Error - 0 1.00000 -1.00000 -0.10000 0. n+1 y' n+1 h(y'n+1 ) Exact - -0.72250 -0.07225 1.000000 0. - 0.1 0.90925 -0.82674 -0.08267 0. - -0.61660 -0.06166 0.909091 -0. - 0.2 0.83358 -0.69486 -0.06949 0. - -0.53195 -0.05320 0.833333 -0. - 0.3 0.76953 -0.59217 -0.05922 0. - -0.46335 -0.04634 0.769231 -0. - 0.4 0.71460 -0.51066 -0.05107 0. - -0.40705 -0.04070 0.714286 -0. - 0.5 0.66699 -0.44488 -0.04449 0. - -0.36031 -0.03603 0.666667 -0. - 0.6 0.62532 -0.39103 -0.03910 0. - -0.32111 -0.03211 0.625000 -0. - 0.7 0.58855 -0.34639 -0.03464 0. - -0.28793 -0.02879 0.588235 -0. - 0.8 0.55586 -0.30898 -0.03090 0. - -0.25960 -0.02596 0.555556 -0. - 0.9 0.52661 -0.27731 -0.02773 0. - -0.23523 -0.02352 0.526316 -0. - 1 0.50028 -0.25028 -0.02503 0. - -0.21412 -0.02141 0.500000 -0.

th^ th 4 -orderorder 4 - Runge--Kutta MethodKutta MethodRungef^2 f f^3 f 1 x x^ + h/2^ x^ + hi i^ i^

4 f 1 ( ) 22 fffff +++=^4321

Volterra example• Write a function in standard form function f = rabfox(t,y)% Computes y’ for the Volterra model.% y(1) is the number of rabbits at time t.% y(2) is the number of foxes at time t.global alpha % interaction constantt % a print statement, just so we can see howfast% the progress is, and what stepsize is beingusedf(1,1) = 2y(1) - alphay(1)y(2);f(2,1) = -y(2) + alphay(1)*y(2);

Runge-Kutta Method

th^ (4 Order)Example

Consider^

Exact Solution

dy^^2^ xy −=^ dx The initial condition is:The step size is:

x 2 22 exxy −++= ( ) 10 = y (^1). 0 =∆ h

th^ thThe 4 Order Runge-The 4Order Runge -KuttaKutta The example of a single step:^ (^ )[^ ]^ (^ )^

(^ )^1.^0011. (^01) , (^01). (^0) , 11 (^ )^10475.^005.^1 ,^05.^01.^0 , 22 11 (^ )^104988.^02 /.^1 ,^05.^01.^0 , (^22) ( )[ ] (^ )^109499.^0104988.^1 ,^1.^01. (^0) , 1 [ ]^104829.^1224321 n 6

341 n

=++++

==+ ∆+∆= ⎤ =+=⎥ ⎦ ⎡^ ⎞⎛^ +∆+∆=⎟⎜⎢⎠⎝⎣ ⎤ ==⎥ ⎦ ⎡^ ⎞⎛^ +∆+∆=⎟⎜⎢⎠⎝⎣

=−== ∆= fkyhxfhk kkkkyy +

kfky fyxfhk fkyhxfhk hxfhk