State Variables and Linear Time-Invariant Systems CEE 541. Structural Dynamics Department of Civil and Environmental Engineering Duke University Henri P. Gavin Fall 2014 1 Linearity and Time Invariance A system G that maps an input u(t) to an ouput y(t) is a linear system if and only if (α1 y1 (t) + α2 y2 (t)) = G[α1 u1 (t) + α2 u2 (t)] (1) where y1 = G[u1 ], y2 = G[u2 ] and α1 and α2 are scalar constants. A system G that maps an input u(t) to an ouput y(t) is a time-invariant system if and only if y(t − to ) = G[u(t − to )] . (2) Systems described by ẋ(t) = Ax(t) + Bu(t) , x(0) = xo y(t) = Cx(t) + Du(t) (4) are linear and time-invariant. variable x u y A B C D description state vector input vector output vector dynamics matrix input matrix output matrix feedthrough matrix (3) dimension n by 1 r by 1 m by 1 n by n n by r m by n m by r 2 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin 2 Example: a spring-mass-damper oscillator An externally-forced spring-mass-damper oscillator is described by mr̈(t) + cṙ(t) + kr(t) = f (t) , r(0) = do , ṙ(0) = vo . (5) Assuming a solution of the form r(t) = r̄eλt , (mλ2 + cλ + k)r̄ = 0 . This equation is valid for r̄ = 0, the trivial solution, and v u u c2 c k λ=− ±t − 2m 4m m Note that λ can be complex, λ = σ ± ıω. Now, defining the natural frequency √ ωn2 = k/m, and the damping ratio ζ = c/(2 mk), we find c/(2m) = ζωn , so, q λ = −ζωn ± ζ 2 ωn2 − ωn2 q = −ζωn ± ωn ζ 2 − 1 (6) and if ζ < 1, the root may be written q λ = −ζωn ± ıωn 1 − ζ 2 . (ı = √ −1) Note that if ζ > 0 then σ < 0 and the system is stable. The second-order ordinary differential equation (5) may be written as two first-order ordinary differential equations, by defining a state vector of the position and velocity, x = [r ṙ]T . d r dt ṙ = 0 1 −k/m −c/m r ṙ + 0 f (t) , 1/m r(0) ṙ(0) = do vo (7) In terms of a desired response from this system, we may be interested in the force on the foundation, fF , and the acceleration of the mass, both of which can be computed directly through a linear combination of the states and the input. f k c r 0 F = + f (t) (8) r̈ −k/m −c/m ṙ 1/m CC BY-NC-ND H.P. Gavin 3 Linear Time Invariant Systems A single degree of freedom oscillator as well as many other types of dynamical systems may be described in a general sense using state variable descriptions, ẋ(t) = Ax(t) + Bu(t) , x(0) = xo y(t) = Cx(t) + Du(t) . 3 Free Response If u(t) = 0, then the free response y(t) of the system to initial conditions xo is y(t) = CeAt xo , (9) where eAt is called a matrix exponential. In Matlab, y(:,p)=C*expm(A*t(p))*xo; 4 Unit Impulse Response Function If xo = 0 and the input is a unit impulse, u(t) = Im δ(t), the responses y(t) of the system are called the unit impulse response function, H(t), H(t) = CeAt B . (10) The set of free responses is richer than the set of unit impulse responses. In Matlab, H(p,:,:)=C*expm(A*t(p))*B; 5 Forced Response The forced response of a linear time invariant system is y(t) = CeAt xo + C Z t eA(t−τ ) 0 Bu(τ ) dτ + Du(t). (11) An efficient method for computing y(t) for a arbitrary inputs u(t) is provided in the last sections of this document. CC BY-NC-ND H.P. Gavin 4 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin 6 The Matrix Exponential The matrix exponential is defined for real square matrices, An×n , as ∞ ∆ X eA = Ak /k! = I + A + AA/2 + AAA/6 + AAAA/24 + · · · (12) k=0 Properties of the matrix exponential: • If A = AT then eA > 0. • If A = −AT then [eA ][eA ]T = I • eAt eBt = e(A+B)t • [eA ]T = eA T • [eA ]−1 = e−A • eSAS −1 eSAS −1 eSAS −1 • d At dt e = SeA S −1 for any square matrix Sn×n . 1 1 = I + SAS −1 + SAS −1 SAS −1 + SAS −1 SAS −1 SAS −1 + · · · 2 6 1 1 = SS −1 + SAS −1 + SAAS −1 + SAAAS −1 + · · · 2 6 = S[I + A + AA/2 + AAA/6 + · · · ]S −1 = SeA S −1 . (13) = AeAt 1 1 1 eAt = I + At + AAt2 + AAAt3 + AAAAt4 + · · · 2 6 24 d At 1 1 e = A + AA + AAAt2 + AAAAt3 + · · · dt 2 6 1 1 1 = A[I + At + AAt2 + AAAt3 + AAAAt4 + · · · ] 2 6 24 d At e = AeAt (14) dt CC BY-NC-ND H.P. Gavin 5 Linear Time Invariant Systems • A R t Aτ 0 e dτ = eAt − I Z t A eAτ dτ 0 Z t = d Aτ e dτ dτ 0 t eAτ 0 At = = e − eA0 = eAt − I Z t A eAτ dτ 0 Z t −Aτ −A • R t A(t−τ ) dτ 0e 0 = eAt − I (15) dτ = e−At − I e (16) = A−1 (eAt − I) Z t eA(t−τ ) dτ 0 = Z t eAt e−Aτ dτ 0 Z At t −Aτ = e 0 e dτ = eAt (−A−1 ) e−At − I = −eAt A−1 e−At + eAt A−1 = −A−1 AeAt A−1 e−At + A−1 AeAt A−1 = −A−1 eAAA −1 t −At e + A−1 eAAA −1 t = −A−1 eAt e−At + A−1 eAt = −A−1 + A−1 eAt = A = −1 At e −I (17) Z t eAτ dτ 0 (18) • The solution to ẋ(t) = Ax(t) + Bu(t), x(0) = xo , for t ≥ 0 is At x(t) = e xo + Z t eA(t−τ ) 0 Bu(τ ) dτ . (19) As a special case of the above, if the input to the system is vδ(t) where v is a m by 1 vector and δ(t) is the Dirac delta function, and if xo = 0, then the output y(t) is called the unit impulse response function, h(t). h(t) = CeAt Bv . (20) CC BY-NC-ND H.P. Gavin 6 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin ∆ q With definitions of the natural frequency, ωn = k/m, the damping ratio, q √ ∆ ∆ ζ = c/(2 mk), and the damped natural frequency, ωd = ωn |ζ 2 − 1|, let A= 0 1 −k/m −c/m = 0 1 2 −ωn −2ζωn (21) . For this dynamics matrix, the matrix exponential depends on the damping ratio, ζ, as follows: damping undamped underdamped damping ratio ζ=0 0<ζ<1 eAt e At " cos ωn t −ωn sin ωn t cos ωd t + √ ζ = eAt = e−ζωn t 1 ωn sin ωn t cos ωn t 1−ζ 2 − √ ωd 1−ζ 2 critically damped overdamped ζ=1 ζ>1 e At =e −ωn t eAt = e−ζωn t # 1 ωd sin ωd t sin ωd t cos ωd t − √ ζ 1 + ωn t t −ωn2 t 1 − ωn t cosh ωd t + √ ζ sinh ωd t 1−ζ 2 − √ ω2d ζ −1 sinh ωd t sin ωd t 1−ζ 2 1 ωd sin ωd t sinh ωd t cosh ωd t − √ ζ2 ζ −1 sinh ωd t CC BY-NC-ND H.P. Gavin 7 Linear Time Invariant Systems 7 Eigenvalues and Diagonalization Consider the dynamics matrix A of a linear time invariant, (LTI) system. If the input, u(t) is zero, then ẋ = Ax. Assuming a solution of the form x(t) = x̄eλt , and substituting this solution into ẋ = Ax, results in: x̄λeλt = Ax̄eλt or x̄λ = Ax̄ , (22) which is a standard eigenvalue problem, in which x̄ is the eigen-vector and λ is the eigen-value. If A is a n×n matrix, then there are n eigen-values, λ1 , · · · , λn and n associated eigen-vectors, x̄1 , · · · , x̄n . For the dynamics matrix given in equation (7), there are two eigenvalues. v u u t c2 k c ± − 2m 4m m q = −ζωn ± ωn ζ 2 − 1 λ1,2 = − (23) (24) The dynamics matrix contains all the information required to determine the natural frequencies and damping ratios of the system. The n eigen-vectors can be assembled, column-by-column into a matrix, X̄ = [x̄1 x̄2 · · · x̄n ] . Pre-multiplying the eigen-problem by X̄ −1 , X̄ −1 AX̄ = X̄ −1 X̄Λ = diag(λi ) = λ1 ... λn This is called a diagonalization of the dynamics matrix A. Now, consider the linear transformation of coordinates, x(t) = X̄q(t), q(t) = X̄ −1 x(t). Substituting this change of coordinates into equation (3), X̄ q̇(t) = AX̄q(t) + Bu(t), CC BY-NC-ND H.P. Gavin 8 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin and pre-multiplying by X̄ −1 q̇ = X̄ −1 AX̄q + X̄ −1 Bu, or q̇ = λ1 ... λn q̇ = Āq + B̄u , q + X̄ −1 Bu , q(0) = X̄ −1 xo q(0) = X̄ −1 xo (25) y = C X̄q + Du y = C̄q + Du (26) The n differential equations q̇i = λi qi + B̄i u are uncoupled. The state qi (t) is independent of all the other states qj (t), j 6= i. Note that if Λ is complex, so are X̄, Ā, B̄, and C̄. Consider one of the un-coupled equations from equation (25), for the unforced case u = 0 q̇i (t) = λi qi (t) , qi (0) = 1 . This equation has a solution qi (t) = eλi t , where λi is, in general, a complex value, λi = σi ± ıωi , and qi + qi∗ is real-valued. 1 λi t 1 λ∗i t e + e 2 2 1 1 σi t = e (cos ωi t + ı sin ωi t) + eσi t (cos ωi t − ı sin ωi t) 2 2 σi t = e cos ωi t , qi (t) + qi∗ (t) = CC BY-NC-ND H.P. Gavin 9 Linear Time Invariant Systems 8 Transfer Function and Frequency Response Function Taking the Laplace transform of equation (3), (and ignoring the effects of initial conditions) gives sX(s) = AX(s) + BU (s) , (27) Y (s) = CX(s) + DU (s) , (28) which can be written as Y (s) in terms of U (s) as follows, Y (s) = H(s) = C[sI − A]−1 B + D. (29) U (s) This is the transfer function of the linear dynamic system. The same may be carried out on equations (25) and (26), resulting in Y (s) = H(s) = C̄[sI − Ā]−1 B̄ + D. U (s) Recall that the matrix Ā = diag(λi ), so, H(λi ) = ∞. The eigen-values λi of A are called the poles of the system. Equation (29) may be used to determine the complex-valued frequency response function of any dynamic system, by evaluating the transfer function along the line s = ıω. Y (ω) = H(ω) = C[ıωI − A]−1 B + D. (30) U (ω) Assuming that the inputs u(t) are sinusoidal with frequency ω and unit amplitude, the magnitude of the frequency response function, q |H(ω)| = <[H(ω)]2 + =[H(ω)]2 gives the amplitude of the responsess y(t). The phase of H(ω), =[H(ω)] ∠H(ω) = arctan − <[H(ω)] gives the phase angle between the input u(t) and the output y(t). So if u(t) = cos(ωt), then y(t) = |H(ω)| cos(ωt + ∠H(ω)). In Matlab, [mag,pha] = bode(A,B,C,D); generates plots of |H(ω)| and ∠H(ω) for a system defined by matrices A, B, C, and D. CC BY-NC-ND H.P. Gavin 10 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin 9 Transforming Continuous Time Systems to Discrete Time Systems (I) Making a substitution of t = ∆t into equation (19), and specifying that u(τ ) = u(ti ) = ui for 0 ≤ τ ≤ ∆t, x(∆t) = eA∆t xi + = e A∆t Z ∆t eA(∆t−τ ) 0 −1 A∆t xi + A dτ Bui − I Bui , e and defining xi+1 = x(∆t), xi+1 = h eA∆t xi + A−1 eA∆t − I B ui , i h i = [Ad ] xi + [Bd ] ui (31) where Ad and Bd are the discrete-time dynamics matrix and the discrete-time input matrix, Ad = eA∆t and Bd = A−1 (Ad − I)B. Note that Bd exists even though A may not be invertible. Consider the diagonalization A = X̄ −1 ΛX̄. The inverse of A may be expressed A−1 = X̄ −1 Λ−1 X̄, where X̄ X̄ −1 = I. So, A−1 (eAt − I) = X̄ −1 Λ−1 X̄ X̄ −1 (eΛt − I)X̄ = X̄ −1 Λ−1 (eΛt − I)X̄, which contains diagonal terms (eλi − 1)/λi , and eλi − 1 =1. lim λi →0 λi To compute Bd without inverting A, note the following: ∆t2 ∆t3 ∆t4 AA + AAA + AAAA + · · · 2 6 24 ∆t2 ∆t3 ∆t4 A−1 (eA∆t − I) = ∆t + A+ AA + AAA + · · · 2 6 24 ∆t2 ∆t3 ∆t4 −1 A∆t Bd = A (e − I)B = ∆tB + AB + AAB + AAAB + · · · , 2 6 24 eA∆t − I = A∆t + and, if M = An×n Bn×r 0r×n 0r×r , (32) CC BY-NC-ND H.P. Gavin 11 Linear Time Invariant Systems then, M ∆t e ∆t3 ∆t4 ∆t2 MM + MMM + MMMM + · · · = I + ∆tM + 2 6 24 2 3 ∆t ∆t A B AA AB AAA AAB + + + ··· = I + ∆t 2 6 0 0 0 0 0 0 = I + ∆tA + ∆t2 2 AA + · · · ∆tB + ∆t2 2 AB 0 + 0 ∆t3 6 AAB + ··· , so eM ∆t = Ad Bd 0 0 , (33) and the discrete time dynamics matrix Ad and input matrix Bd may be computed using a single matrix exponential computation. In Matlab: [n,r] = size(B); M = [ A B ; zeros(r,n+r) ]; eMdt = expm(M*dt); Ad = eMdt(1:n,1:n); Bd = eMdt(1:n,n+1:n+r); With the matrices Ad and Bd , the transient response may be computed digitally using equation (31). x(:,1) = x0; for p=1:points-1 x(:,p+1) = Ad * x(:,p) + Bd * u(:,p); end CC BY-NC-ND H.P. Gavin 12 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin 10 Transforming Continuous Time Systems to Discrete Time Systems (II) Making a substitution of t = ∆t into equation (19), and specifying that the input changes linearly over a time increment, ∆t, 1 u(τ ) = u(ti ) + (u(ti+1 ) − u(ti )) τ = ui + u0i τ for 0 ≤ τ ≤ ∆t , (34) ∆t gives x(∆t) = eA∆t xi + A∆t = e A∆t = e xi + Z ∆t eA(∆t−τ ) 0 Z ∆t A(∆t−τ ) 0 e B u(τ ) dτ dτ B ui + Z ∆t eA(∆t−τ ) 0 −2 A∆t xi + A−1 eA∆t − I B ui + A e B u0i τ dτ − I − A∆t B u0i . Defining xi+1 = x(∆t), xi+1 = h eA∆t xi + A−1 eA∆t − I B ui + A−2 eA∆t − I − A∆t B u0i , i h = [Ad ] xi + [Bd ] ui + [Bd0 ] u0i i h i (35) where Ad , Bd , and Bd0 are the discrete-time dynamics matrix and the discretetime input matrices. If u(τ ) is constant within the time increment, then u0i = 0 and Bd0 need not be computed. The input matrices Bd and Bd0 exist even though A may not be invertible. To compute Bd without inverting A, note the following: ∆t2 ∆t3 ∆t4 A∆t e − I = A∆t + AA + AAA + AAAA + · · · 2 6 24 ∆t2 ∆t3 ∆t4 A−1 (eA∆t − I) = ∆t + A+ AA + AAA + · · · 2 6 24 ∆t2 ∆t3 ∆t4 −1 A∆t Bd = A (e − I)B = ∆tB + AB + AAB + AAAB + · · · , 2 6 24 and, ∆t2 ∆t3 ∆t4 e − I − A∆t = AA + AAA + AAAA + · · · 2 6 24 ∆t2 ∆t3 ∆t4 −2 A∆t A (e − I − A∆t) = + A+ AA + · · · 2 6 24 ∆t2 ∆t3 ∆t4 0 −2 A∆t Bd = A (e − I − A∆t)B = B+ AB + AAB + · · · , 2 6 24 A∆t CC BY-NC-ND H.P. Gavin 13 Linear Time Invariant Systems If ∆ M(n+2m)×(n+2r) = An×n Bn×r 0n×r 0r×n 0r×r Ir×r 0r×n 0r×r 0r×r (36) , then, eM ∆t = I + ∆tM + ∆t2 ∆t3 ∆t4 MM + MMM + MMMM + · · · 2 6 24 AA AB B AAA AAB AB A B 0 3 2 ∆t ∆t + = I + ∆t 0 0 I + 0 0 0 0 0 + ··· 0 2 6 0 0 0 0 0 0 0 0 0 I + ∆tA + = ∆t2 2 AA + ··· ∆tB + 0 0 ∆t2 2 AB + 0 0 ∆t3 6 AAB + ··· ∆t2 2 B + ∆t3 6 AB 0 0 + ··· , so, M ∆t e = Ad Bd 0 0 0 0 0 Bd 0 , (37) 0 and the discrete time dynamics matrix Ad and input matrices Bd and Bd0 may be computed using a single matrix exponential computation. In Matlab: [n,m] M eMdt Ad Bd Bd_ Bd0 Bd1 = = = = = = = = size(B); [ A B zeros(n,r) ; zeros(r,n+r) eye(r) ; zeros(r,n+2*r) ]; expm(M*dt); eMdt(1:n,1:n); eMdt(1:n,n+1:n+r); eMdt(1:n,n+r+1:n+2*r); Bd - Bd_ / dt; Bd_ / dt; With the matrices Ad , Bd , and Bd0 , the transient response may be computed digitally using equation (35). x(:,1) = x0; for p=1:points-1 x(:,p+1) = Ad * x(:,p) + Bd0 * u(:,p) + Bd1 * u(:,p+1); end CC BY-NC-ND H.P. Gavin 14 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin lsym.m http://www.duke.edu/∼hpgavin/lsym.m 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 function y = lsym (A ,B ,C ,D ,u ,t , x0 ) % LSYM S i m u l a t i o n o f a c o n t i n u o u s −time l i n e a r s ys t e m t o a r b i t r a r y i n p u t s . % y = LSYM(A, B, C,D, u , t , x0 ) computes t h e time r e s p o n s e o f t h e l i n e a r s y st e m : % . % x = Ax + Bu % y = Cx + Du % % A : r e a l n by n dynamics matrix % B : r e a l n by r i n p u t matrix % C : r e a l m by n o u t p u t matrix % D : r e a l m by r feedthrough matrix % u : real r by p m a t r i x o f sampled i n p u t s % t : r e a l 1 by p v e c t o r o f u n i f o r m l y s p a c e d p o i n t s i n time % x0 : r e a l n by 1 v e c t o r o f i n i t i a l s t a t e s , d e f a u l t s t o z e r o % y : r e a l m by p m a t r i x o f t h e sy s te m o u t p u t s % % LSYM r e t u r n s a semi−a n a l y t i c e x a c t s o l u t i o n u s i n g a % c o n t i n u o u s −to−d i s c r e t e c o n v e r s i o n b a s e d on t h e m a t r i x e x p o n e n t i a l , % and assuming u i s a l i n e a r ramp b e t w e e n sample p o i n t s . 20 21 [n ,r , m ] = abcddim (A ,B ,C , D ); % d e t e r m i n e and c h e c k c o m p a t a b i l i t y o f m a t r i x dim ’ s 22 23 points = s i z e (u ,2); % number o f d a t a p o i n t s 24 25 = zeros (m , points ); y % memory a l l o c a t i o n f o r t h e o u t p u t 26 27 28 29 30 31 i f ( nargin == 7 ) x = x0 ; else x = zeros (n ,1); end % i n i t i a l conditions for the state % i n i t i a l c o n d i t i o n s are zero 32 33 dt = % uniform time−s t e p v a l u e t (2) - t (1); 34 35 36 37 38 39 40 41 M eMdt Ad Bd Bd_ Bd0 Bd1 = = = = = = = [ A B zeros (n , r ) ; zeros (r , n + r ) eye( r ) ; zeros (r , n +2* r ) ]; expm( M * dt ); % matrix e x p o n e n t i a l eMdt (1: n ,1: n ); % d i s c r e t e −time dynamics m a t r i x eMdt (1: n , n +1: n + r ); % d i s c r e t e −time i n p u t m a t r i x eMdt (1: n , n + r +1: n +2* r ); % d i s c r e t e −time i n p u t m a t r i x Bd - Bd_ / dt ; % d i s c r e t e −time i n p u t m a t r i x f o r time p Bd_ / dt ; % d i s c r e t e −time i n p u t m a t r i x f o r time p+1 42 43 y (: ,1) = C * x + D * u (: ,1); 44 45 f o r p = 1: points -1 46 x 47 = Ad * x + Bd0 * u (: , p ) + Bd1 * u (: , p +1); 48 y (: , p +1) = C 49 * x + D * u (: , p +1); 50 51 end CC BY-NC-ND H.P. Gavin Linear Time Invariant Systems 15 abcddim.m http://www.duke.edu/∼hpgavin/abcddim.m 1 2 3 4 5 6 7 8 9 10 11 function [n , r , m ] = abcddim (a , b , c , d ) % Usage : [ n , r , m] = abcddim ( a , b , c , d ) % % Check f o r c o m p a t i b i l i t y o f t h e d i m e n s i o n s o f t h e m a t r i c e s d e f i n i n g % t h e l i n e a r sy s t em ( a , b , c , d ) . % % Returns n = number o f s ys t e m s t a t e s , % r = number o f sy s te m i n p u t s , % m = number o f s y st e m o u t p u t s . % % Returns n = r = m = −1 i f t h e s y s te m i s n o t c o m p a t i b l e . 12 13 % A. S . Hodel <s c o t t e @ e n g . auburn . edu> 14 15 16 17 i f ( nargin ˜= 4) error ( ’ usage : abcddim (a , b , c , d ) ’ ); end 18 19 n = -1; r = -1; m = -1; 20 21 22 [ am , an ] = s i z e ( a ); i f ( am ˜= an ) , error ( ’ abcddim : a is not square ’ ); end 23 24 25 [ bm , bn ] = s i z e ( b ); i f ( bm ˜= am ) , error ( ’ abcddim : a and b are not compatible ’ ); end 26 27 28 [ cm , cn ] = s i z e ( c ); i f ( cn ˜= an ) , error ( ’ abcddim : a and c are not compatible ’ ); end 29 30 31 32 [ dm , dn ] = s i z e ( d ); i f ( cm ˜= dm ) , error ( ’ abcddim : c and d are not compatible ’ ); end i f ( bn ˜= dn ) , error ( ’ abcddim : b and d are not compatible ’ ); end 33 34 35 36 n = an ; r = bn ; m = cm ; 37 38 % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− abcddim .m CC BY-NC-ND H.P. Gavin 16 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin damp.m http://www.duke.edu/∼hpgavin/damp.m 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 function [ wnout , z ] = damp (a , delta_t ) % DAMP N a t u r a l f r e q u e n c y and damping f a c t o r f o r c o n t i n u o u s s y s t e m s . % [Wn, Z ] = DAMP(A) r e t u r n s v e c t o r s Wn and Z c o n t a i n i n g t h e % n a t u r a l f r e q u e n c i e s and damping f a c t o r s o f A. The v a r i a b l e A % can be i n one o f s e v e r a l f o r m a t s : % % 1) I f A i s s q u a r e , i t i s assumed t o be t h e s t a t e −s p a c e % ’A’ m a t r i x . % 2) I f A i s a row v e c t o r , i t i s assumed t o be a v e c t o r o f % t h e p o l y n o m i a l c o e f f i c i e n t s from a t r a n s f e r f u n c t i o n . % 3) I f A i s a column v e c t o r , i t i s assumed t o c o n t a i n % root locations . % % When i n v o k e d w i t h o u t l e f t hand arguments DAMP p r i n t s t h e % e i g e n v a l u e s w i t h t h e i r n a t u r a l f r e q u e n c y and damping f a c t o r i n a % t a b u l a r f o r m a t on t h e s c r e e n . 17 18 [m , n ] = s i z e ( a ); 19 20 i f (n <1 || m <1) , wnout =0; z =0; return ; end 21 22 23 24 25 26 27 28 29 30 i f ( m == n ) r = e ig ( a ); e l s e i f ( m == 1) r = ( roots ( a )); e l s e i f ( n == 1) r = a; else error ( ’ Must be a vector or a square matrix . ’ ); end 31 32 i f ( nargin == 2 ) , r = log ( r )/ delta_t ; end % d i s c r e t e time s ys t em 33 34 35 36 37 f o r k = 1: n wn ( k ) = abs( r ( k )); z(k) = - ( r e a l ( r ( k )) - 2* eps) / ( wn ( k ) + 2* eps ); end 38 39 40 41 42 43 [ wns , idx ] = sort (abs( wn )); % s o r t by i n c r e a s i n g n a t u r a l f r e q u e n c y wn = wn ( idx ); z = z ( idx ); r = r ( idx ); wd = wn .* sqrt ( abs ( z .ˆ2 - 1 ) ); 44 45 46 47 48 49 50 i f nargout == 0 % D i s p l a y r e s u l t s on t h e s c r e e n . f p r i n t f ( ’ \ n ’ ); fprintf (’ Natural Damped \ n ’ ); fprintf (’ Frequency Frequency Eigenvalue \ n ’ ); fprintf (’ ( cyc / sec ) Damping ( cyc / sec ) real imag \ n ’ ); fprintf (’ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\ n ’ ); 51 52 53 54 f o r idx = 1:1: n fprintf (’ end %10.5 f %10.5 f %10.5 f %10.5 f %10.5 f \ n ’ , wn ( idx )/(2* pi ) , z ( idx ) , wd ( idx )/(2* p 55 56 57 58 return % S u p p r e s s o u t p u t end wnout = wn ; 59 60 % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− DAMP CC BY-NC-ND H.P. Gavin 17 Linear Time Invariant Systems mybode.m http://www.duke.edu/∼hpgavin/mybode.m 1 2 3 4 5 6 7 8 9 10 11 12 function [ mag , pha ] = mybode (a ,b ,c ,d , iu ,w ,axes , figno , leg , tol ) % [ mag , pha ] = mybode ( a , b , c , d , iu , w , axes , f i g n o , l e g , t o l ) % p l o t s t h e magnitude and p h a s e o f t h e % s t e a d y −s t a t e harmonic r e p o n s e o f a c o n t i n u o u s time l i n e a r dynamic sy s te m . % where : % a , b , c , d a r e t h e s t a n d a r d s t a t e −s p a c e m a t r i c e s o f a dynamic sy s te m % i u i s t h e s e l e c t e d i n p u t ( column o f B) ( d e f a u l t : i u = 1) % w is a vector of frequencies ( d e f a u l t : w = l o g s p a c e ( −2 ,2 ,200)∗2∗ p i % a x i s i s e i t h e r x , y , n , or b t o i n d i d a t e wich a x e s s h o u l d be l o g −s c a l e d . . . % x , y , n e i t h e r , or b o t h . The d e f a u l t i s b o t h . The y−a x i s f o r t h e p h a s e p l o t % i s a l w a y s l i n e a r l y −s c a l e d . % mag and pha a r e t h e magnitude and p h a s e o f t h e f r e q u e n c y r e s p o n s e f c t n 13 14 % Henri Gavin , Dept . C i v i l E n g i n e e r i n g , Duke U n i v e r s i t y , h e n r i . gavin@duke . edu 15 16 17 % Krajnik , Eduard , ’A s i m p l e and r e l i a b l e p h a s e unwrapping a l g o r i t h m , ’ % h t t p : / /www. mathnet . or . k r / mathnet / p a p e r f i l e / Czech / Eduard / p h a s e . ps 18 19 [n ,m , p ] = abcddim (a ,b ,c , d ); % check f o r c o m p a t i b i l e dimensions 20 21 22 23 24 if if if if ( nargin ( nargin ( nargin ( nargin < < < < 10) tol = 1e -16; end 7) axes = ’b ’; end 6) w = logspace ( -2 ,2 ,200)*2* pi ; 5) iu = 1; end % default % default end % % default rcond l e v e l plot formatting d e f a u l t frequency axis input 25 26 27 28 nw = length ( w ); biu = b (: , iu ); diu = d (: , iu ); 29 30 I = sqrt ( -1.0); 31 32 %warning o f f 33 34 g = zeros ( nw , p ); % a l l o c a t e memory f o r t h e f r e q u e n c y r e s p o n s e f u n c t i o n , g 35 36 37 38 39 40 41 42 43 % compute t h e f r e q u e n c y r e s p o n s e f u n c t i o n , g f o r j =1: nw % g ( j , : ) = [ c ∗ ( (w( j ) ∗ I ∗ e y e ( n)−a ) \ b i u ) + d i u ] ’ ; [u ,s , v ] = svd( w ( j )* I *eye( n ) - a ); % s i n g u l a r v a l u e decomp . o f A idx = max( find ( diag ( s ) > s (1 ,1)* tol ) ); char_eq = v (: ,1: idx ) * inv ( s (1: idx ,1: idx )) * u (: ,1: idx ) ’; g (j ,:) = [ c * char_eq * biu + diu ] ’; end 44 45 46 47 48 mag = abs( g ); pha = zeros ( nw , p ); pha (1 ,:) = -atan2(imag( g (1 ,:)) , r e a l ( g (1 ,:))); % −ve s i g n ! pha (2: nw ,:) = ones( nw -1 ,1)* pha (1 ,:) - cumtrapz ( angle ( g (2: nw ,:)./ g (1: nw -1 ,:))); 49 50 %pha = unwrap(−atan2 ( imag ( g ) , r e a l ( g ) ) ) ; % −ve s i g n ! 51 52 i f (nargout < 2 ) % s e t up t h e p l o t s 53 54 55 56 57 58 59 60 i f ( nargin >= 8) , f i g u r e ( figno ); e l s e f i g u r e (13); end clf subplot (211) i f ( axes == ’x ’) semilogx ( w /2/ pi , mag ); % p l o t t h e magnitude r e s p o n s e e l s e i f ( axes == ’y ’) semilogy ( w /2/ pi , mag ); % p l o t t h e magnitude r e s p o n s e CC BY-NC-ND H.P. Gavin 18 61 62 63 64 65 66 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin e l s e i f ( axes == ’n ’) plot ( w /2/ pi , mag ); else log log ( w /2/ pi , mag ); end i f ( nargin >= 9) , legend ( leg ); end % p l o t t h e magnitude r e s p o n s e % p l o t t h e magnitude r e s p o n s e 67 68 69 70 axis ([ min( w )/2/ pi , max( w )/2/ pi , min(min( mag )) , max(max( mag )) ]); ylabel ( ’ magnitude ’ ); grid on 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 subplot (212) i f ( axes == ’n ’ || axes == ’y ’) plot ( w /(2* pi ) , pha *180/ pi ); % p l o t the phase else semilogx ( w /(2* pi ) , pha *180/ pi ); % p l o t the phase end i f ( nargin >= 9) , legend ( leg ); end pha_min = f l o o r (min(min( pha *180/ pi ))/90)*90; pha_max = c e i l (max(max( pha *180/ pi ))/90)*90; set (gca , ’ ytick ’ , [ pha_min : 90 : pha_max ]) axis ([ min( w )/2/ pi max( w )/2/ pi pha_min pha_max ]); xlabel ( ’ frequency ( Hertz ) ’) ylabel ( ’ phase ( degrees ) ’) grid on 86 87 88 end end 89 90 % −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−− MYBODE CC BY-NC-ND H.P. Gavin 19 Linear Time Invariant Systems 11 Numerical Example: a spring-mass-damper oscillator For the single degree of freedom oscillator of Section 2, let’s say m = 2 ton, c = 1.4 N/mm/s, k = 6.8 N/mm, do = 5.5 mm and vo = 2.1 mm/s. Note that these units are consisent. (1 N)=(1 kg)(1 m/s2 )=(1 ton)(1 mm/s2 ) For these values, the linear time invariant system description of equations (7) and (8) become ẋ(t) = y(t) = 0 1 0 x(t) + u(t) , −3.4 −0.7 0.5 x(0) = 5.5 2.1 (38) 6.8 1.4 0 x(t) + u(t) −3.4 −0.7 0.5 (39) 1. What are the natural frequencies and damping ratios of this system? >> A = [ 0 1 ; -3.4 -0.7 ] % the dynamics matrix A = 0.00000 -3.40000 1.00000 -0.70000 >> eig(A) % eigenvalues of the dynamics matrix ans = -0.3500 + 1.8104i -0.3500 - 1.8104i >> wn = abs(eig(A)) % absolute values of the eig’s of A are omega_n wn = 1.8439 1.8439 >> z = -real(eig(A)) ./ wn % ratio of real eig(A) to omega_n is damping ratio z = 0.18981 0.18981 CC BY-NC-ND H.P. Gavin 20 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin >> wd = imag(eig(A)) % imaginary parts of the eig’s of A are omega_d wd = 1.8104 -1.8104 q So, the natural frequency is 1.84 rad/s (the same as k/m), the damping √ ratios is 19% (the same as c/ q 4mk), and the damped natural frequency is 1.81 rad/s (the same as ωn |ζ 2 − 1|). These calculations can be done in one step with the m-file damp.m >> damp(A) Natural Damped Frequency Frequency Eigenvalue (cyc/sec) Damping (cyc/sec) real imag ----------------------------------------------------0.29347 0.18981 0.28813 -0.35000 1.81039 0.29347 0.18981 0.28813 -0.35000 -1.81039 2. What is the free response of this system to the specified initial conditions xo ? >> >> >> >> >> >> >> > > >> >> >> >> dt = 0.01; % n = 1000; % t = [0:n-1]*dt; % xo = [ 5.5 ; 2.1]; % C = [ 6.8 1.4 ; -3.4 -0.7 ]; % y = zeros(2,n); % for k=1:n y(:,k) = C*expm(A*t(k))*xo; end plot(t,y) legend(’foundation force, N’, ’mass xlabel(’time, s’) ylabel(’outputs, y_1 and y_2’) time step value, sec number of time steps time values, starting at t=0 initial state (mm, mm/s) output matrix initialize outputs acceleration, mm/sˆ2’) The free response is plotted in figure 1. CC BY-NC-ND H.P. Gavin 21 Linear Time Invariant Systems foundation force, N mass acceleration, mm/s2 40 outputs, y1 and y2 30 20 10 0 -10 -20 0 2 4 6 8 10 time, s Figure 1. Free response of the linear time invariant system given in equations (38) and (39). 3. What is the response of this system to a unit impuse, u(t) = δ(t)? >> >> >> >> > > >> >> >> >> B = v = h = for [ 0 ; 0.5 ]; % input matrix 1; zeros(2,n); % initialize unit impulse responses k=1:n h(:,k) = C*expm(A*t(k))*B*v; end plot(t,h) legend(’foundation force, N’, ’mass acceleration, mm/sˆ2’) xlabel(’time, s’) ylabel(’unit impuse responses, h_1(t) and y_2(t)’) The unit impuse response is plotted in figure 2. 4. What is the response of this system to external forcing u(t) = 50 cos(πt)? >> D = [ 0 ; 0.5 ]; % feedthrough matrix >> u = 50 * cos(pi*t); % external forcing >> y = lsym(A,B,C,D,u,t,xo); % use the "lsym" command >> plot(t,y) >> legend(’foundation force, N’, ’mass acceleration, mm/sˆ2’) >> xlabel(’time, s’) >> ylabel(’forced harmonic responses, y_1(t) and y_2(t)’) CC BY-NC-ND H.P. Gavin 22 CEE 541. – Structural Dynamics – Duke University – Fall 2014 – H.P. Gavin foundation force, N mass acceleration, mm/s2 unit impuse responses, h1(t) and h2(t) 1.5 1 0.5 0 -0.5 -1 0 2 4 6 8 10 time, s Figure 2. Unit impulse response of the linear time invariant system given in equations (38) and (39). The forced harmonic response is plotted in figure 3. 5. What is the frequency response function from u(t) to y(t) for this system? >> w = 2*pi*logspace(-1,0,100); >> bode(A,B,C,D,1,w); % frequency axis data The magnitude and phase of the steady-state forced harmonic response is plotted in figure 4. Note how the magnitude and phase of the frequency response shown in figure 4 can be used to predict the steady steate response of the system to a forcing of u = 10 cos(πt). (The forcing frequency is 0.5 Hertz). This is a fairly simple example. Nevertheless, by simply changing the definitions of the system matrices, A, B, C, and D, and of the input forcing u(t), any linear time invariant system may be analyzed using the same sets of Matlab commands. CC BY-NC-ND H.P. Gavin 23 Linear Time Invariant Systems 60 input forcing 40 20 0 -20 -40 -60 0 2 4 6 8 10 responses, y1(t) and y2(t) time, s 60 40 20 0 -20 -40 foundation force, N mass acceleration, mm/s2 -60 -80 0 2 4 6 8 10 time, s magnitude Figure 3. Forced response of the linear time invariant system given in equations (38) and (39). 100 10 -1 100 phase (degrees) 180 90 0 -90 -180 100 frequency (Hertz) Figure 4. Frequency response of the linear time invariant system given in equations (38) and (39). CC BY-NC-ND H.P. Gavin