LABORATORIO FONDAMENTI AUTOMATICA – 1ª ESERCITAZIONE JORDAN Jordan Canonical Form.
JORDAN(A) computes the Jordan Canonical/Normal Form of the matrix A.
The matrix must be known exactly, so its elements must be integers or ratios of small integers. Any errors in the input matrix may completely change its JCF.
[V,J] = JORDAN(A) also computes the similarity transformation, V, so that V\A*V = J.
The columns of V are the generalized eigenvectors.
» A=[2 -1 0 3;1 1 0 -2;3 0 1 1;-2 -2 4 1];
» JM=jordan(A) JM =
−−−−0.3415 0 0 0 0 0.4391 −−−− 2.3900i 0 0 0 0 0.4391 + 2.3900i 0 0 0 0 4.4634
CAT Concatenate arrays.
CAT(DIM,A,B) concatenates the arrays A and B along the dimension DIM.
CAT(2,A,B) is the same as [A,B].
CAT(1,A,B) is the same as [A;B].
B = CAT(DIM,A1,A2,A3,A4,...) concatenates the input arrays A1, A2, etc. along the dimension DIM.
» A=[1 2;3 4];
» B=[5 6;7 8];
» Cc=cat(2,A,B) Cc =
1 2 5 6 3 4 7 8
» Cr=cat(1,A,B) Cr =
1 2 3 4 5 6 7 8
INITIAL Initial condition response of state-space models.
INITIAL(SYS,X0) plots the undriven response of the state-space model SYS with initial condition X0 on the states. This response is characterized by the equations
Continuous time: x = A x , y = C x , x(0) = x0
Discrete time: x[k+1] = A x[k], y[k] = C x[k], x[0] = x0 .
The time range and number of points are chosen automatically.
INITIAL(SYS,X0,TFINAL) simulates the time response from t=0 to the final time
t=TFINAL. For discrete-time models with unspecified sample time, TFINAL should be the number of samples.
INITIAL(SYS,X0,T) specifies a time vector T to be used for simulation. For discrete systems, T should be of the form 0:Ts:Tf where Ts is the sample time. For continuous-time models, T should be of the form 0:dt:Tf where dt will become the sample time of a discrete approximation of the continuous model.
INITIAL(SYS1,SYS2,...,X0,T) plots the response of multiple LTI models SYS1,SYS2,.on a single plot. The time vector T is optional. You can also specify a color, line style, and
marker for each system, as in initial(sys1,'r',sys2,'y--',sys3,'gx',x0).
When invoked with left hand arguments, [Y,T,X] = INITIAL(SYS,X0)
returns the output response Y, the time vector T used for simulation, and the state
trajectories X. No plot is drawn on the screen. The matrix Y has LENGTH(T) rows and as many columns as outputs in SYS.
Similarly, X has LENGTH(T) rows and as many columns as states.
STEP Step response of LTI models.
STEP(SYS) plots the step response of the LTI model SYS (created with either TF, ZPK, or SS). For multi-input models, independent step commands are applied to each input channel. The time range and number of points are chosen automatically.
STEP(SYS,TFINAL) simulates the step response from t=0 to the final time t=TFINAL. For discrete-time models with unspecified sampling time, TFINAL is interpreted as the number of samples.
STEP(SYS,T) uses the user-supplied time vector T for simulation. For discrete-time models T should be of the form Ti:Ts:Tf where Ts is the sample time. For continuous-time models, T should be of the form Ti:dt:Tf where dt will become the sample time for the discrete approximation to the continuous system. The step input is always assumed to start at t=0 (regardless of Ti).
STEP(SYS1,SYS2,...,T) plots the step response of multiple LTI models SYS1,SYS2,... on a single plot. The time vector T is optional. You can also specify a color, line style, and marker for each system, as in step(sys1,'r',sys2,'y--',sys3,'gx').
When invoked with left-hand arguments, [Y,T] = STEP(SYS)
returns the output response Y and the time vector T used for simulation. No plot is drawn on the screen. If SYS has NY outputs and NU inputs, and LT=length(T), Y is an array of size [LT NY NU] where Y(:,:,j) gives the step response of the j-th input channel.
For state-space models, [Y,T,X] = STEP(SYS)
also returns the state trajectory X which is an LT-by-NX-by-NU array if SYS has NX states.
LSIM Simulate time response of LTI models to arbitrary inputs.
LSIM(SYS,U,T) plots the time response of the LTI model SYS to the input signal described by U and T. The time vector T consists of regularly spaced time samples and U is a matrix with as many columns as inputs and whose i-th row specifies the input value at time T(i).
For example, t = 0:0.01:5; u = sin(t); lsim(sys,u,t)
simulates the response of a single-input model SYS to the input u(t)=sin(t) during 5 seconds.
For discrete-time models,Ushouldbesampledatthesamerate as SYS (Tisthenredundant and can be omitted or set to the empty matrix).
For continuous-time models, choose the sampling period T(2)-T(1) small enough to
accurately describe the input U. LSIM checks for intersample oscillations and resamples U if necessary.
LSIM(SYS,U,T,X0) specifies an additional nonzero initial state X0 (for state-space models only).
LSIM(SYS1,SYS2,...,U,T,X0) simulates the response of multiple LTI models SYS1,SYS2,...
on a single plot. The initial condition X0 is optional. You can also specify a color, line style, and marker for each system, as in:
lsim(sys1,'r',sys2,'y--',sys3,'gx',u,t).
When invoked with left-hand arguments, [YS,TS] = LSIM(SYS,U,T)
returns the output history YS and time vector TS used for simulation. No plot is drawn on the screen. The matrix YS has LENGTH(TS) rows and as many columns as outputs in SYS.
WARNING: TS contains more points than T when U is resampled to reveal intersample oscillations. To get the response at the samples T only, extract YS(1:d:end,:) where d=round(length(TS)/length(T)).
For state-space models,
[YS,TS,XS] = LSIM(SYS,U,T,X0)
also returns the state trajectory XS, a matrix with LENGTH(TS) rows and as many columns as states.
L’ESPONENZIALE di una MATRICE QUADRATA A è definito tramite lo sviluppo in serie di seguito esplicitato:
...
120 ·
· 1 24
· 1 6
· 1 2
· 1
...
·
! · ... 1
·
! · 2
· 1
! · 1
· 1
! · 0
· 1
! · 1
5 5 4
4 3
3 2
2
2 2 1
1 0
0 0
+ +
+ +
+ +
=
= + +
+ +
+
=
= ∑∞
=
t A t
A t
A t
A t
A I
t k A t
A t
A t
A t
k A
e
k kk
k k At
Tuttavia è possibile calcolare l’esponenziale della matrice A nota la matrice di Jordan a essa associata, cioè, indicata con Z la matrice le cui colonne sono costituite dagli autovettori della matrice A si ottiene:
· 1
·
−= Z e Z
e
At Ajt in cui è:A
J= Z
−1A · Z
EXPM Matrix exponential.
EXPM(X) is the matrix exponential of X. EXPM is computed using a scaling and squaring algorithm with a Pade approximation.
Although it is not computed this way, if X has a full set of eigenvectors V with corresponding eigenvalues D, then [V,D] = EIG(X)
and EXPM(X) = V*diag(exp(diag(D)))/V.
ESERCIZIO 1
AUTOVALORI AUTOVETTORI DIAGONALIZZAZIONE
Si consideri la matrice quadrata di ordine n = 4:
−
−
−
−
=
1 4 2 2
1 1 0 3
2 0 1 1
3 0 1 2 A
» A=[2 -1 0 3;1 1 0 -2;3 0 1 1;-2 -2 4 1];
» polcar=poly(A) polcar =
1.0000 -5.0000 8.0000 -23.0000 -9.0000
» autovalori=roots(polcar) autovalori =
4.4634
0.4391 + 2.3900i 0.4391 - 2.3900i -0.3415
» tracciaA=trace(A) traccia =
5
» sommautoval=sum(autovalori) sommautoval =
5.0000
» determ=det(A) deter =
−−−−9
» prodautoval=prod(autovalori) prodautoval =
−−−−9.0000
» [T D]=eig(A) T =
0.5094 −−−− 0.0030i 0.5094 + 0.0030i 0.2231 0.5976 −−−−0.3224 −−−− 0.4472i −−−−0.3224 + 0.4472i −−−−0.8466 −−−−0.0929 −−−−0.0089 −−−− 0.4825i −−−−0.0089 + 0.4825i −−−−0.1587 0.6503 −−−−0.3701 + 0.2583i −−−−0.3701 −−−− 0.2583i −−−−0.4563 0.4597 D =
0.4391 + 2.3900i 0 0 0 0 0.4391 - 2.3900i 0 0 0 0 -0.3415 0 0 0 0 4.4634
» T1=inv(T);
» AD=T1*A*T AD =
0.4391 + 2.3900i 0.0000 + 0.0000i −−−−0.0000 −−−− 0.0000i 0.0000 + 0.0000i 0.0000 −−−− 0.0000i 0.4391 −−−− 2.3900i 0.0000 + 0.0000i 0 −−−− 0.0000i -0.0000 + 0.0000i −−−−0.0000 −−−− 0.0000i −−−−0.3415 + 0.0000i 0.0000 −−−− 0.0000i -0.0000 −−−− 0.0000i −−−−0.0000 + 0.0000i −−−−0.0000 + 0.0000i 4.4634 −−−− 0.0000i
MATRICE A IN FORMA DI JORDAN A ELEMENTI REALI.
Si ricava la parte reale e la parte immaginaria di uno dei due autovettori associati agli auto valori complessi.
» V1=real(T(:,1)) V1 =
0.5094 −−−−0.3224 −−−−0.0089 −−−−0.3701
» V2=imag(T(:,1)) V2 =
−−−−0.0030 −−−−0.4472 −−−−0.4825 0.2583
» V3=T(:,3) V3 = 0.2231 −−−−0.8466 −−−−0.1587 −−−−0.4563
» V4=T(:,4) V4 = 0.5976 −−−−0.0929 0.6503 0.4597
» Treal=cat(2,V1,V2,V3,V4)
» T1real=inv(Treal)
» Jreal=T1real*A*Treal Jreal =
0.4391 2.3900 0 0.0000 −−−−2.3900 0.4391 0.0000 −−−−0.0000 −−−−0.0000 0.0000 −−−−0.3415 0.0000 −−−−0.0000 −−−−0.0000 −−−−0.0000 4.4634
ESERCIZIO 2
» A1=[0.4 -1;1 0];
» polcar1=poly(A) polcar1 =
1.0000 −−−−0.4000 1.0000
» IA1=inv(A1) IA1 =
0 1.0000 −−−−1.0000 0.4000
» [Z1 D1]=eig(A1) Z1 =
−−−−0.6928 + 0.1414i −−−−0.6928 −−−− 0.1414i 0 + 0.7071i 0 −−−− 0.7071i
D1 =
0.2000 + 0.9798i 0
0 0.2000 −−−− 0.9798i
Calcolare l’esponenziale matrice con t = 0.1 arrestandosi a K = 4
» expmA1serie=eye(2)+A1*0.1+(A1^2)/2*(0.1)^2+(A1^3)/6*(0.1^3)+(A1^4)/24*(0.1)^4 expmA1serie =
1.0357 −−−−0.1019 0.1019 0.9949
» [Z1 D1]=eig(A1) Z1 =
−−−−0.6928 + 0.1414i −−−−0.6928 −−−− 0.1414i 0 + 0.7071i 0 −−−− 0.7071i D1 =
0.2000 + 0.9798i 0
0 0.2000 - 0.9798i
» AJ1=inv(Z1)*A1*Z1 AJ1 =
0.2000 + 0.9798i 0.0000 −−−− 0.0000i 0.0000 + 0.0000i 0.2000 −−−− 0.9798i
» expmA1jordan=Z1*expm(AJ1*0.1)*inv(Z1) expmA1jordan =
1.0357 + 0.0000i −−−−0.1019 + 0.0000i 0.1019 + 0.0000i 0.9949 + 0.0000i
Si verifica il risultato ottenuto con quello fornito dal comando expm di matlab
» ESM=expm(A1*0.1) ESM =
1.0357 −−−−0.1019 0.1019 0.9949
ESERCIZIO 3
Si consideri il sistema descritto nello SPAZIO degli STATI dall’EQUAZIONE di STATO e dalla TRASFORMAZIONE di USCITA di seguito riportate:
0 ];
1 0 1 [
; 1 2 1
; 2 10 10
12 3 2
2 1 0
) ( )
( )
(
) ( )
( )
( = =
=
−
−
−
−
= +
=
+
=
D C
B t A
Du t
Cx t
y
t Bu t
Ax t
x &
Calcolo degli auto valori
» A=[0 -1 2;2 -3 12;10 -10 -2];B=[1;2;1];C=[1 0 1];D=0;
» autovalA=roots(poly(A)) autovalA =
−−−−2.0000 +10.0000i −−−−2.0000 −−−−10.0000i −−−−1.0000
Gli auto valori, pertanto, sono: λλλλ1 = −−−−1; λλλλ2 = −−−−2 + 10·j ; λλλλ3 = −−−−2 −−−− 10·j Le funzioni modali sono caratterizzate dalle relazioni:
modo1 =
e
λ1·t= e
−1·t= e
−tmodo21 =
e
λ2·t= e
(−2+10j)·t= e
−2t·[cos( 10 · t ) + j sin( 10 · t )]
modo22 =
e
λ3·t= e
(−2+10j)·t= e
−2t·[cos( 10 · t ) − j sin( 10 · t )]
» t=0:0.001:3; m1=exp(-2*t);
» m21=exp((-2+10i)*t); m22=exp((-2-10i)*t); m2=m21+m22;
» subplot(211),plot(t, real(m21), t, imag(m21)) ,grid
» subplot(212),plot(t, real(m22), t, imag(m22)) ,grid
» figure(2),plot(t, m1, t, m2), title(‘Rappresentazione delle Funzioni Modali’), grid
Determinazione del PUNTO di EQUILIBRIO corrispondente all’ingresso
u ( t ) = u = 1
Lo stato di equilibrio è determinato dalla condizione
x & = 0
, da cui consegue:x C y t
Du t
Cx t
y
u B A x u
B x A u
B x A t
Bu t
Ax t
x
· )
( )
( )
(
0 )
( )
( )
(
1⇒ = +
=
−
⇒ =
−
⇒ = +
⇒ = +
=
−&
La matrice inversa A−−−−1 ESISTE se la matrice A È NON SINGOLARE, ovvero det(A) ≠≠≠≠ 0
» determA=det(A) determA = −−−−104
» xE=-inv(A)*B xE =
0.7308 0.8462 −−−−0.0769
» yE=C*xE yE = 0.6538
Calcolo e tracciamento del MOVIMENTO LIBERO dello STATO e dell’USCITA del sistema con STATO INIZIALE x(0) = [0; 1; 1]
» Xo=[0;1;1];
» sist=ss(A,B,C,D);
» [yl t xl]=initial(sist,Xo);
» subplot(211),plot(t,xl),title('movimento libero dello stato'),grid
» subplot(212),plot(t,yl),title('movimento libero dell''uscita'),grid
Per individuare il movimento di ciascuna delle tre componenti dello stato si usa l’istruzione:
» subplot(211),plot(t,(xl(:,1)'),'g',t,(xl(:,2)'),'r',t,(xl(:,3)'),'b'),grid
Calcolo e tracciamento del MOVIMENTO FORZATO dello STATO e dell’USCITA del sistema con INGRESSO:
u ( t ) = u = 1
.» [yf t xf]=step(sist);
» subplot(211),plot(t,xf),title('movimento forzato dello stato'),grid
» subplot(212),plot(t,yf),title('movimento forzato dell''uscita'),grid
ESERCIZIO 4
Si consideri il sistema descritto nello SPAZIO degli STATI dall’EQUAZIONE di STATO e dalla TRASFORMAZIONE di USCITA di seguito riportate:
0 ];
0 1 [ 1 ;
; 1 1 4
3 1 )
(
· ) (
· ) (
) (
· ) (
· )
( = =
=
−
−
−
= +
=
+
=
D C
B t A
u D t x C t y
t u B t x A t x &
Calcolo degli auto valori
» A=[-1 -3;4 -1];B=[1;1];C=[1 0];D=0;
» autovalA=roots(poly(A)) autovalA =
−−−−1.0000 + 3.4641i −−−−1.0000 - 3.4641i
Determinazione del PUNTO di EQUILIBRIO corrispondente all’ingresso
u ( t ) = u = 10
Lo stato di equilibrio è determinato dalla condizione
x & = 0
, da cui consegue:x C y t
u D t x C t y
u B A x u
B x A u
B x A t
u B t x A t x
· )
(
· ) (
· ) (
0 )
(
· ) (
· )
(
1⇒ = +
=
−
⇒ =
−
⇒ = +
⇒ = +
=
−&
La matrice INVERSA A−−−−1 ESISTE se e SOLO se la matrice A È NON SINGOLARE, questo richiede che sia soddisfatta la condizione: det(A) ≠≠≠≠ 0
» determA=det(A) determA = 13
» u=10;
» xE=-inv(A)*B*u xE =
−−−−1.5385 3.8462
» yE=C*xE yE =
−−−−1.5385
Calcolo e tracciamento del MOVIMENTO dell’USCITA y(t) del sistema con STATO INIZIALE qualsiasi (si è scelto x(0) = [2; -1]), segnale d’ingresso u(t) = 10 e intervallo 0 ≤≤≤≤ t ≤≤≤≤ 8.
» Xo=[2;-1];
» t=0:0.01:8;
» sist=ss(A,B,C,D);
» ylib=initial(sist,Xo,t);
» subplot(211),plot(t,ylib),title('movimento libero dell’’uscita'),grid
» yfor=step(10*(sist),t);
» subplot(212),plot(t,yfor),title('movimento forzato dell’’uscita'),grid
» yTot=ylib+yfor;
» plot(t,ylib,t,yfor,t,yTot),grid
» title(‘Movimento libero, movimento forzato e movimento totale dell’’uscita’)
Nella figura seguente si sono riportati gli andamenti temporali dell’uscita yT(t) e delle sue due componenti, movimento libero yL(t) e movimento forzato yF(t).
Calcolo del movimento dello stato x(t) e dell’uscita y(t) nell’intervallo di tempo 0 ≤≤≤≤ t ≤≤≤≤ 10 con l’ingresso u(t) = sin(2·t) e stato iniziale nullo.
» t=0:0.01:10; Xo=[0;0];
» u=sin(2*t);
» [y,ts,x] = lsim(sist,u,t,Xo);
» subplot(212),plot(t,x),title('movimento dello stato x(t)'),grid
» subplot(211),plot(t,y),title('movimento dell''uscita y(t)'),grid