Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views17 pages

Matlab 04

The document outlines a practical exercise in control theory, focusing on transfer functions and state-space representations. It includes examples demonstrating the conversion between transfer functions and state-space models, eigenvalue calculations, and canonical forms. The document also covers simulations and transformations relevant to control systems.

Uploaded by

frederickhuallpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views17 pages

Matlab 04

The document outlines a practical exercise in control theory, focusing on transfer functions and state-space representations. It includes examples demonstrating the conversion between transfer functions and state-space models, eigenvalue calculations, and canonical forms. The document also covers simulations and transformations relevant to control systems.

Uploaded by

frederickhuallpa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

FUNCION DE TRANSFERENCIA - AMORTIGUAMIENTO – PRACTICA 04

OBJETIVOS: El alumno debe desarrollar las primeras funciones de Teoria de Control.

>> %Ejemplo 4.1


>> z=0.5;
>> wn=1.5;
>> q=wn*wn;
>> p=[1 2*z*wn wn*wn]

p =

1.0000 1.5000 2.2500

>> roots(p)

ans =

-0.7500 + 1.2990i
-0.7500 - 1.2990i

>> [a,b,c,d]=tf2ss(q,p)

a =

-1.5000 -2.2500
1.0000 0

b =

1
0

c =

0 2.2500

d =

>> eig(a) %should be identical to the poles

ans =

-0.7500 + 1.2990i
-0.7500 - 1.2990i

>> [q2,p2]=ss2tf(a,b,c,d,1) %Should recover q(s) and p(s)


q2 =

0 0 2.2500

p2 =

1.0000 1.5000 2.2500

>> %Set up according to text


>> a=[0 1; -2.25 -1.5]; b=[0; 2.25]; c=[1 0]; d=0;
>> eig(a) %still the same!

ans =

-0.7500 + 1.2990i
-0.7500 - 1.2990i

>> [qs,ps]=ss2tf(a,b,c,d,1)

qs =

0 0 2.2500

ps =

1.0000 1.5000 2.2500

>> %Repeat with the object-oriented state-space models


>> q=2.25;
>> p=[1 1.5 2.25];
>> [a,b,c,d]=tf2ss(q,p);
>> sys_obj=ss(a,b,c,d)

a =
x1 x2
x1 -1.5 -2.25
x2 1 0

b =
u1
x1 1
x2 0

c =
x1 x2
y1 0 2.25
d =
u1
y1 0

Continuous-time model.

>> eig(sys_obj.a) %eigenvalue of state matrix a same as the poles

ans =

-0.7500 + 1.2990i
-0.7500 - 1.2990i

>> tf(sys_obj) %Get the transfer function back

Transfer function:
2.25
------------------
s^2 + 1.5 s + 2.25

>> %Starting from the transfer function


>> sys2=ss(tf(q,p))

a =
x1 x2
x1 -1.5 -1.125
x2 2 0

b =
u1
x1 1
x2 0

c =
x1 x2
y1 0 1.125

d =
u1
y1 0

Continuous-time model.

>> eig(sys2.a) %Another check

ans =
-0.7500 + 1.2990i
-0.7500 - 1.2990i

>> %The minor tidbits


>> printsys(a,b,c,d)

a =
x1 x2
x1 -1.50000 -2.25000
x2 1.00000 0

b =
u1
x1 1.00000
x2 0

c =
x1 x2
y1 0 2.25000

d =
u1
y1 0

>> printsys(q,p,'s')

num/den =

2.25
------------------
s^2 + 1.5 s + 2.25

>> [a,b,c,d]=ord2(wn,z) % Bueno para q=1 solamente

a =

0 1.0000
-2.2500 -1.5000

b =

0
1

c =
1 0

d =

>> %Simulacion de tiempo de respuesta


>> %Try using LTI Viewer yourself
>> %We'll do Example 4.1 with plotting statements here
>> a=[0 1; -2.25 -1.5]; b=[0; 2.25]; c=[1 0]; d=0;
>> sys=ss(a,b,c,d);
>> step(sys)
>> hold
Current plot held

>> G=tf(2.25,[1 1.5 2.25]);


>> step(G,'x')
>> hold off

>> %Transformaciones
>> %Ejemplo 4.6
>> A=[0 1 0; 0 -1 -2; 1 0 -10];
>> rank(A)

ans =

>> eig(A)

