of 16
8/2/2019 Laboratory in Automatic Control Lab4
1/16
Laboratory in Automatic Control
Lab 4
Control System Characteristics
8/2/2019 Laboratory in Automatic Control Lab4
2/16
Max and Min Function
SyntaxC=max(A)
D=min(A)
MATLAB code
a=magic(3)b=max(a)
c=min(a)
d=max(b)
e=min(c)
8/2/2019 Laboratory in Automatic Control Lab4
3/16
Residue Function
Syntax
[r,p,k]=residue(num,den)
MATLAB code
1 2
1 2
n
n
N s rr rF s k sD s s p s p s p
...
num=3
den=[1 6 5]
[r,p,k]=residue(num,den)
23 0 75 0 75
6 5 5 1F s
s s s s
. .
8/2/2019 Laboratory in Automatic Control Lab4
4/16
Flow Control
Syntaxfor variable=expression
statements
end
MATLAB code% create a 3*4 zero matrix
% method 1
for i=1:3
for j=1:4
a(i,j)=0;end
end
b=a
% method 2
c=zeros(3,4)
8/2/2019 Laboratory in Automatic Control Lab4
5/16
Flow Control
% a(i,j) & a(i)
a=[6 5 4;3 2 1]
b=a;
size(a)
s1=min(size(a));
s2=max(size(a));
d=s1*s2;
for i=1:d
b(i)=i;end
c=b
d=[a(1,1) a(1,2) a(1,3);a(2,1) a(2,2) a(2,3)]
MATLAB code
size(a)
8/2/2019 Laboratory in Automatic Control Lab4
6/16
Flow Control
Syntaxifexpression
statements
end
MATLAB codet=0:10;
for i=1:length(t)
if(t(1,i)>5)&(t(1,i)
8/2/2019 Laboratory in Automatic Control Lab4
7/16
Flow Control
Syntax
ifexpression 1
statements 1
elseifexpression 2
statements 2
elseifexpression N-1
statements N-1
elsestatements N
end
8/2/2019 Laboratory in Automatic Control Lab4
8/16
Flow Control
MATLAB code
a=[2 0 0 7;1 0 1 6]
for i=1:2
for j=1:4
ifmod(a(i,j),2)==0
even(i,j)=a(i,j);else
odd(i,j)=a(i,j);
end
end
endodd,even
8/2/2019 Laboratory in Automatic Control Lab4
9/16
Flow Control
Syntax
switch switch_expr
case case_expr
statement, ..., statement
case {case_expr1, case_expr2, case_expr3, ...}statement, ..., statement
otherwise
statement, ..., statement
end
8/2/2019 Laboratory in Automatic Control Lab4
10/16
Flow Control
MATLAB code
a=[2 0 0 7;1 0 1 6]
for i=1:2
for j=1:4
switch mod(a(i,j),2)
case 1
odd(i,j)=a(i,j);
otherwise
even(i,j)=a(i,j);
endend
end
odd,even
8/2/2019 Laboratory in Automatic Control Lab4
11/16
Flow Control
Example MATLAB code
for k=0:0.1:5
sys_cl=feedback(tf([10],[1 k 0]),[1]);
t=0:0.1:5;
[y,t]=step(sys_cl,t);
ymax=max(y);
if(ymax>1.01)&(ymax
8/2/2019 Laboratory in Automatic Control Lab4
12/16
Flow Control
8/2/2019 Laboratory in Automatic Control Lab4
13/16
Flow Control
MATLAB code
for k=0:0.1:5
sys_cl=feedback(tf([10],[1 k 0]),[1]);
t=0:0.1:5;
[y,t]=step(sys_cl,t);
ymax=max(y);
if(ymax>1.01)&(ymax
8/2/2019 Laboratory in Automatic Control Lab4
14/16
Flow Control
8/2/2019 Laboratory in Automatic Control Lab4
15/16
Lab 4 Homework
P1. Consider the transfer function (without feedback)
when the input is a unit step, the desired steady-state value
of the output is one. Using the MATLAB step function,show that the steady-state error to a unit step input is 0.8.
( )
25
2 25G s
s s
0 0 1 10t : . :
8/2/2019 Laboratory in Automatic Control Lab4
16/16
Lab 4 Homework
P2. Consider the closed-loop control system shown in
Figure 1. Develop a MATLAB script to assist in the search
for a value ofkso that the percent over-shoot to a unit step
input is greater than 1 %, but less than 10%. The script
should compute the closed-loop transfer
function, , and generate the step response.
Verify graphically that the steady-state error to a unit step
input is zero. (Hint: search kwithin [1, 5], )
T s Y s R s
0 0 1 5t : . :
10
s
Controller
1
s k
Plant
R s Y s
Figure 1