Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
Control system analysis and design often requires a number of computational and graphical representation procedures, especially involving a systems time and/or frequency response. In this course, you will be introduced to a variety of procedures for analyzing control system that provide a great deal of information to the control systems engineer. The analytic procedures can be greatly simplied by the use of software such as Matlab. Modern software frees the control student from the tedious task of generating plots and frequency responses, and doing rote calculations, so that you can concentrate your eorts on the analysis and design issues.
The rst line assigns the value 2 to the variable x. The second line evaluates the expression 2 + 2. The third evaluates the expression ex+3 and assigns the resulting value to the variable y. The ; that ends the third command line suppresses output to the command window. In the rst two commands, the result is returned to the command window upon execution of the command. In the third, only the next command prompt >> comes up. The fourth command among these simple examples is a command for printing the current gure window, and the fth loads all the variables saved in a le saved_data.mat back into the Matlab workspace. The Matlab workspace is the set of all currently available variables (and their values). You can view the workspace by typing the command >> who or >> whos The command who lists the variables in the workspace; whos provides some information about each of the variables. If you are confused about the usage of any command in Matlab type help followed by the command name. For example, 1
>> help who shows documenation about the who command. Help is also available under Help on the menu bar of the command window, but often the typed command gets you want you want more quickly. This on-line help facility of Matlab is very informative and easy to use. You will frequently want to save data onto a oppy disk and load this data back in at your next lab session. You can save the current workspace to a le filename.mat in the current directory via >> save filename Loading this data back in is accomplished by >> load filename You can also specify a path to the le, if it is not in the current directory, via for example >> save C:\directory\filename >> load C:\directory\filename or >> save C:\directory name with spaces\filename >> load C:\directory name with spaces\filename To change the current directory, for instance to a disk in the oppy drive, click on the path browser on the Matlab command window toolbar (the symbol for the path browser is a connected set of le folders). Within the path browser you can adjust the current directory, and also manage the Matlab path. The path is a sequence of directories in which Matlab will look for command names and lenames that are called for in command statements Matlab is asked to execute.
(The % markers at the beginning of the remarks after the above commands are comment indicators. Matlab ignores everything on a command line after the %.) Vectors are analogous to one dimensional arrays and matrices are equivalent to two dimensional arrays. In vectors and matrices, the values are enclosed in square brackets, and rows are separated by semicolons. You can use Matlab to ll an array with a sequence of numbers. 2
>> v=[first:inc:last]; % first is the first number in the sequence. >> % inc is the difference between entries. >> % last is the end of the sequence. >> v = [1:2:9]; % Results in v taking value [1 3 5 7 9] Another function allows you to ll an array with values that are evenly spaced on a logarithmic scale. >> v=logspace(d1,d2); This will generate an array starting with 10d1 and ending with 10d2 , with a number of logarithmically spaced values in between. This is helpful in spacing frequency values for Bode diagrams. Basic arithmetic is handled in the manner that you would expect. However, with the basic element of the workspace a matrix, Matlab distinguishes between matrix operation and array operations. Matrix operations follow the normal rules of matrix arithmetic. Array operations are element-by-element operations. For example, >> [1 2]*[3 ; 4] ans = 11 is the result of the matrix multiplication 1 2 while >> [1 2].*[3 4] ans = 3 8 3 4 = (1)(3) + (2)(4) = 11,
sum of integer powers of the variable times the scalar coecients. Distinct polynomials can thus be specied by the set of coecients. When evaluating polynomials, Matlab uses an array vector whose entries are the coecients of the polynomial in question. The polynomial vector starts with the highest order coecient and ends with the zero order coecient (the constant term). For instance one can enter two polynomials to be used as the numerator and denominator of a linear time-invariant system. For example >> num = [1 0]; >> den = [1 2 2]; % numerator polynomial, (1 x s^1) + (0 x s^0) % denominator polynomial
would enter the numerator and denominator of the transfer function s G(s) = 2 . s + 2s + 2
(1)
One can then specify the system variable G as the system with this transfer function numerator and denominator by >> G = tf(num,den) Once this is entered you can determine system properties such as the location of system poles. For instance >> pole(G) ans = -1.0000 + 1.0000i -1.0000 - 1.0000i You may also use Matlab to do the polynomial analysis directly, via >> roots(den) ans = -1.0000 + 1.0000i -1.0000 - 1.0000i which computes the roots of the polynomial den. Polynomial algebra is also possible. To multiply two polynomials, use the conv function. >> product = conv(poly1,poly2); In this example poly1 and poly1 are two polynomials and product is their arithmetic product. If two systems are connected in cascade, the composite transfer function is the product of the two individual transfer functions, so this is useful for creating connections of systems in the workspace. Better yet, one can apply system algebra directly via commands such as series, parallel, and feedback. For example 4
>> G1 = tf([0 0 1],[1 3 2]) >> G2 = tf([1 2 1],[1 4 5]) >> H = series(G1,G2) forms H as H(s) = the series connection of G1 (s) = 1 2 + 3s + 2 s and G2 (s) = s2 + 2s + 1 . s2 + 4s + 5 1 s2 + 3s + 2 s2 + 2s + 1 , s2 + 4s + 5
For a list of commands for polynomial manipulation, type >> help polyfun For a list of commands on system forms, information, and manipulation, type >> help control and look at the sections Creation of LTI Models, Model Dynamics, and System interconnections.
-+ m
- K
G(s)
as K varies from 0 to . As an example, >> G = tf([1 2],conv([1 0],[1 1])); >> rlocus(G) generates the root locus plot shown in Fig. 1. Note that the zero of G at s = 2 is shown with a , and the two poles at s = 0 and s = 1 are marked by . It is also possible to use Matlab to determine the value of gain K that achieves pole locations on the root locus diagram. This goal is eected by the command 5
1.5
0.5
1.5 5
2 1 Real Axis
Figure 1: Sample root locus plot. >> rlocus(G) >> [k,poles]=rlocfind(G) Upon execution of th rlocfind command, the current gure window (which should contain the root locus plot that was just created) is brought up with a set of crosshairs superimposed. Using the mouse, you can position the crosshairs at a desired closed loop poles location, and then click on that location. The location that is selected is marked by + signs, the variable k is set to the gain that achieves these locations, and poles is set to a vector containing the values of all achieved closed loop poles for this k.
Bode Diagrams From: U(1) 60 40 Phase (deg); Magnitude (dB) To: Y(1) 20 0 20 90 95 100 105 110 2 10
1 0 1
10
10
10
Frequency (rad/sec)
Figure 2: Sample Bode plot. >> G = tf([1 2],conv([1 0],[1 1])); >> grid >> bode(G) producing the Bode plot shown in Fig. 2. Notice how in the plot of Fig. 2, the frequency axis covers the range from = 102 to = 101 . It may also be o interest to view the plot for a wider frequency range. The frequency range is controlled automatically by bode, but may also be manually set. A sequence of commands to view the Bode plot from = 103 to = 103 would be >> w = logspace(-3,3); >> grid >> bode(G,w) The result of these commands is shown in Fig. 3.
Bode Diagrams From: U(1) 100 50 Phase (deg); Magnitude (dB) To: Y(1) 0 50 100 90 95 100 105 110
2 0 2
10
10
10
Frequency (rad/sec)
Figure 3: Sample Bode plot with wider frequency range. The set of time values over which the responses are computed is determined automatically by Matlab. To override this, you can set your own range of values in a time variable t and use >> step(G,t) (similarly for impulse(G,t)).
xlabel ylabel axis grid semilogx semilogy loglog You can use the help <command name> facility for details on the exact syntax for these commands. An example: >> >> >> >> >> >> >> >> >> num=[1 0]; den=[1 2 2]; freq=logspace(-1,2,100); [mag,phase]=bode(num,den,freq*2*pi); semilogx(freq,20*log10(mag)) grid title(Bode Magnitude Plot) xlabel(Frequency (Hz)) ylabel(Magnitude (dB)) % System numerator % System denominator % Calculate frequency response % Plot with logarithmic x-axis % Title and label the plot.
This will make a semilog plot of the magnitude response, as shown in Fig. 4. You can also save your gure as a postscript le. The command >> print -dps myfigure creates the le myfigure.ps in the current directory. This can then be used to print the gure later or to include it in documents. To get encapsulated postscript les, use instead >> print -deps myfigure You can use help print to get further details.
10
20 Magnitude (dB)
30
40
50
60 1 10
10
10 Frequency (Hz)
10
10