DK2781 AppC
DK2781 AppC
C.1 INTRODUCTION
MATLABÕ is a technical computing environment (program) designed for
numerical computation and visualization. Over the years it has become a
standard tool in many universities and research organizations for performing
mathematical calculations. Originally written to provide access to matrix
manipulation software, MATLAB has developed into a powerful tool to
simplify mathematical analysis.
In order to use MATLAB successfully, the student should under-
stand how to enter and manipulate variables, how to model control
systems in MATLAB, and how to produce plots and graphs depicting
the performance of control systems. This appendix is intended to guide
the student through the MATLAB functions which are useful in under-
standing and accomplishing these tasks. Students are encouraged to use
the documentation provided with MATLAB to explore more advanced
problems.
The commands shown here are valid for MATLAB version 6.1, Release
12.1, for Windows 98. There may be variations in other versions, or releases
for other platforms. Many of the commands shown here are in the Control
Systems Toolbox, which is available as an add-on to the basic MATLAB
program.
C.2 BASICS
MATLAB is a window-based workspace environment in which variables are
entered and manipulated. The MATLAB program is started by double click-
ing the MATLAB icon in the Windows desktop. This opens a window similar
to that shown in Fig. C.1. Commands are entered in the command window,
which is the inner window as shown on the right side of Fig. C.1. Two right
arrows (>>) is the command prompt, indicating that the program is ready
for the next command. Variables are created as they are entered, and are
stored in the workspace. Variable names must begin with a letter. A variable
to represent = 1.7 may be entered as follows:
alpha = 1.7;
Placing the variable name‘‘alpha’’to the left of the equal sign defines alpha as
whatever is on the right side of the equal sign.
MATLAB displays the variable upon entry unless a semicolon is placed
at the end of the line, that is,
Who
Your variables are:
alpha beta
C.2.1 Matrices
Matrices are entered a row at a time as follows:
A = [11 12 13
21 22 23
31 32 33]
The carriage return is implied at the end of each line and is not
explicitly shown in this text. MATLAB displays the variables upon entry
unless a semicolon is placed at the end of the line. Semicolons are also used
to simplify and conserve space. The same 3 3 matrix may be entered as
follows:
A = [11 12 13; 21 22 23; 31 32 33]; % Optional Comment
Matrices are indexed in (row, column) format. For example, a single element
of a matrix can be referenced as follows:
A(2,3)
This gives the result
ans =
23
x=
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 26
This command opens a plot window as shown in Fig. C.2. The window has
menu buttons across the top which allows the user to rescale, annotate, edit,
save, and print the plot.
FIGURE C.3 Multiple plots in one window: sine plot (top figure); cosine plot
(bottom figure).
Note that the titles and labels can be set from the command line or within
the plot window using the buttons across the top of the window. A number of
line styles and colors may be specified as described by the command:
help plot options
Typing ‘‘help’’ at the prompt will provide an outline of the help available in
the command window. More extensive help features are accessed through the
help menu button near the top of the MATLAB window.
is formed as follows:
num = [1 5];
den = conv([1 0], conv([1 3], [1 10]))
den =
1 13 30 0
2 3
ym
6 7
y ¼ Cx þ Du ¼ ym ¼ ½ 1 0 0 4 om 5 þ ½0ea ðC:4Þ
i_m
oz-in:
Bm ¼ 0:013 oz:-in: Kt ¼ 1:223
A
mV
Lm ¼ 0:75 mH Kb ¼ 0:905
rpm
J ¼ 0:085 104 oz:-in:-s2 Rm ¼ 24
2 3
0 1 0
A ¼ 40 1530 144000 5 ðC:5Þ
0 11:5 32000
2 3
0
B¼4 0 5 ðC:6Þ
1330
The following commands are used to enter the state space model, to
generate a linear time-invariant system model object, ‘‘sys2.’’ This state
space model object may be used for analysis like the transfer function system
model object. These commands have been saved in an m-file named ‘‘dcser-
vo.m’’ which is on the accompanying CDROM and can be executed by typing
‘‘dcservo’’at the command prompt.
A = [0 1 0 % Define the plant matrix
0 -1530 144000
0 -11.5 -32000];
B = [0; 0; 1330]; % Define the input matrix
C = [1 0 0]; % Define the output matrix
D = [0]; % Define the direct
% feedthrough matrix
sys2 = ss(A,B,C,D) % Generates a state space
% model object
which produces the state and output equations:
a=
x1 x2 x3
x1 0 1 0
x2 0 1530 1:44eþ005
x3 0 11:5 32000
b=
u1
x1 0
x2 0
x3 1330
c=
x1 x2 x3
y1 1 0 0
d=
u1
y1 0
continuous-time model.
C.4 ANALYSIS
C.4.1 Root Locus
The LTI system model object is used for analysis. The root locus for a unity
feedback system is presented in Chap. 7. The root locus is plotted in
MATLAB using the ‘‘rlocus’’command.
rlocus(sys) % Plots a root locus for sys
or
rlocus(sys, K) % Plots a root locus with
% user-specified vector
% of gains K
A more advanced interface for root locus analysis and design is the
‘‘SISOTOOL’’ interface. The ‘‘SISOTOOL’’ is a graphical user interface that
facilitates compensator design and is started with the command:
sisotool(’rlocus’,sys) % Startroot locus design tool
This command opens a new window, plots the root locus as shown in Fig. C.4,
and allows the user to specify a gain or add compensator components by
placing poles and zeros on the plot. Design constraints such as desired damp-
ing ratio or peak overshoot can be set within the tool and appear as bounds on
the plot.
A root-locus plot for a digital control system (see Chap. 15) is shown
in Fig. C.5.
C.5 SIMULATION
Control systems are commonly evaluated by simulating the response to a step
and an impulse inputs.The‘‘step’’and ‘‘impulse’’commands generate plots
of the step and impulse response respectively.When invoked with arguments
to the left of the equal sign as shown,
[y, t] = step(sys)
or
[y, t] = impulse(sys)
the output vector ‘‘y’’and time vector ‘‘t’’ that are generated automatically for
the plot, are defined in the workspace.These vectors are available then for use
elsewhere.
It is often desirable to specify the input as a function of time to generate
simulations that are more complex than the step and impulse inputs. This is
done by defining an input vector ‘‘u’’ and the corresponding time vector ‘‘t’’.
These vectors are used as inputs to the ‘‘lsim’’ command that simulates the
response of a linear system as follows:
t = [0:.1:10]; % Define a simulation time
% vector
u = [ones(1,51) zeros(1,50)]; % Define vector representing
% a pulse input
[y, t] = lsim(sys,u,t); % Simulate the response
plot(t, [y, u]) % Plot the response
This example also illustrates the ones and zeros commands. A vector
or matrix whose elements are all ones or zeros is defined with these
commands, using arguments which are the size of the vector or matrix
desired. A related function is ‘‘eye (rows, columns)’’ which defines an
identity matrix or a nonsquare matrix with ones on the principal diagonal
and zeros elsewhere.
eye(3)
ans=
1 0 0
0 1 0
0 0 1
eye(3,5)
ans=
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
C.5.1 Simulink
For simulations of more advanced system models, including nonlinear
models, it is useful to run Simulink. Simulink is a graphical simulation tool
which is started from the MATLAB command window by typing ‘‘simu-
link’’ at the prompt. This opens a window with the Simulink block library
and provides an option for creating a new Simulink model. Blocks are selected
and placed on the model workspace to create a system block diagram as shown
in Fig. C.10.
FIGURE C.9 Nichols chart diagram SISOTOOL window with grid and bounds.