Iniial Value Problems ChEn 2450 d d f(, ) (0) 0 6 ODE.key - November 26, 2014
Example - Cooking a Lobser Assumpions: The lobser remains a a uniform emperaure. This implies ha he hermal conduciviy of he lobser is large. This is likely a poor assumpion! The lobser is a cylinder wih lengh L and radius r. The lobser s mass remains consan wih ime (reasonable assumpion) The hea capaciy of he lobser is approximaely ha of waer (quesionable, bu reasonable assumpion). Wha is he emperaure of he lobser afer 3 minues? A 2 rl + 2 r2 L 0.3 m r 0.1 m m 1 kg cp 4200 J kg K Boiling i in waer Baking i in he oven (convecive hea ransfer) (radiaive hea ransfer) dt d ha (T mcp h 500 dt d T ) J m2 1 s Exac soluion: ha T T1 + (T0 T1 ) exp mcp A 4 (T mcp 5.6704 10 T4 ) 8 J m2 K s Exac soluion: (requires soluion of a nonlinear equaion) an 1 T T1 7 + an 1 T T1 an 1 T0 T1 + anh 1 T0 T1 3 + 2 T1 ODE.key - November 26, 2014
Explici Time Inegraion Forward Euler Single ODE: Iniial condiion: d d f(, ) (0) 0 Firs order forward-difference approximaion: d d n n+1 n+1 n n + + O( ) d d n In words: ϕn+1 is approximaed using he slope of he funcion a he previous ime sep. Forward Euler Δ +Δ n + f( n, Forward Euler n ) Why explici? Because all informaion is explicily known o move soluion forward. Wha happens as we decrease? Forward Euler Algorihm: Given ϕn, n, end,, f(,ϕ): 1. Se n+1+. 2. Calculae ϕn+1. (requires calcluaion of f(n,ϕn) ) 3. Se nn+1, ϕn ϕn+1 4. If n<end, reurn o sep 1. 5. Reurn ϕn. 8 ODE.key - November 26, 2014
Example - Lobsers Again... In waer (convecive hea ransfer) dt d ha mc p (T T ) funcion rhs lobser_convecion(, T ) % The ime-change of emperaure of a lobser pu in % boiling waer, assuming ha he emperaure of he % lobser is spaially uniform. In hea ransfer, you % will learn ha his is called a "lumped" analysis. Twaer 373.15; % emperaure of boiling waer (K) m 1.0; % lobser's mass (kg) cp 4200; % lobser's hea capaciy. h 500; % hea ransfer coefficien (W/(m2 K)) L 0.3; % lengh (m) r 0.1; % radius (m) % area, assuming ha he lobser is a cylinder. A 2*pi*r*L + 2*pi*r^2; rhs -h*a/(m*cp) * (T-Twaer); In he oven (radiaive hea ransfer) dt d A mc p (T 4 T 4 ) funcion rhs lobser_radiaion(, T ) % The ime-change of emperaure of a lobser pu in an oven, % assuming ha he emperaure of he lobser is spaially % uniform. In hea ransfer, you will learn ha his is % called a "lumped" analysis. Tinf 400; % oven emperaure, K sigma 5.6704e-8; % Sefan-Bolzmann consan, (J/(m2 K s)) emiss 1.0; % emissiviy (no unis) m 1.0; % lobser's mass (kg) cp 4200; % lobser's hea capaciy. L 0.3; % lengh (m) r 0.1; % radius (m) % area, assuming ha he lobser is a cylinder. A 2*pi*r*L + 2*pi*r^2; rhs -sigma*emiss*a/(m*cp) * (T^4-Tinf^4); 9 ODE.key - November 26, 2014
Sysems of ODEs Examples in Chemical Engineering: Kineics (muliple reacing species). Coupled processes (e.g. variable energy and composiion, ec). Ofen arise from discreizaion of PDEs Approach: use vecor of soluion variables, and a funcion which reurns he rhs as a vecor. d 1 d f 1 (, 1, 2,..., n), d 2 d f 2 (, 1, 2,..., n),. d n d f n (, 1, 2,..., n), d d F (, ) ( 0) 0 10 ODE.key - November 26, 2014
Example: A Falling Objec A 0, we release an objec a x0 and i sars falling o earh. Find x() and v(). A low Reynolds number, (ball in molasses) he drag force is proporional o v. A high Reynolds number (skydiver), he drag force is proporional o v 2. d 2 x d 2 g v d 2 x d 2 g v2 x(0) 0, x() g 2 dx d 0 0 Order reducion: wrie a second-order ODE as a sysem of firs-order ODEs! dx d v dv d g v [ 1 + exp ( )] v() g (1 exp( )) x(0) 0, dx d 0 0 analyic soluion sill possible, bu messy... Order reducion: dx d v dv d g v2 11 ODE.key - November 26, 2014
Implici Time Inegraion Backward Euler d d f(, ) d d n+1 Forward difference in ime Forward Euler (explici) Backward difference in ime Backward Euler (implici) n+1 n + O( ) Backward Euler n+1 n + d d n+1 n + f( n+1, n+1 ) Backward Euler Forward Euler Δ +Δ Problem: we don know f(ϕn+1,n+1) Implici If f(ϕn+1,n+1) is nonlinear in ϕ hen we mus solve a nonlinear equaion a each imesep. g( n+1 ) n+1 n f n+1, Repea he lobser example using backward Euler... n+1 Backward Euler Algorihm: Given ϕn, n, end,, f(,ϕ): 1. Guess ϕn+1. 2. Se n+1n+. 3. Solve g(ϕn+1)0 for ϕn+1 (nonlinear equaion) 4. Se nn+1, ϕn ϕn+1. 5. If n<end, reurn o sep 1. 6. Reurn ϕn. 12 ODE.key - November 26, 2014
Example dc d kc2 wih c(0) given Backward Euler c n+1 c n k(c n+1 ) 2 residual form g(c n+1 )(k )(c n+1 ) 2 + c n+1 c n analyic soluion c n+1 1 ± p 1+4k c n 2k numeric soluion g 0 2(k )c n+1 )+1 Newon updae c n+1 k+1 cn+1 k c n+1 k g(c n+1 k ) g 0 (c n+1 k ) k (c n+1 k ) 2 + c n+1 k 2k c n+1 k +1 k - ieraion couner n - ime level couner c n Ierae unil convergence - hen move on o nex ime level. 13 ODE.key - November 26, 2014
Example: Cyclical Sysems Change of heigh of car as a funcion of ime: dy d r sin( ) r - radius of ferris wheel ω - roaion rae (radians/ime) θ 14 ODE.key - November 26, 2014
Crank-Nicholson f( n, n ) f( n+1, n+1 ) n+1 n n+1 n Firs-order accurae in ime. Add 1/2 forward Euler + 1/2 backward Euler (average slope) n+1 n 1 2 f(n+1, n+1 ) + f( n, Second-order accurae in ime. n ) g( n+1 ) n+1 n 1 2 f(n+1, n+1 ) + f( n, n ) Forward Euler Crank Nicholson Δ Backward Euler +Δ Crank-Nicholson Algorihm: Given ϕn, n, end,, f(,ϕ): 1. Guess ϕn+1 ϕn. 2. Se n+1n+. 3. Solve g(ϕn+1)0 for ϕn+1 (nonlinear equaion) 4. Se nn+1, ϕn ϕn+1 5. If n<end, reurn o sep 1. 6. Reurn ϕn. 15 ODE.key - November 26, 2014
Time Inegraion wih Malab s Inegraors 1. Creae he RHS funcion in he form f(,φ). RHS funcion should produce a column vecor. 2. Deermine he ime(s) ha you wan he soluion Eiher [sar,end] or a vecor of specific imes. 3. Use he appropriae inegraor (ode45, ode15s): Funcion ode45 ode15s Descripion Explici ime inegraor. Try his firs. Bes for non-siff problems Implici ime inegraor. Use his for siff problems (when ode45 sruggles) [,phi] ode45( rhsfun, [0,end], phi0 ); [,phi] ode45( rhsfun, ps, phi0 ); [,phi] ode15s( rhsfun, [0,end], phi0 ); [,phi] ode15s( rhsfun, ps, phi0 ); 16 ODE.key - November 26, 2014
Example: A Sysem of ODEs Hypoheical reacion mechanism: A k 1! B 2B k 2! B + C B + C k 3! A + C k1 0.04 k2 3 10 7 k3 10 4 da d k 1A + k 3 BC db d k 1A k 2 B 2 k 3 BC dc d k 2B 2 Solve his using: Forward Euler Backward Euler ODE45 ODE15s 17 ODE.key - November 26, 2014