An
Introduction To Matlab
Using System Functions
-
Start Matlab.
-
We'll look at getting
a root locus
first.
-
Build an m-file.
In that file, type the following Matlab commands
-
Num = [1]
-
Den = [8 14 7 1]
-
Sys = tf(Num,Den)
-
rlocus(Sys)
-
Let's dissect this m-file.
-
Num = [1] defines a
numerator array of 1.
-
Den = [8 14 7 1] defines
a denominator array that represents s3 + 7s2
+ 14s + 8.
-
This is (s + 1)(s +
2)(s + 4) expanded.
-
Sys = tf(Num,Den) defines
a system representation for a system with Num for the numerator and Den
for the denominator.
-
rlocus(Sys) generates
data and plots the root locus for the system.
-
Now, you can save the
m-file and run it. You may need to be sure that the m-file can be
found, so you may need to set a path. Anyhow, we will assume that
you save the file as Mymfile.m
-
After you have the path
set, type Mymfile. You don't need the ".m" extension, and using it
will get you an error message.
-
If you check workspace
variables by using the whos
command, you will find that you have a tf
object in the workspace. That's
where the transfer function information is stored. Once the tf object
is defined you can use it in other commands like:
-
Once you have a tf object
defined in your workspace, you can use ltiview
(Linear, Time-Invariant View!) to look at a number of system analysis plots,
and you can choose from any of the tf objects in your workspace.
Try ltiview and experiment with it.
-
Next, we will look at
getting the closed loop step response
for the same system. Here's the system we will use. G(s) will
be taken as 1/(s + 1)(s + 2)(s + 4).
-
The m-file that will
generate a step response is:
-
CLNum = [1]
-
K = 2
-
CLDen = [8 14 7 1+K]
-
CLSys = tf(CLNum,CLDen)
-
step(CLSys)
-
Generate an m-file with
these commands and save it with a name of your choice.
-
Run the m-file and you
will get the closed loop step response.
-
Notice what you did
in this example.
-
You defined a system
with a specified numerator and denominator.
-
The denominator included
a variable term, 1 + K,
-
The gain, K, was set
in a separate statement. This statement could be removed as long
as the gain was set earlier within the workspace. If you remove this
statement, you can set the gain in the workspace, and re-run the m-file
repeatedly to check response for different gains.
-
Throughout this example,
we used a prefix "CL" to indicate that we have closed loop system variables.
-
Once CLSys is defined
in the workspace, you can use all of the usual commands available for any
tf object, including bode, nyquist, etc.
One final note. There is a control system demo. To get that
use a ctrldemo
command. There you can learn more about control system functions.