ans =
-0.2902
-0.6877
-10.0221

>> [P,L] = eig(A)

P =

0.9557 -0.8208 0.0216


-0.2773 0.5644 -0.2164
0.0984 -0.0881 -0.9761

L =

-0.2902 0 0
0 -0.6877 0
0 0 -10.0221

>> a = inv(P)*A*P %Verificar que podemos realmente diagonalizar la matriz

a =

-0.2902 -0.0000 -0.0000


0.0000 -0.6877 -0.0000
-0.0000 0.0000 -10.0221

>> % Second route


>> B=[0; 2; 0];
>> C=[1 0 0];
>> D=[0];
>> S=ss(A,B,C,D);
>> SD=canon(S)

a =
x1 x2 x3
x1 -0.29018 0 0
x2 0 -0.6877 0
x3 0 0 -10.022

b =
u1
x1 5.2524
x2 6.1155
x3 -0.022556

c =
x1 x2 x3
y1 0.95572 -0.82076 0.02159
d =
u1
y1 0

Continuous-time model.

>> %The 3rd alternative


>> SD=ss2ss(S,inv(P))

a = %Numerically, the algorithm behind this method is not as clean


x1 x2 x3
x1 -0.29018 -1.6646e-16 -3.9409e-15
x2 1.1919e-16 -0.6877 -3.9643e-15
x3 -4.9829e-17 -2.5323e-17 -10.022

b =
u1
x1 5.2524
x2 6.1155
x3 -0.022556

c =
x1 x2 x3
y1 0.95572 -0.82076 0.02159

d =
u1
y1 0

Continuous-time model.

>> %Find the observable canonical form


>> SO=canon(S,'companion')

a =
x1 x2 x3
x1 0 0 -2
x2 1 0 -10
x3 0 1 -11

b =
u1
x1 1
x2 0
x3 0

c =
x1 x2 x3
y1 0 2 -2

d =
u1
y1 0

Continuous-time model.

>> roots([1 11 10 2]) % Check the results

ans =

-10.0221
-0.6877
-0.2902

>> poly(A)

ans =

1.0000 11.0000 10.0000 2.0000

>> %Optional reading, using Appendix of Chapter 4 to find the canonical forms
ourselves
>> P=[B A*B A^2*B];
>> inv(P)*A*P

ans =

0 0 -2
1 0 -10
0 1 -11

>> inv(P)*B

ans =

1
0
0

>> poly(A); %just a check

>> M=[10 11 1; 11 1 0; 1 0 0];


>> T=P*M;
>> inv(T)*A*T

ans =
0 1.0000 0
0 0 1.0000
-2.0000 -10.0000 -11.0000

>> inv(T)*B

ans =

0
-0.0000
1.0000

>> %Onto Example 4.8


>> G=zpk([],[-1 -2 -3],1);
>> S=ss(G);
>> eig(S) %Check

ans =

-3
-2
-1

>> [P,L]=eig(S.a)

P =

1.0000 0.5774 -0.4082


0 -0.5774 0.4082
0 0.5774 -0.8165

L =

-3 0 0
0 -2 0
0 0 -1

>> inv(P)*S.a*P % Just a check of L

ans =

-3.0000 0 0
0 -2.0000 0
0 0 -1.0000

>> SD=canon(S) %find the diagonalized system

a =
x1 x2 x3
x1 -3 0 0
x2 0 -2 0
x3 0 0 -1

b =
u1
x1 0.5
x2 -1.7321
x3 -1.2247

c =
x1 x2 x3
y1 1 0.57735 -0.40825

d =
u1
y1 0

Continuous-time model.

>> inv(P)*S.b % Identical to SD.b

ans =

0.5000
-1.7321
-1.2247

>> S.c*P % Identical to SD.c

ans =

1.0000 0.5774 -0.4082

>> SO=canon(S,'companion') %observable canonical form

a =
x1 x2 x3
x1 0 0 -6
x2 1 0 -11
x3 0 1 -6

b =
u1
x1 1
x2 0
x3 0

c =
x1 x2 x3
y1 0 0 1

d =
u1
y1 0

Continuous-time model.

Example 4.1

>> %Example 4.1


>> z=0.5; % Pick two sample numbers
>> wn=1.5;
>> p=[1 2*z*wn wn*wn];
>> [a,b,c,d]=tf2ss(wn*wn,p)

