Chapter 4 MATLAB Results

The collection of MATLAB statements and screen display for:

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 =

     0

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 =

     0

>> 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 =

     1

c =

    -1

d =

     1

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.