EE 422
Matlab Documentation - For Matlab Assignment 1
For the first Matlab assignment, you will:
1) Be introduced to Matlab
2) Learn how to enter vectors and matrices in Matlab
3) Become familiar with the following Matlab functions: plot, semilogx, bode, step, and rlocus.
1 - Introduction
Matlab is another tool which you may choose to add to your engineering toolbox once you start to practice your profession away from the confines of Anderson Hall and maniacal professors who won't let you use it on examinations. Matlab won't make you any smarter, but it will free you from some of the mundane calculations required of engineers and allow you to beter visualize problems.
You can find Matlab on PC and UNIX platforms around the college of engineering. In particular, the PC lab and EWL lab both have Matlab. However, these locations contain slightly different versions of Matlab so be careful. This handout is written for the PC version of MATLAB but is also applicable to the workstation version of Matlab with minor modification. Once you have entered Matlab, you should presently view a screen with the Matlab copyright message and INFO, HELP and DEMO instructions. Most importantly, you should see the Matlab prompt, >>. This means you are ready to start using Matlab. To exit Matlab, just type quit.
2 - Matrices, Vectors, and Matlab
The most important facet of Matlab is its ability to work with vectors and Matrices. Let us now perform some simple Matrix manipulations. To Matlab, there is no difference between entering a matrix and entering a vector. We enter a matrix (or vector) by entering each row separated by semicolons with the entire matrix enclosed in square brackets. Let us enter a matrix A and a column vector x by performing the following command sequence:
A = [1 2;3 4] <cr>
x = [ 5;6 ] <cr>
Notice that Matlab echoes the matrix and the vector back to you in a nice readable format. We can perform arithmetic operations on matrices and vectors using the four basic operation symbols, addition (+), subtraction (-), multiplication (*) and division (/). Division?! ``How can we do division with matrices?'' you ask. Cake-city! Try the following,
I = A/A <cr>
What did you get? If you don't like this method of dividing matrices (as I don't) we can use the inv() function and multiplication. Try
I = A*inv(A) <cr>
Did you get the same result? Good! Try some more matrix manipulations on your own. Matlab won't hurt you if you make a mistake. Be bold.
3 - Functions of Matlab
It is the numerous functions of Matlab which make the program so powerful. The functions you will use in your first prelab are: plot, semilogx, bode, step, and rlocus. A brief description of the purpose of these functions follows. To obtain a more detailed listing, use the on-line help facility of Matlab by typing, help "function name'' <cr>.
plot(t,y) - plots a vector y vs. a vector t
[mag,phase]=bode(num,den,w) - returns the magnitude and phase of the transfer function G(s)=num/den for the frequency values in w. Caution: mag is not in dB so you will have to convert to dB by using the command, 20*log10(mag). The best way to space the frequency vector is to use the logspace command. For example, w=logspace(-1,2,100)<cr> generates 100 points evenly logarithmically spaced from 10-1 to 102 radians per second. The values of num and den are the polynomial coefficients of numerator and denominator of G(s) in descending order. For example, if G(s)=(8s2+15s+9)/(14s2+6) then num=[8 15 9]<cr> and den=[14 0 6]<cr>
semilogx(w,20*log10(mag)) - makes a semi-log plot of mag (in dB) vs. w where w is plotted on a log scale. semilogx(w,phase) would make a semi-log plot of the phase vs. w.
y=step(num,den,T) - returns the step response of the transfer function G(s)=num/den for the time values in T. The best way to generate T is to use the following command: T=[0:0.01:4]<cr> will generate a time vector from 0 to 4 in increments of 0.01.
r=rlocus(num,den,k) - generates the closed-loop poles for the negative unity feedback system described by

where G(s) is again described by G(s)=num/den. To plot out the root locus, use the command plot(r,'x')<cr> which will use the letter x to represent each closed-loop pole. To see a list of the poles and the corresponding values of the gain K which produced those poles, enter [r k]<cr>