Laboratory in Automatic Control Lab4

You might also like

Download as ppt or pdf
Download as ppt or pdf
You are on page 1of 16

Laboratory in Automatic Control

Lab 4 Control System Characteristics

Max and Min Function


Syntax
C=max(A) D=min(A)

MATLAB code
a=magic(3) b=max(a) c=min(a) d=max(b) e=min(c)

Residue Function
rn r1 r2 F s ... k s D s s p1 s p2 s pn N s

Syntax
[r,p,k]=residue(num,den)

MATLAB code
num=3 den=[1 6 5] [r,p,k]=residue(num,den)
F s 3 0.75 0.75 2 s 6s 5 s 5 s 1

Flow Control
Syntax
for 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)

Flow Control
MATLAB code
% 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)]

size(a)

Flow Control
Syntax
if expression statements end

MATLAB code
t=0:10; for i=1:length(t) if (t(1,i)>5)&(t(1,i)<8) c=t(1,i) end end

Flow Control
Syntax
if expression 1 statements 1 elseif expression 2 statements 2 elseif expression N-1 statements N-1 else statements N end

Flow Control
MATLAB code
a=[2 0 0 7;1 0 1 6] for i=1:2 for j=1:4 if mod(a(i,j),2)==0 even(i,j)=a(i,j); else odd(i,j)=a(i,j); end end end odd,even

Flow Control
Syntax switch switch_expr case case_expr statement, ..., statement case {case_expr1, case_expr2, case_expr3, ...} statement, ..., statement otherwise statement, ..., statement end

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); end end end odd,even

Flow Control
Example
R s

MATLAB code
10 s 2 ks
Y s

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<1.1) k,ymax end end plot(t,y,[0 5],[1.1 1.1],'--');grid xlabel('Time (sec)');ylabel('y(t)');

Flow Control

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<1.1) k,ymax,break end end plot(t,y,[0 5],[1.1 1.1],'--');grid xlabel('Time (sec)');ylabel('y(t)');

Flow Control

Lab 4 Homework
P1. Consider the transfer function (without feedback)
G s 5 s 2 2s 25

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. ( t 0 : 0.1:10 )

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 of k so 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, T s Y s R s , and generate the step response. Verify graphically that the steady-state error to a unit step input is zero. (Hint: search k within [1, 5], t 0 : 0.1 : 5)
Controller
R s

Plant

10 s

1 sk

Y s

Figure 1

You might also like