a =

-1.5000 -2.2500
1.0000 0

b =

1
0

c =

0 2.2500

d =

Example 4.3

>> %Example 4.3


>> q=[1 3];
>> p=[1 0.4 1];
>> roots(p)

ans =

-0.2000 + 0.9798i
-0.2000 - 0.9798i

>> [a,b,c,d]=tf2ss(q,p)
a =

-0.4000 -1.0000
1.0000 0

b =

1
0

c =

1 3

d =

>> eig(a)

ans =

-0.2000 + 0.9798i
-0.2000 - 0.9798i

>> [q2,p2]=ss2tf(a,b,c,d,1) %check by going backward

q2 =

0 1.0000 3.0000

p2 =

1.0000 0.4000 1.0000

Example 4.4

>> %Example 4.4


>> [a,b,c,d]=tf2ss([1 2], [1 3])

a =

-3

b =

c =

-1
d =

Example 4.6
>> %Example 4.6
>> %Check the eigenvalues of A
>> A=[0 1 0; 0 -1 -2; 1 0 -10]

A =

0 1 0
0 -1 -2
1 0 -10

>> eig(A)

ans =

-0.2902
-0.6877
-10.0221

Example 4.7A

>> %Example 4.7A


>> t1=0.25; t2=0.5; % Define the variables
>> k1=1; k2=2;
>> V1=1; V2=2;
>> cos=1;
>> % Calculate the steady state values
>> c1s=cos/(1+k1*t1)

c1s =

0.8000

>> c2s=c1s/(1+k2*t2)

c2s =

0.4000

>> % Coefficients of A and B in (E4-27)


>> a11=-(1/t1+k1)

a11 =

-5

>> a12=0;
>> a21=1/t2;
>> a22=-(1/t2+k2)
a22 =

-4

>> b11=1/t1;
>> b12=(cos-c1s)/V1

b12 =

0.2000

>> b21=0;
>> b22=(c1s-c2s)/V2

b22 =

0.2000

>> % Finally build A and B in (E4-27)


>> a=[a11 a12; a21 a22]

a =

-5 0
2 -4

>> b=[b11 b12; b21 b22]

b =

4.0000 0.2000
0 0.2000

>> eig(a)

ans =

-4
-5

>> % Define C such that both C1 and C2 are outputs


>> c=[1 0; 0 1]

c =

1 0
0 1

>> d=[0 0; 0 0];

>> %Now for input number 1, Co


>> [q1,p]=ss2tf(a,b,c,d,1)
q1 =

0 4 16
0 0 8

p =

1 9 20

>> %And input number 2, Q


>> [q2,p]=ss2tf(a,b,c,d,2)

q2 =

0 0.2000 0.8000
0 0.2000 1.4000

p =

1 9 20

>> %If C2 is the only output


>> c=[0 1];
>> d=[0 0];
>> [q21,p]=ss2tf(a,b,c,d,1) %Co as input

q21 =

0 0 8

p =

1 9 20

>> [q22,p]=ss2tf(a,b,c,d,2) %Q as input

q22 =

0 0.2000 1.4000

p =

1 9 20

>> %If C1 is the only output


>> c=[1 0];
>> d=[0 0];
>> [q11,p]=ss2tf(a,b,c,d,1)

q11 =

0 4 16

p =

1 9 20

>> [q12,p]=ss2tf(a,b,c,d,2)

q12 =

0 0.2000 0.8000

p =

1 9 20

Example 4.9

>> %Example 4.9


>> G=zpk([],[-1 -2 -3],1)

Zero/pole/gain:
1
-----------------
(s+1) (s+2) (s+3)

>> S=ss(G); % S is the state space system


>> canon(S) % cannon() default is the diagonal form

a =
x1 x2 x3
x1 -3 0 0
x2 0 -2 0
x3 0 0 -1

b =
u1
x1 0.5
x2 -1.7321
x3 -1.2247

c =
x1 x2 x3
y1 1 0.57735 -0.40825

d =
u1
y1 0

Continuous-time model.

>> canon(S,'companion') %The observable companion

a =
x1 x2 x3
x1 0 0 -6
x2 1 0 -11
x3 0 1 -6

b =
u1
x1 1
x2 0
x3 0

c =
x1 x2 x3
y1 0 0 1

d =
u1
y1 0

Continuous-time model.

You might also like