lab1_control_systems
lab1_control_systems
Matlab Exercise
EE371 Instrumentation & Control Laboratory Duration: 3 hours
Objective
Familiarisation with MATLAB software from control system engineer point of view.
syms s
t1 =8* s /( s ^2+81)
t2 =4+1/5/ s
t3 =3* s +6+1/5/ s
t4 =6* s +11+1/5/ s
t5 = t2
t112 = t1 * t2 /( t3 * t4 - t5 ^2)
simplify ( t112 )
2. Write MATLAB commands to solve Equations (1) and (2) to obtain the I (s) of equation (3)
syms s
m =[3* s +6+1/5/ s -4 -1/5/ s ; -4 -1/5/ s 6* s +11+1/5/ s ]
e =[8* s /( s ^2+81) ; 0]
I = inv ( m ) * e
8 1 1 12
4s + + V1 (s) + − 4s − V2 (s) = (4)
15 2s 5 s
1 11 −1
4s + V1 (s) + 4s + V2 (s) = 2 (5)
5 30 s +1
3. Write MATLAB commands to obtain V1 (s) and V2 (s) from Equations (4) and (5).
m =[4* s +8/15+1/2/ s -4*s -1/5 ; -4*s -1/5 4* s +11/30]
i =[12/ s ; -1/( s ^2+1) ]
V = inv ( m ) * i
conv([coeff1]), [coeff2]).
1
For the step command the transfer function coefficients are input in either vector form, followed
by the “tf” command, or the “zpk” form may be used to define the transfer function. For example,
suppose we want the step response for a system with transfer function
10(s + 1) 10(s + 1)
T (s) = 2
=
s + 5s + 6 (s + 2)(s + 3)
The step response using the vector form may be created by
num=[10 10]
den=[1 5 6]
t=tf(num, den)
step(t)
Another approach is to use the “zpk” command
t=zpk(-1, [-2 -3], 10)
step(t)
In either case, the computer, in effect, multiplies T (s) by 1/s to get the step response. That response
is then calculated and plotted.
Responses to other than a step response may be taken by employing a simple trick with the step
command. If you want the time response of some Y (s) = T (s)R(s) when R(s) is not 1/s, obtain
the step response of sY (s). The computer can be thought of as multiplying by 1/s, then cancelling
the s, resulting in the time response of Y (s).
Suppose we want the time response for the T (s) when
r(t) = 6 cos 4t
6s
R(s) = 2
s + 16
Then
10(s + 1) 6s
sY (s) = sT (s)R(s) = s 2
(s + 2)(s + 3) (s + 16)
To employ the step command in vector form, the “conv” (meaning convolve) command may be used
to multiply polynomial vectors
snum=60*conv([1 0 0], [1 1])
den1=conv([1 2], [1 3])
den=conv(den1, [1 0 16])
sy=tf(snum, den)
step(sy)
Prob 1. Use the step command to get the step response of the following:
5
(a) T (s) =
(s + 4)2
5(s + 6)
(b) T (s) =
(s + 1 + j4)(s + 1 − j4)
Prob 2. Use the step command to get the time response of the following:
32
(a) Y (s) =
(s + 2)2 (s2 + 16)
(b) Y (s) = T (s)R(s),
where
48
T (s) =
(s + 3)(s2 + s + 16)
r(t) = 3e−3t
2
If we want to solve
Y (s) = T (s)R(s)
10(s + 1)
Y (s) =
s2 + 5s + 6
r(t) = 6 cos 4t
sysm s t
T=10*(s+1)/(s^
2+5*s+6)
R=laplace(6*cos(4t))
Y=RT
y=ilaplace (Y)
ezplot (y, [0 10])
Suppose we want the ramp response and the ramp error response for
10
T (s) =
s2 + 3s + 10
Let Y (s) represent the Laplace transform of the ramp response while E(s) represents the Laplace
transform of the ramp error response obtained by using the step command
r1=zpk([], 0, 1)
numt=10
dent=[1 3 10]
t=tf(numt, dent)
sy=t*r1
step(sy)
te=1-t
se=te*r1
step(se)
Here step(sy) provides the ramp response of Y (s) while step(re) provides the ramp error response
of E(s).
Prob 3. Use MATLAB to get the step and ramp responses of
20
(a) T (s) =
s2
+ 5s + 25
9s + 20
(b) T (s) = 3
s + 6s2 + 20
Prob 4. Find the closed-loop step and ramp responses for the following open-loop transfer functions,
assuming unity feedback
20
G(s) =
s(s + 1)(s + 2)
Ans.
r1=zpk([], 0, 1)
ga=zpk([], [0, -1, -2], 20)
ta=ga/(1+ga)
r1=zpk([], 0, 1)
sya=ta*r1
step(sya)
3
Since the MATLAB software assumes that the gain K is positive, to obtain a negative gain
root locus, a negative sign must be introduced into the open-loop transfer function. For example, a
negative-gain root locus for a system can be obtained as follows:
Or, by defining
n=[-3 -9]
d=[1 -1 -1 -15 0]
gh=tf(n,d)
4
semilog plots with a logarithmic x-axis.
Without left-hand arguments, the Bode plot is drawn with the margins indicate on the plot
margin(g)
5(s + 6)
T (s) = (6)
s2 + 6s + 25
5
t = zpk ( -6 ,[ -3+ j *4 -3 - j *4] ,5)
4. Write MATLAB commands using the ”tf” command to create
8s
Ta (s) = (7)
s2 + 92
(2/9)(s + 1/20)
Tb (s) = (8)
s3 + (23/6)s2 + (259/90)s + 1/10
(s + 8)
Y (s) = (9)
s2 + 6s + 36
then we can get y(t) by the commands
syms s t
Y =( s +8) /( s ^2+6* s +36)
y = ilaplace ( Y )
5. Use MATLAB to get the inverse laplace transforms of
(s + 13)
Y (s) = (10)
s(s2 + 4s + 13)
9
Y (s) = (11)
s(s + 3)2
6.Write commands to get the following laplace transforms.
SY S = SS(A, B, C, D)
6
We convert from state-space to transfer function form using the “tf” command.
>> g s = tf (g)
We can then transfer back to state space form using the “ss” command
>> g ss = ss(g s)
Moreover the “tf” and “ss” commands create system objects that MATLAB commands can
interpret. If we want direct access to the object features such as numerator, denominator, and the
A, B, C, D matrices, we need to extract them. To extract the A, B, C, D matrices, we use the
“ssdata” command.
>> [a, b, c, d] = ssdata(g ss)
We can now use these matrices to determine stability, controllability and other system properties.
the system can be transformed to other forms using the “canon” and “ss2ss” commands. The
“canon” command has the following syntax:
where type is either ’companion’ or ’modal.’ The latter diagonalizes the system (also known as the
modal realization), an the former converts it to companion form (a variation of the phase variable
or dual-phase variable forms)
>>p\a ∗ p
>>p\b
>>c ∗ p
7
Computer Aided Learning 7
System stability can be obtained by looking at the poles or eigenvalues of the system. MATLAB
has two commands to find poles and zeros. They are “pole” and “tzero.” The “pole” command
returns the poles and “tzero” returns the so-called transmission zeros of the system. If the A matrix
is available, we can determine asymptotic stability by finding the eigenvalues of A using the “eig”
command. For the system defined by
−2 1 1 1
ẋ = −3 0 0 x + 1 u
0 0 0 1
y = 2 −2 1 x
we get
>>pole(g)
>>eig(a)
>>tzero(g)
The system controllability and observability can be determined by examining the corresponding
matrices. MATLAB has “ctrb” abd “obsv” to obtain them. For the above-defined system, we get,
>>CO = ctrb(a, b)
>>OB = obsv(a, c)
We can then use “det” and “rank” to find the determinant and rank of these matrices.
Q: Determine the stability, controllability and observability of
a = [−1, −2, 0; 1, 2, 0; −2, −1, −3]; b = [1; 0; 0]; c = [1, 0, 1], d = 0
Solution of state equation can be obtained using the “lsim” and ‘initial” commands.
plots the response of a state-space system with input U (T ) and initial state X0 . The time sequence
T must be defined as a vector, and the input must be of the same size as T . Here is an example:
returns the output Y , the state vector X and time vector T used fo simulation, and no plot is drawn
on the screen.
[y, t, x] = lsim(gs, u, t, x0);
subplot(211), plot(t, x(:, 1)), subplot(212), plot(t, x(:, 2))
The “initial” command is used to solve for the zero input response (ZIR) of the state-space
system:ẋ = Ax subject to initial conditions:
IN IT IAL(SY S, X0, T, T F ) simulates and plots the time response from t = 0 to the final time
t − TF.
IN IT IAL(SY S, X0, T ) specifies a time vector T to be used for simulation
[Y, T, X] = IN IT IAL(SY S, X0, . . . ) returns the left hand side vectors but does not plot.