14/15 Semester 5 Computational Method in Chemical Engineering (TKK-2109) Instructor: Rama Oktavian Email: rama.oktavian@ub.ac.id Office Hr.: M.13-15, T. 13-15, W. 13-15, F. 13-15 Ordinary Differential Equation Differential equation An equation relating a dependent variable to one or more independent variables by means of its differential coefficients with respect to the independent variables is called a “differential equation”. d 3 y dy 2 x ( ) 4 y 4 e cos x 3 dx dx Ordinary differential equation -------only one independent variable involved: x T 2T 2T 2T Partial differential equation --------------C p k ( 2 2 2 ) more than one independent variable involved: x, y, z, x y z Ordinary Differential Equation Differential equation Ordinary differential equations are classified in terms of order and degree Order of an ordinary differential equation is the same as the highest order derivative The degree of a differential equation is the highest power of the highest order differential coefficient that the equation contains after it has been rationalized. Ordinary Differential Equation Differential equation Ordinary differential equations are classified in terms of order and degree 3rd order O.D.E. 1st degree O.D.E. 1st order O.D.E. 2nd degree O.D.E. Ordinary Differential Equation Linear or non-linear Differential equations are said to be non-linear if any products exist between the dependent variable and its derivatives, or between the derivatives themselves. d 3 y dy 2 x ( ) 4 y 4 e cos x 3 dx dx Product between two derivatives ---- non-linear dy 4 y 2 cos x dx Product between the dependent variable themselves ---- non-linear Ordinary Differential Equation Swinging pendulum d 2 g sin 0 2 dt l A second-order nonlinear ODE. Falling parachutist problem Ordinary Differential Equation Differential equation Ordinary differential equations are classified in terms of order and degree 3rd order O.D.E. 1st degree O.D.E. 1st order O.D.E. 2nd degree O.D.E. Ordinary Differential Equation ODE in chemical engineering Illustrative Example: A Blending Process An unsteady-state mass balance for the blending system: rate of accumulation rate of rate of of mass in the tank mass in mass out (2-1) Ordinary Differential Equation ODE in chemical engineering d Vρ or w1 w2 w dt (2-2) where w1, w2, and w are mass flow rates. The unsteady-state component balance is: d Vρx dt w1x1 w2 x2 wx (2-3) For constant , Eqs. 2-2 and 2-3 become: dV w1 w2 w dt d Vx dt w1x1 w2 x2 wx (2-12) (2-13) Ordinary Differential Equation ODE in chemical engineering Equation 2-13 can be simplified by expanding the accumulation term using the “chain rule” for differentiation of a product: d Vx dt dx dV V x dt dt (2-14) Substitution of (2-14) into (2-13) gives: dx dV V x w1x1 w2 x2 wx (2-15) dt dt Substitution of the mass balance in (2-12) for dV/dt in (2-15) gives: dx V x w1 w2 w w1x1 w2 x2 wx dt (2-16) Ordinary Differential Equation ODE in chemical engineering After canceling common terms and rearranging (2-12) and (2-16), a more convenient model form is obtained: dV 1 w1 w2 w dt w2 dx w1 x x 1 x2 x dt V V (2-17) (2-18) Ordinary Differential Equation ODE in chemical engineering Ordinary Differential Equation Numerical method for solving ODE Euler’s method y dy f x, y , y 0 y 0 dx Slope Rise Run y1 y0 x1 x0 True value Φ x0,y0 y1, Predicted value Step size, h f x0 , y 0 y1 y0 f x0 , y0 x1 x0 y0 f x0 , y0 h x Figure 1 Graphical interpretation of the first step of Euler’s method http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Euler’s method y yi 1 yi f xi , yi h True Value h xi 1 xi yi+1, Predicted value Φ yi h Step size xi xi+1 x Figure 2. General graphical interpretation of Euler’s method http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Euler’s method How does one write a first order differential equation in the form of dy f x, y dx Example dy 2 y 1.3e x , y 0 5 dx is rewritten as dy 1.3e x 2 y, y 0 5 dx In this case f x, y 1.3e x 2 y http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Euler’s method Example The concentration of salt, x in a home made soap maker is given as a function of time by dx 37.5 3.5 x dt At the initial time, t = 0, the salt concentration in the tank is 50g/L. Using Euler’s method and a step size of h = 1.5 min, what is the salt concentration after 3 minutes. dx 37.5 3.5 x dt f t , x 37.5 3.5x xi 1 xi f t i , xi h Ordinary Differential Equation Numerical method for solving ODE Euler’s method For i 0, t0 0, x0 50 Step 1: Example x1 x0 f t0 , x0 h 50 f 0,501.5 50 37.5 3.5501.5 50 137.501.5 156.25 g / L x1 is the approximate concentration of salt at t t1 t0 h 0 1.5 1.5 min x1.5 x1 156.25g / L Ordinary Differential Equation Numerical method for solving ODE Euler’s method Example For i 1, t1 1.5, x1 156.25 Step 2: x2 x1 f t1 , x1 h 156.25 f 1.5,156.251.5 156.25 37.5 3.5 156.251.5 156.25 584.381.5 720.31g / L x 2 is the approximate concentration of salt at t t2 t1 h 15. 1.5 3 min x3 x2 720.31g / L Ordinary Differential Equation Numerical method for solving ODE The exact solution of the ordinary differential equation is given by xt 10.714 39.286e 3.5 x The solution to this nonlinear equation at t=3 minutes is x3 10.715 g/L Ordinary Differential Equation Numerical method for solving ODE Figure 3. Comparing exact and Euler’s method Ordinary Differential Equation Numerical method for solving ODE Table 1. Concentration of salt at 3 minutes as a function of step size, h h Step 3 1.5 0.75 0.375 0.1875 x3 Et |t | % −362.50 720.31 284.65 10.718 10.714 373.22 −709.60 −273.93 −0.0024912 0.0010803 3483.0 6622.2 2556.5 0.023249 0.010082 Ordinary Differential Equation Numerical method for solving ODE Figure 4. Comparison of Euler’s method with exact solution for different step sizes Ordinary Differential Equation Numerical method for solving ODE Runge Kutta 2nd order method Taylor’s expansion http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Runge Kutta 2nd order method Taylor’s expansion http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Runge Kutta 2nd order method However, it is relatively difficult to find second derivative of ODE For dy f ( x, y ), y (0) y0 dx Runge Kutta 2nd order method is given by yi 1 yi a1k1 a2 k2 h where k1 f xi , yi k2 f xi p1h, yi q11k1h http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Heun’s method Slope f xi h, yi k1h y Here a2=1/2 is chosen 1 a1 2 p1 1 Slope f xi , yi q11 1 resulting in 1 1 yi 1 yi k1 k2 h 2 2 where k1 f xi , yi yi+1, predicted Average Slope yi xi 1 f xi h, yi k1h f xi , yi 2 xi+1 x Figure 1 Runge-Kutta 2nd order method (Heun’s method) k 2 f xi h, yi k1h http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Midpoint Method Here a2 1 is chosen, giving a1 0 p1 1 2 q11 1 2 resulting in yi 1 yi k2h where k1 f xi , yi 1 1 k 2 f xi h, yi k1h 2 2 http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Ralston’s Method Here a 2 2 is chosen, giving 3 1 3 3 p1 4 3 q11 4 resulting in a1 2 1 yi 1 yi k1 k 2 h 3 3 where k1 f xi , yi 3 3 k 2 f xi h, yi k1h 4 4 http://numericalmethods.eng.usf.edu Ordinary Differential Equation Example The concentration of salt, x in a home made soap maker is given as a function of time by dx 37.5 3.5 x dt At the initial time, t = 0, the salt concentration in the tank is 50g/L. Using Euler’s method and a step size of h=1.5 min, what is the salt concentration after 3 minutes. dx 37.5 3.5 x dt f t , x 37.5 3.5x 1 1 xi 1 xi k1 k 2 h 2 2 http://numericalmethods.eng.usf.edu Solution Step 1: i 0, t0 0, x0 50 k1 f t0 , xo f 0,50 37.5 3.550 137.50 k 2 f t0 h, x0 k1h f 0 1.5,50 137.501.5 f 1.5,156.25 37.5 3.5 156.25 584.38 1 1 x1 x0 k1 k 2 h 2 2 1 1 50 137.50 584.381.5 2 2 50 223.44 1.5 385.16 g / L x1 is the approximate concentration of salt at t t t h 0 1.5 1.5 min 1 0 x1.5 x1 385.16 g/L http://numericalmethods.eng.usf.edu Solution Step 2: i 1, t1 t 0 h 0 1.5 1.5, x1 385.16 g / L k1 f t1 , x1 f 1.5,385.16 37.5 3.5385.16 1310.5 k 2 f t1 h, x1 k1h f 1.5 1.5,385.16 1310.51.5 f 3,1580.6 37.5 3.5 1580.6 5569.8 1 1 x2 x1 k1 k 2 h 2 2 1 1 385.16 1310.5 5569.81.5 2 2 385.16 2129.6 1.5 x1 is the approximate concentration of 3579.7 g / L salt at t t2 t1 h 1.5 1.5 3 min x3 x1 3579.7 g/L http://numericalmethods.eng.usf.edu Solution Table 1. Effect of step size for Heun’s method Step size, h 3 1.5 0.75 0.375 0.1875 x3 |t | % Et 1803.1 −1792.4 16727 3579.6 −3568.9 33306 442.05 −431.34 4025.4 11.038 −0.32231 3.0079 10.718 −0.0024979 0.023311 x(3) 10.715 (exact) http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Runge Kutta 4th order method Taylor’s expansion http://numericalmethods.eng.usf.edu Ordinary Differential Equation Numerical method for solving ODE Runge Kutta 4th order method However, it is relatively difficult to find second and third derivative of ODE For dy f ( x, y ), y (0) y0 dx Runge Kutta 4th order method is given by http://numericalmethods.eng.usf.edu Ordinary Differential Equation Example The concentration of salt, x in a home made soap maker is given as a function of time by dx 37.5 3.5 x dt At the initial time, t = 0, the salt concentration in the tank is 50g/L. Using Euler’s method and a step size of h=1.5 min, what is the salt concentration after 3 minutes. dx 37.5 3.5 x dt f t , x 37.5 3.5x http://numericalmethods.eng.usf.edu Solution Step 1: i 0, t0 0, x0 50 g / L k1 f t0 , x0 f 0, 50 37.5 3.550 137.5 1 1 1 1 k 2 f t0 h, x0 k1h f 0 1.5, 50 137.51.5 2 2 2 2 f 0.75, 53.125 37.5 3.5 53.125 223.44 1 1 1 k3 f t0 k 2 h f 0 1.5, 50 223.44 1.5 2 2 2 f 0.75, 217.58 37.5 3.5217.58 724.02 k 4 t0 h, x0 k3h f 0 1.5, 50 724.031.5 f 1.5, 1036.0 37.5 3.51036.0 3663.6 http://numericalmethods.eng.usf.edu Solution 1 k1 2k2 2k3 k4 h 6 1 50 137.5 2223.44 2 724.02 3663.6 1.5 6 1 50 2525.01.5 6 681.24 g/L x1 x0 x1 is the approximate concentration of salt at t t1 t0 h 0 1.5 1.5 x1.5 x1 681.24 g / L http://numericalmethods.eng.usf.edu Solution Step 2: i 1, t1 1.5, x1 681.24 g / L k1 f t1 , x1 f 1.5, 681.24 37.5 3.5681.24 2346.8 1 1 1 1 k 2 f t1 h, x1 k1h f 1.5 1.5,681.24 2346.81.5 2 2 2 2 f 2.25,1078.9 37.5 3.5 1078.9 38.13.6 1 1 1 1 k3 f t1 h, x1 k 2 h f 1.5 1.5, 681.24 3813.6 1.5 2 2 2 2 f 2.25, 3541.4 37.5 3.53541.4 12358 k 4 f t1 h, x1 k3h f 1.5 1.5, 681.24 123581.5 f 3,17855 37.5 3.5 17855 62530 http://numericalmethods.eng.usf.edu Solution 1 x2 x1 k1 2k 2 2k3 k 4 h 6 1 681.24 2346.8 23813.6 2 12358 625301.5 6 1 681.24 430961.5 6 11455 g/L x 2 is the approximate concentration of salt at t2 t1 h 1.5 1.5 3 min . x3 x2 11455g / L http://numericalmethods.eng.usf.edu Solution Table 1 Value of concentration of salt at 3 minutes for different step sizes Step size, h x3 Et |t | % 3 1.5 0.75 0.375 0.1875 14120 11455 25.559 10.717 10.715 −14109 −11444 −14.843 −0.0014969 −0.00031657 131680 106800 138.53 0.013969 0.0029544 x(3) 10.715 (exact) http://numericalmethods.eng.usf.edu