Computational Methods CMSC/AMSC/MAPL 460 Ordinar differential equations Ramani Duraiswami, Dept. of Computer Science Several slides adapted from Prof. ERIC SANDT, TAMU
ODE: Previous class Standard form Eamples of converting equations to standard form Volterra equation Euler Method (an eplicit method) Backward Euler Method (an implicit/nonlinear method) A predictor corrector method
Toda Eplicit and Implicit methods Runge Kutta methods Matlab function RK45 Solve volterra equation Multistep methods: Adams Bashforth Implicit methods: Adams Moulton
Runge-Kutta Methods Eplicit methods: Use known values Derivation of the nd order RK method Look for a formula of the tpe ak bk + + + n n (, ) k hf n n (, ) k hf α h βk + + n n
Runge-Kutta Methods The initial conditions are: d d 0 f (, ) ( ) 0 The Talor series epansion including nd order terms is d, d, ( ) ( ) + + h + d! d ( ) h ( ) n n n n n n
Runge-Kutta Methods Epand the derivatives: d d d d d d [ f (, ) ] f + f f + f f The Talor series epansion becomes n+ n+ hf + h f+ ff ( ) Have epressed second derivative in terms of st derivatives of f
Runge-Kutta Methods From the Runge-Kutta n + n ahf + bhf + α n h, + β + n hf The definition of the function ( ) Epand the net step ( ) f + αh, + βhf f + αhf + βhf f n n [ ] ( α β ) + + ahf + bh f + hf + hf f n n + + + + n a b hf bαh f bβh f f
Runge-Kutta Methods From the Runge-Kutta [ ] + a + b hf + bαh f + bβ + h f f n n Compare with the Talor series [ a + b] αb βb 4 Unknowns
Runge-Kutta Methods The Talor series coefficients (3 equations/4 unknowns) [ a + b], αb, βb If ou select a as 3 3 a, b, α, β 3 3 If ou select a as a b, α β Note: These coefficient would result in a modified Euler or Midpoint Method
Runge-Kutta Method ( nd Order) Eample Consider Eact Solution d d The initial condition is: The step size is: h 0. ( 0 ) + Use the coefficients a b, α β
Runge-Kutta Method ( nd Order) Eample The values are (, ) k hf i i (, ) k hf + h + k i i + k + k [ ] i+ i
Runge-Kutta Method ( nd Order) Eample The values are similar to that of the Modified Euler also a second order method k Estimate Solution k Eact Error n n 'n h'n *n+ *' n+ h(*'n+ ) 0.00000 -.00000-0.0000 0.90000-0.8000-0.0800.000000 0.000000 0. 0.90950-0.879-0.087 0.8678-0.68357-0.06836 0.90909-0.000409 0. 0.83396-0.69549-0.06955 0.7644-0.58433-0.05843 0.833333-0.00069 0.3 0.76997-0.5986-0.0599 0.7069-0.50507-0.0505 0.7693-0.000740 0.4 0.7507-0.533-0.053 0.66394-0.4408-0.04408 0.7486-0.000789 0.5 0.66747-0.4455-0.04455 0.69-0.3880-0.03880 0.666667-0.00080 0.6 0.6579-0.396-0.0396 0.58663-0.3443-0.0344 0.65000-0.000790 0.7 0.58900-0.3469-0.03469 0.5543-0.3076-0.03073 0.58835-0.000768 0.8 0.5569-0.30946-0.03095 0.5535-0.7599-0.0760 0.555556-0.000738 0.9 0.570-0.7775-0.0778 0.4995-0.495-0.049 0.5636-0.000705 0.50067-0.5067-0.0507 0.47560-0.60-0.06 0.500000-0.00067
Runge-Kutta Method ( nd Order) Eample [b] The values are a 3, b, α, β 3 3 3 (, ) k hf i i ( α, β ) k hf + h + k i i + ak + bk i+ i
Runge-Kutta Method ( nd Order) Eample [b] The values are k Estimate Solution k Eact Error n n 'n h'n *n+ *' n+ h(*'n+ ) Eact 0.00000 -.00000-0.0000 0.85000-0.750-0.075.000000 0.000000 0. 0.9095-0.8674-0.0867 0.7854-0.6660-0.0666 0.90909-0.00059 0. 0.83358-0.69486-0.06949 0.7935-0.5395-0.0530 0.833333-0.00048 0.3 0.76953-0.597-0.059 0.68070-0.46335-0.04634 0.7693-0.00095 0.4 0.7460-0.5066-0.0507 0.63800-0.40705-0.04070 0.7486-0.00037 0.5 0.66699-0.44488-0.04449 0.6006-0.3603-0.03603 0.666667-0.00034 0.6 0.653-0.3903-0.0390 0.56667-0.3-0.03 0.65000-0.0003 0.7 0.58855-0.34639-0.03464 0.53659-0.8793-0.0879 0.58835-0.00034 0.8 0.55586-0.30898-0.03090 0.5095-0.5960-0.0596 0.555556-0.000303 0.9 0.566-0.773-0.0773 0.4850-0.353-0.035 0.5636-0.0009 0.5008-0.508-0.0503 0.4674-0.4-0.04 0.500000-0.00078
Runge-Kutta Methods Fourth order Runge-Kutta method n+ +/6(k n +k +k 3 +k 4 ) k hf(,) k h(f(+h/, +/ k ) k 3 h(f(+h/, +/ k ) k 4 h(f(+h,+k 3 ))
4th -order Runge-Kutta Method f f 4 f 3 f f f 3 + 6 ( f + f + f f ) 4 i i + h/ i + h
Volterra eample Write a function in standard form function f rabfo(t,) % Computes for the Volterra model. % () is the number of rabbits at time t. % () is the number of foes at time t. global alpha % interaction constant t % a print statement, just so we can see how fast % the progress is, and what stepsize is being used f(,) *() - alpha*()*(); f(,) -() + alpha*()*();
Stud its solution for various values of encounter % Run the rabbit-fo model for various values of % the encounter parameter alpha, plotting each % solution. global alpha for i:-:0, alpha 0^(-i) [t,] ode45('rabfo',[0:.:], [0,0]); plot(t,(:,),'r',t,(:,),'b'); legend('rabbits','foes') title(sprintf('alpha %f',alpha)); pause end
Runge-Kutta Method (4 th Order) Eample Consider Eact Solution d d The initial condition is: The step size is: h 0. + + e ( 0 )
The 4 th Order Runge-Kutta The eample of a single step: k k k k 3 4 h h f h f h (, ) [ ] ( ) ( f 0.f 0, 0. 0 ) ( 0.05,.05) ( 0.05,. + k / ) [ f ( + h, + k )] 0.f ( 0.,.04988) 6 + + h, h, 0. [ k + k + k + ]. 0489 n+ n + 3 k4 + + 3 k k 0.f 0. f 0.0475 0.09499 0.04988
Runge-Kutta Method (4 th Order) Eample The values for the 4 th order Runge-Kutta method f(,) k f k f 3 k 3 f 4 k 4 Change Eact 0 0..0475 0.0475.049875 0.04988.094988 0.09499 0.68974 0..0489.09489 0.09483.3707 0.3707.398 0.398.78747 0.7875 0.68608.0489 0..8597.78597 0.786.507 0.503.6848 0.685.508 0.508 0.7963.8597 0.3.3404.504 0.504.8048 0.805.8648 0.865.308306 0.3083 0.76804.3404 0.4.46875.30875 0.3087.33084 0.3308.339 0.333.35398 0.354 0.7986.46875 0.5.6078.3578 0.358.36634 0.36634.367095 0.367.377988 0.37799 0.8964.6079 0.6.73788.37788 0.37788.38474 0.3847.384594 0.38459.38634 0.38634 0.83096.73788 0.7.87646.38646 0.3865.383059 0.38306.38899 0.389.374536 0.37454 0.897.87647 0.8.04458.374458 0.37446.36068 0.36068.35999 0.35999.340457 0.34046 0.8566.04459 0.9.50396.340396 0.3404.3495 0.349.3364 0.3364.876 0.876 0.78797.50397.877.877 0.87.43303 0.433.438 0.438.95855 0.9586 0.744694.878
The 4 th Order Runge-Kutta The step sizes are: [ ] [ ] 4 3 3 3 3 k k k k h k k k + + + + + ( ) ( ) ( ) ( ) ( ) h h h + + + + + The net step would be:
Eplicit Methods Up until this point we have dealt with: Euler Method Modified Euler/Midpoint Runge-Kutta Methods These methods are called eplicit methods, because the use onl the information from previous steps. Moreover these are one-step methods
One Step Method The techniques are defined as: These methods allow us to var the step size. Use onl one initial value. After each step is completed the past step is forgotten: We do not use this information.
Multi-Step Methods The principle behind a multi-step method is to use past values, and/or d/d to construct a polnomial that approimate the derivative function.
Multi-Step Methods Similar to quadrature d d d f f ( ) ( ) d i + + + i i i f ( ) d d i+ i i+ i f ( ) d
Multi-Step Methods The integral can be represented. i + i h f Two Point i i f ( ) d [ 3 f ] Three Point Adam Bashforth h + [ 3 f 6 f 5 f ] i i i
Multi-Step Methods The integral can be represented. i + i f ( ) d Four Point Adam Bashforth h + 4 [ 55 f 59 f 37 f 9 f ] i i i i 3
Multi-Step Methods These methods are known as eplicit schemes because the use of current and past values are used to obtain the future step. The method is initiated b using either a set of known results or from the results of a Runge-Kutta to start the initial value problem.
Adam Bashforth Method (4 Point) Eample Consider Eact Solution d d The initial condition is: The step size is: h 0. + + e ( 0 )
4 Point Adam Bashforth From the 4th order Runge Kutta f 0,.0000 ( ) ( 0.,.0489) ( 0.,.8597) ( 0.3,.3404). 504 The 4 Point Adam Bashforth is: f f f.09489.78597 0. 4 [ 55 f 59 f + 37 f f ] 9 0.3 0. 0. 0
4 Point Adam Bashforth The results are: Upgrade the values f ( 0.4).3404+ ( 0.4,.46879). 30879 ( ) 59(.78597) 0. 55.504 4 + 37.09489 0.8038 ( ) 9( ) 0.8038.46879
4 Point Adam Bashforth Method - Eample The values for the Adam Bashforth Adam Bashforth f(,) sum 4th order Runge-Kutta Eact 0 0..0488958.09489.0488958.0489 0..859699.78597.859699.8597 0.3.340408.504 30.799.340408.3404 0.4.468796.30879 3.9467.46874786.46875 0.5.608865.3588 3.786.6078076.6079 0.6.73789699.377897 33.0969.737880409.73788 0.7.876707.3867 33.730.87646365.87647 0.8.044964.37449 3.6766.04458009.04459 0.9.5044005.34044 3.505.50395695.50397.87746.8774 9.7936.87685.878
4 Point Adam Bashforth Method - Eample The eplicit Adam Bashforth method gave solution gives good results without having to go through large number of calculations. Y Value 4 0 - -4-6 -8 4 Point Adam Bashforth Eample 0 3 4 Adam Bashforth 4th order Runge-Kutta Eact -0 X Value
Implicit Methods There are second set of multi-step methods, which are known as implicit methods. The implicit methods use the future steps to modif the future steps. Since future data is used an iterative method must be used iterate an initial guess until convergence Could use Runge-Kutta or Adams Bashforth to start the initial value problem.
Implicit Multi-Step Methods The main method is Adams Moulton Method Three Point Adams-Moulton Method h 5 + 8 [ f f f ] i+ i i Four Point Adams-Moulton Method h 9 + 9 5 + 4 [ f f f f ] i+ i i i
Implicit Multi-Step Methods The method uses what is known as a Predictor-Corrector technique. eplicit scheme to estimate the initial guess uses the value to guess the future * and d/d f*(,*) Using these results, appl Adam Moulton method
Implicit Multi-Step Methods Adams third order Predictor-Corrector scheme. Use the Adam Bashforth three point eplicit scheme for the initial guess. h * [ ] i+ i + 3 fi 6 fi + 5 fi Use the Adam Moulton three point implicit scheme to take a second step. h [ ] * i+ i + 5 fi+ + 8 fi fi
Adam Moulton Method (3 point) Eample Consider Eact Solution d d The initial condition is: The step size is: h 0. + + e ( 0 )
4 Point Adam Bashforth From the 4th order Runge Kutta f f f ( 0,).0000 ( 0.,.0489).09489 ( 0.,.8597). 78597 The 3 Point Adam Bashforth is: 0. + [ 3 f 6 f f ] 5 0. 0. 0.0
3 Point Adam Moulton Predictor-Corrector Method The results of eplicit scheme is: 0. 3.78597 0.587 The functional values are: f * * ( 0.3) ( 0.3,.34084). 5084 [ ( ) 6(.09489) + 5( ) ].8597 + 0.587.34084
3 Point Adam Moulton Predictor-Corrector Method The results of implicit scheme is: 0. 5.5084 0.54 The functional values are: f ( 0.3) ( 0.3,.34084). 5038 [ ( ) + 8(.78597).09489 ( )].8597 + 0.54.34038
3 Point Adam Moulton Predictor-Corrector Method The values for the Adam Moulton Adam Moulton Three Point Predictor-Corrector Scheme f sum * f* sum 0 0..0489.09489 0..8597.78597 0.587.34084.5084 0.54 0.3.34038.5038 0.808.4689.3089 0.803 0.4.46868.30868 0.3355.6033.3533 0.33098 0.5.6066.3566 0.36659.73795.37795 0.36597 0.6.737863.377863 0.3849.8769.3869 0.38359 0.7.876.386 0.388.0450.37450 0.3804 0.8.0445.37445 0.3603.50438.340438 0.3598 0.9.50353.340353 0.3404.8757.8757 0.33.8663.8663 0.406.405869.95869 0.40
3 Point Adam Moulton Predictor-Corrector Method The implicit Adam Moulton method gave solution gives good results without using more than a three points. Y Value 4 0 - -4-6 Adam Moulton 3 Point Implicit Scheme 0 3 4 4th order Runge-Kutta Eact Adam Moulton -8 Adam Bashforth -0 X Value