| |
Many of our M-files files originated from the very old days of MATLAB when their
functions were less fully featured. Now, there is only a handful of tasks
that we really need to write an M-file. They are listed in the first table
on this page. Before you use any of them, read the comments at the
beginning of each file on how to use (or to modify) them.
Scripts that the text uses most often
| ezbo.m
|
Bode plot for functions with dead time. (The MATLAB default does not add phase lag.)
Usage: This M-file expects the transfer function named "G" and variable
tdead defined in the Command Window beforehand.
|
| recipe.m
& ciancone.m
|
Written as a function. A collection of the tuning relations
in Tables 6.1 and 6.2. Yes, it calculates all the PID settings
for you. The graphical Ciancone-Marlin relations are in its own ciancone.m.
It can be used on its own or be called from inside recipe.m.
Usage:
recipe(K, dead_time,time_constant), or
recipe(K, dead_time,time_constant,system_time_constant), or
recipe(ultimate_gain, ultimate_frequency)
ciancone, or
ciancone(K, dead_time,time_constant)
|
| spid.m
|
Template which can be modified to do most closed-loop time response
simulations with respect to a unit step change in the set point.
Usage: This M-file contains the definitions of the transfer functions,
but expects the values of all the variables (gains, time constants, etc.) to be
defined in the Command Window. |
The simpler (and less useful) M-files are left here more as examples
on how to write/use M-files to do repeated tasks. Some of them are so simple
that you should find it more flexible to do copy-and-paste from a scratch
file/window or from the Command History window. Or incorporate the most
important statements into other more useful or problem specific M-files.
Scripts that help to do time response calculations
PIDgui.m
& PIDfuc.m
|
A GUI demo that does all kinds of calculations related to
a unity feedback system with either a first or second order process. The
M-file uses a first order process if the Slider "tau 2" is set to zero.
Both M-files are needed to work together.
Usage: Just enter PIDgui in the Command Window
This M-file will then make use of the functions stored in PIDfuc.m. |
tzeta.m
tzeta2.m
|
Calculates features like overshoot and decay ratio of a second order
underdamped function.
tzeta.m uses the time period and damping ratio.
tzeta2.m looks for the second order polynomial. |
| tspec.m
|
Given any tranfser function which exhibits oscillatory behavior, estimates
overshoot, settling time, etc. from a unit step response. (Written as a function.
Not much use since the introduction of the LTI Viewer and MATLAB Version 6.) |
| tau2z.m
|
A two-line M-file. Calculates the time period and damping ratio of an
overdamped second order function with given time constants tau1 and tau2 |
dr2z.m
& z2dr.m
|
Simple M-files that do the calculations in Eqs. (3.29) and (5.19).
Convert between decay ratio and damping ratio. |
| pade2.m
|
Textbook definition of Pade approximation |
| trespon.m
|
Plots the step and impulse response of a given transfer function object G.
(Of course that's trivial!)
Really more as an exercise to understand the dominant poles.
|
| z2p.m
|
A two-line M-file. Generates the second order polynomial with given
time constant and damping ratio; calculates the roots |
Scripts that help to do root locus
| ezplace.m
|
Root locus with given open-loop poles and zeros |
| ezroot.m
|
Root locus with given transfer function G(s) |
| rfind.m
|
An extended script for using rlocfind() |
Scripts that help to do frequency response calculations
| ezbo.m
|
Duplicate listing of most often used M-files. |
| ezn.m
|
Nyquist plot. This version is preferred if you find the MATLAB default
too busy. |
| ezc.m
|
Mag/phase plot of a closed-loop function |
Scripts that help to do closed-loop time-domain simulations
sp1.m
sp2.m
|
Written on the basis of theoretical derivations. Do the time response
of a unit step change on the set point with proportional control on first
(sp1) and second (sp2) order processes |
| spid.m |
Duplicate listing of most often used M-files. |
initpid.m
chkgain.m
|
Initializes all the variables that you may use in other simulation M-files (e.g. spid.m).
List the current process and controller gains |
| recipe.m
& ciancone.m
|
Duplicate listing of most often used M-files. |
Scripts that help to do state-space calculations
| ode2phv.m
|
Constructs a phase-variable model from an o.d.e. |
| ss2phv.m
|
Transforms a state variable equation to phase-variables |
| stm.m
|
Finds the state transition matrix with Cayley-Hamilton theorem |
| ltstm.m
|
Finds the state transition matrix in Laplace transform domain |
Miscellaneous scripts
| routh.m
|
Constructs the Routh array; illustrative example |
| sserr.m
|
A function that calculates the error constants and steady state errors
of a system |
odesolver.m
lotka.m
|
Shows how to use Runge-Kutta for a set of o.d.e.'s lotka.m
is "called" by odesolver.m |
| addlabel.m
|
The simple-minded example described in MATLAB Session 1 |
| import.m |
Loads a data file. Really an example to illustrate the use of
input() and eval().
|
|