Introduction to Simuation - Lecture 12 for Ordinary Differentia Equations Jacob White Thanks to Deepak Ramaswamy, Jaime Peraire, Micha Rewienski, and Karen Veroy
Outine Initia Vaue probem exampes Signa propagation (circuits with capacitors). Space frame dynamics (struts and masses). Chemica reaction dynamics. Investigate the simpe finite-difference methods Forward-Euer, Backward-Euer, Trap Rue. Look at the approximations and agorithms Examine properties experimentay. Anayze Convergence for Forward-Euer
Appication Probems Signa Transmission in an Integrated Circuit Logic Gate Signa Wire Wire has resistance Wire and ground pane form a capacitor Ground Pane Logic Gate Meta Wires carry signas from gate to gate. How ong is the signa deayed?
Appication Probems Signa Transmission in an Integrated Circuit Circuit Mode resistor capacitor Cut the wire into sections. Mode wire resistance with resistors. Mode wire-pane capacitance with capacitors. Constructing the Mode
Appication Probems Osciations in a Space Frame What is the osciation ampitude?
Appication Probems Osciations in a Space Frame Simpified Structure Struts Bots Ground Load Exampe Simpified for Iustration
Appication Probems Osciations in a Space Frame Modeing with Struts, Joints and Point Masses Point Mass Strut Constructing the Mode Repace Meta Beams with Struts. Repace cargo with point mass.
Appication Probems Chemica Reaction Dynamics Crucibe Reagent Strange green stuff How fast is product produced? Does it expode?
i C1 Appication Probems v1 i v R2 2 i R1 i R3 C 1 R 2 R 1 R 3 C 2 Signa Transmission in an Integrated Circuit Constitutive Equations dvc ic = C dt 1 ir = vr R A 2x2 Exampe Noda Equations Yieds 2x2 System dv i C2 1 1 1 Conservation Laws i i i + + = 0 1 1 2 C R R i i i 1 + C1 0 dt R1 R2 R 2 v1 0 C = 2 dv2 1 1 1 v 2 + dt R2 R3 R 2 + = 0 2 3 2 C R R
Appication Probems Signa Transmission in an Integrated Circuit A 2x2 Exampe Let C = C = 1, R = R = 10, R = 1 dv1 1 1 1 + C1 0 dt R1 R2 R 2 v1 0 C = dv 1 1 1 v 2 2 2 + dt R2 R3 R 2 1 2 1 3 2 Eigenvaues and Eigenvectors eigenvectors dx 1.1 1.0 = dt 1.0 1.1 A 1 1 1 0.1 0 1 1 A = 1 1 0 2.1 1 1 Eigenvaues x
Eigendecomposition: An Aside on Eigenanaysis () Consider an ODE: dx t = Axt (), x(0) = x dt λ 0 0 A E E E E E 1 = 1 2 n 0 0 1 2 E n 0 0 λ n E 1 Change of variab e s : Ey( t) = xt ( ) yt ( ) = E xt ( ) dey() t Substituting: = AEy(), t Ey(0) = x0 dt λ 0 0 1 dy() t 1 1 Mutipy by E : = E AEy() t = 0 0 dt 0 0 λ n 0 yt () 1
An Aside on Eigenanaysis Continued From ast side: dy() t dt λ1 0 0 = 0 0 0 0 λ n yt () Decouped Equations! dyi () t λit Decouping: = λiyi() t yi() t = e y(0) dt () Steps for soving dx t = Axt (), x(0) = x0 dt 1) Determine E, λ 1 λ1t 2) Compute y(0) = E x e 0 0 0 3) Compute yt ( ) = 0 0 y(0) λnt 0 0 e 4) xt () = Eyt ()
Appication Probems Signa Transmission in an Integrated Circuit A 2x2 Exampe v 1(0) = 1 v 2(0) = 0 Notice two time scae behavior v 1 and v 2 come together quicky (fast eigenmode). v 1 and v 2 decay to zero sowy (sow eigenmode).
Appication Probems Struts, Joints and point mass exampe A 2x2 Exampe y = y0 + u Define v as veocity (du/dt) to yied a 2x2 System f s f m Constitutive Equations 2 du fm = M dt 2 y y EA 0 c fs = EAc = u y0 y0 dv EAc M 0 dt 0 v y 0 0 1 = du u 1 0 dt Conservation Law f s + f = m 0
Appication Probems Struts, Joints and point mass exampe A 2x2 Exampe Let M = 1, EA c = 1 y dv EAc M 0 dt 0 v y 0 0 1 = du u 1 0 dt 0 Eigenvaues and Eigenvectors 1 1 1 i 0 1 1 A = i i 0 i i i eigenvectors Eigenvaues dx 0 1.0 = x dt 1.0 0 A
0.5 1 v (0) = 1 Appication Probems Struts, Joints and point mass exampe A 2x2 Exampe -0.5 0 u (0) = 0-1 0 5 10 15 Note the system has imaginary eigenvaues Persistent Osciation Veocity, v, peaks when dispacement, u, is zero.
Appication Probems Amount of reactant Chemica Reaction Exampe A 2x2 Exampe = R, the temperature = T dt T R dt = + More reactant causes temperature to rise, higher temperatures increases heat dissipation causing temperature to fa dr R 4T dt = + Higher temperatures raises reaction rates, increased reactant interferes with reaction and sows rate.
Appication Probems Chemica Reaction Exampe A 2x2 Exampe dt dt 1 1 T dx 1 1 = dr 4 1 R = dt 4 1 dt A Eigenvaues and Eigenvectors 1 1 1 1 0 1 1 A = 2 2 0 3 2 2 eigenvectors Eigenvaues x
12 10 8 6 4 2 Appication Probems R (0) = 0 Chemica Reaction Exampe A 2x2 Exampe T (0) = 1 0 0 0.5 1 1.5 2 2.5 Note the system has a positive eigenvaue Soutions grow exponentiay with time.
First - Discretize Time Basic Concepts Second - Represent x(t) using vaues at t i ˆx 2 3 ˆx xˆ 4 ˆx x( t ) ˆx 1 0 t1 t2 t3 d xt dt Third - Approximate ( using ) the discrete tl t Approx. so n 1 + 1 ˆ ˆ ˆ ˆ d x x x x Exampe: xt ( ) or dt t t 0 t t1 t2 tl 1 + 1 t tl Exact so n xˆ 's = T
Basic Concepts Forward Euer Approximation x d sope = xt ( ) dt xt+ 1 xt sope = t t + 1 ( ) ( ) t t d xt ( 1) xt ( ) xt ( ) Axt + = ( ) dt t or xt ( ) xt ( ) + taxt ( ) + 1 = xt ( ) xt ( ) + taxt ( ) ( ) + 1
Basic Concepts Forward Euer Agorithm xt ( ) x = x(0) + tax 0 1 ˆ 1 ( ) x xt ( ˆ ˆ ˆ 2) x = x + tax 2 1 1 xt ( ) xˆ = xˆ + taxˆ L L L 1 L 1 1 taxˆ tax(0) t1 t2 t 3 t
x Finite Difference d sope = xt ( + 1) dt xt+ 1 xt sope = t t + 1 ( ) ( ) t t Basic Concepts Backward Euer Approximation d xt ( 1) xt ( ) xt ( 1) Axt + + = ( + 1) dt t or xt ( ) xt ( ) + taxt ( ) + 1 + 1 = xt ( ) xt ( ) + taxt ( ) ( ) + 1 + 1
Basic Concepts Backward Euer Agorithm Sove with Gaussian Eimination xt ( ˆ ˆ 1) x = x(0) + tax 1 1 I ta xˆ = x 1 [ ] (0) xt ( ˆ ˆ 2) x = [ I ta] x L xt ( ) xˆ = [ I ta] xˆ L 2 1 1 1 L 1 2 taxˆ 1 taxˆ x t1 t2 t
1 d d ( xt ( + 1 ) + xt ( )) 2 dt dt 1 = ( Ax ( t+ 1 ) + Ax ( t )) 2 xt ( + 1) xt ( ) t 1 xt ( + 1) xt ( ) + taxt ( ( + 1) + xt ( )) 2 Basic Concepts x Trapezoida Rue d sope = xt ( ) dt d sope = xt ( + 1) dt xt+ 1 xt sope = ( ) ( ) t t 1 1 = (( xt+ 1) taxt ()) (() xt + taxt ( + 1)) 2 2
Basic Concepts Trapezoida Rue Agorithm Sove with Gaussian Eimination t x( t1) xˆ = x(0) + Ax(0) + Axˆ 2 t t I A x = I + A x 2 2 ( ) 1 1 1 ˆ (0) x 1 2 t t 1 xt ( 2) xˆ = I 2 A I+ 2 A xˆ 1 L ( ) ˆ t t xtl x = I A I+ A xˆ 2 2 L 1 t1 t2 t
Basic Concepts Numerica Integration View d xt xt xt t A d dt + 1 () = A xt ( ) ( + 1) = ( ) + x ( τ ) t t t + 1 Ax( τ ) dτ t 2 ( ) tax( t + 1) tax( t ) τ Ax( t) + Axt ( ) Trap BE FE t t + 1
Basic Concepts Summary Trap Rue, Forward-Euer, Backward-Euer Are a one-step methods 1 2 3 xˆ is computed using ony xˆ, not xˆ, xˆ, etc. Forward-Euer is simpest No equation soution expicit method. Boxcar approximation to integra Backward-Euer is more expensive Equation soution each step impicit method Trapezoida Rue might be more accurate Equation soution each step impicit method Trapezoida approximation to integra
4 Numerica Experiments Unstabe Reaction 3.5 3 2.5 t = 0.1 Backward-Euer Exact Soution 2 1.5 1 Trap rue Forward-Euer 0.5 0 0.5 1 1.5 2 FE and BE resuts have arger errors than Trap Rue, and the errors grow with time.
Numerica Experiments Unstabe Reaction-Error Pots 0 0.4 6 x 10-3 -0.05-0.1-0.15-0.2-0.25 Forward Euer 0.35 0.3 0.25 0.2 0.15 0.1 Backward Euer 5 4 3 2 1 0 Trap Rue -0.3 0.05-1 -0.35 0 1 2 0 0 1 2-2 0 1 2 A methods have errors which grow exponentiay
M ax Finite Difference 10 2 10 0 Backward-Euer Numerica Experiments Unstabe Reaction-Convergence 10-2 E rr 10-4 Trap rue Forward-Euer o r 10-6 10-8 Timestep 10-3 10-2 10-1 10 0 For FE and BE, Error t For Trap, Error ( t) 2
4 2 t = 0.1 Numerica Experiments Osciating Strut and Mass Forward-Euer 0-2 -4-6 0 5 10 15 20 25 30 Why does FE resut grow, BE resut decay and the Trap rue preserve osciations Trap rue Backward-Euer
Numerica Experiments Two timescae RC Circuit sma t Backward-Euer Computed Soution arge t With Backward-Euer it is easy to use sma timesteps for the fast dynamics and then switch to arge timesteps for the sow decay
Numerica Experiments Two timescae RC Circuit Forward-Euer Computed Soution The Forward-Euer is accurate for sma timesteps, but goes unstabe when the timestep is enarged
Convergence Numerica Experiments Summary Did the computed soution approach the exact soution? Why did the trap rue approach faster than BE or FE? Energy Preservation Why did BE produce a decaying osciation? Why did FE produce a growing osciation? Why did trap rue maintain osciation ampitude? Two timeconstant (stiff) probems Why did FE go unstabe when the timestep increased? We wi focus on convergence today
Convergence Anaysis Convergence Definition Definition: A finite-difference method for soving initia vaue probems on [0,T] is said to be convergent if given any A and any initia condition T 0, t ( ) max xˆ x t 0 as t 0 xˆ computed with t t xˆ computed with 2 x exact
Convergence Anaysis Order-p convergence Definition: A finite-difference method for soving initia vaue probems on [0,T] is said to be order p convergent if given any A and any initia condition max T 0, t for a t ess than a given ( ) ( ) xˆ x t C t t Forward- and Backward-Euer are order 1 convergent Trapezoida Rue is order 2 convergent 0 p
Convergence Anaysis Two Conditions for Convergence 1) Loca Condition: One step errors are sma (consistency) Typicay verified using Tayor Series 2) Goba Condition: The singe step errors do not grow too quicky (stabiity) A one-step methods are stabe in this sense.
Convergence Anaysis Consistency Definition Definition: A one-step method for soving initia vaue probems on an interva [0,T] is said to be consistent if for any A and any initia condition 1 ˆ ( ) x x t t 0 as t 0
Convergence Anaysis Consistency for Forward Euer Forward-Euer definition xˆ 1 = x 0 + tax 0 τ [ 0, t ] ( ) ( ) Expanding in t about zero yieds 2 2 dx 0 t d x x( t) = x( 0) + t + dt 2 dt ( ) ( ) ( ) d Noting that x (0) = Ax (0) and subtracting dt 2 2 τ ˆ 1 x x t ( ) t ( ) ( ) 2 d x dt 2 2 τ Proves the theorem if derivatives of x are bounded
Forward-Euer definition xˆ + = xˆ + taxˆ 1 Convergence Anaysis Convergence Anaysis for Forward Euer Expanding in t about t yieds (( 1) ) ( ) ( ) x + t = x t + tax t + e where e is the "one-step" error bounded by ( ) 2 e C t, where C = 0.5 max 2 d x τ [0, T ] 2 dt τ ( )
Convergence Anaysis Convergence Anaysis for Forward Euer Continued Subtracting the previous side equations ( ) (( 1) ) ( ) ˆ ( ) xˆ + x + t = I + ta x x t + e 1 Define the "Goba" error E + = I + ta E + e ( ) 1 ˆ ( ) E x x t Taking norms and using the bound on + 1 E I + ta E + C t ( ) ( ) ( ) 1 t A E C( t) + + 2 2 e
Convergence Anaysis A hepfu bound on difference equations A emma bounding difference equation soutions ( ) + 1 0 If u 1 + ε u + b, u = 0, ε > 0 Then u e ε ε b To prove, first write u as a power series and sum 1 1 ( 1+ ε ) ( 1 ) j u + ε b = b 1 ( 1 ε ) j= 0 + j
Convergence Anaysis A hepfu bound on difference equations cont. ε To finish, note (1 + ε) e (1 + ε) Mapping the goba error equation to the emma + 1 E 1+ t A E + C ( t )2 ε b ( ε) ( ) j ( ε) 1 1+ 1+ 1 e u b = b b 1 1+ j e ε ε ε ε ε
max C [ 0, L] A Convergence Anaysis Back to Forward Euer Convergence anaysis. Appying the emma and canceing terms 1 E 1+ t A E + C ( t )2 ε b Finay noting that t T, C( t) 2 AT E e t t A e t A
Convergence Anaysis Observations about the forward-euer anaysis. max C AT [ 0, L] E e t A forward-euer is order 1 convergent The bound grows exponentiay with time interva C is reated to the soution second derivative The bound grows exponentiay fast with norm(a).
12 Convergence Anaysis Exact and forward-euer(fe) Pots for Unstabe Reaction. 10 8 6 4 2 Texact Rexact RFE TFE 0 0 0.5 1 1.5 2 2.5 Forward-Euer Errors appear to grow with time
E r r o r 1.2 1 0.8 0.6 0.4 0.2 0-0.2 0 0.5 1 1.5 2 2.5 Rexact-RFE Time Convergence Anaysis forward-euer errors for soving reaction equation. Texact - TFE Note error grows exponentiay with time, as bound predicts
1 Convergence Anaysis Exact and forward-euer(fe) Pots for Circuit. 0.8 v1fe 0.6 v1exact 0.4 v2fe 0.2 0 0 0.5 1 1.5 2 2.5 3 3.5 4 Forward-Euer Errors don t aways grow with time v2exact
E r r o r Finite Difference 0.03 0.02 0.01 0-0.01 v1exact - v1fe Convergence Anaysis forward-euer errors for soving circuit equation. -0.02 v2exact-v2fe -0.03 0 0.5 1 1.5 2 2.5 3 3.5 4 Time Error does not aways grow exponentiay with time! Bound is conservative
Summary Initia Vaue probem exampes Signa propagation (two time scaes). Space frame dynamics (osciator). Chemica reaction dynamics (unstabe system). Looked at the simpe finite-difference methods Forward-Euer, Backward-Euer, Trap Rue. Look at the approximations and agorithms Experiments generated many questions Anayzed Convergence for Forward-Euer Many more questions to answer, some next time