Python Command Explanation: Ae2235-I Aerospace Systems and Control Theory Command Summary

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

ae2235-I Aerospace Systems and Control Theory Command summary

Python command explanation


import control.matlab as ml Import statements. Note that you may vary these, this list
import matplotlib.pyplot as plt uses these imports to show which module provides a certain
import scipy as np command. Note that all of numpy is also in scipy.

np.absolute(x) Calculate the absolute value of x


np.angle(x) The angle of x in radians
ml.append(s1, s2) Combine systems with concatenated input and output
vectors
np.arange(x0, x1, step) Create a range, start, stop, step, excludes stop
np.arctan(x) Arctangent of x
np.arctan2(y, x) Four quadrant arc tangent
plt.axis([xmin, xmax, ymin, ymax]) Adjust axis of current plot
ml.bode(s1) Bode plot
plt.clf() Clear current figure
ml.connect(sys, Q, inp, outp) Connect inputs and outputs of a state-space system
np.cos(x) Calculate cosine of x
ml.damp(sys) Damping and frequency
dir(H) Listing of members and functions for an object
np.eig(M) Eigenvalue and eigenvector calculation
np.exp(a) e to the power of a
H.feedback(G) Calculate equivalent system for closed loop, H/(1+GH)
help(H) Help can be requested on any object (except string)
x.imag Find the imaginary part of x
ml.impulse(H, t) Calculate impulse response
np.log(x) Calculate natural logarithm of x
np.log10(x) Calculate 10 base logarithm of x
np.logspace(x0, x1, npoints) create a logarithmic range
np.linspace(x0, x1, npoints) create a range
ml.margin(sys) Phase and gain margin
np.matrix([[1, 2], [5, 6]]) Create a matrix
x.max() Return maximum element from x
x.min() Return minimum element from x
ml.minreal(s1) Remove cancelling pole/zero pairs from a transfer function,
or irrelevant states from a state-space system
ml.nyquist(h1) Nyquist plot
ml.parallel(s1, s2) Combine systems in parallel
plt.plot(t, y) plot data
plt.plot(t1, y1, t2, y2) Plot multiple signals in a single plot
H.pole() Calculate poles
x.real Find the real part of x
m.reshape( (nx, ny) ) Change the shape of a matrix
ml.rlocus(H) Root-locus plot. When clicking a point on the plot, data on
that point is given
np.roots(p) Calculate roots of polynomial
ml.series(s1, s2) Combine systems in series
plt.show() Show/complete current plot
m.shape Return the dimensions of a matrix
np.sin(x) Calculate sine of x
ml.ss(A, B, C, D) Create or convert to state-space system
ml.step(H, t) Calculate step response
ml.tf(num, den) Create a transfer function, convert to transfer function.
s = ml.tf([1, 0], [1]) Create Laplace variable
H.zero() Calculate zeros
sys.A Extract A (B, C, D) matrix of system sys

Zoomable plots in Spyder: Tools – Preferences – IPython console – Graphics, set backend=Automatic
Use “#%%” comments to create code cells, run with Ctrl-Enter or Shift-Enter
version 1.4 28/06/2018
ae2235-I Aerospace Systems and Control Theory Command summary

Matlab command explanation


abs(x) Calculate the absolute value of x
angle(x) The angle of x in radians
append(s1, s2) Combine systems with concatenated input and output vectors
atan(x) Arctangent of x
atan2(y, x) Four quadrant arc tangent
axis([xmin, xmax, ymin, ymax]) Adjust axis of current plot
bode Bode plot
clear Clean workspace
clf Clear current figure
connect(sys, Q, inp, outp) Connect inputs and outputs
cos(x) Calculate cosine of x
damp(sys) Damping and frequency
eig(M) Eigenvalue and eigenvector calculation
exp(a) e to the power of a
feedback(H, G) Calculate equivalent system for closed loop, H/(1+GH)
hold off When plotting new graphics, replace current plot
hold on Plot following graphics in existing plot
imag(x) Find the imaginary part of x
impulse(sys) Calculate the impulse response
log(x) Calculate natural logarithm of x
log10(x) Calculate 10 base logarithm of x
lsiminfo Calculate time response parameters
margin Phase and gain margin
max(x) Return maximum element from x
min(x) Return minimum element from x
minreal Remove cancelling pole/zero pairs from a transfer function
nyquist Nyquist plot
parallel(s1, s2) Combine systems in parallel
plot plot data
plot(t1, y1, t2, y2) Plot multiple signals in a single plot
pole Calculate poles
real(x) Find the real part of x
residue Partial fraction expansion
rltool Root-locus design gui
roots Calculate roots of polynomial
series(s1, s2) Combine systems in series
sin(x) Calculate sine of x
sisotool Single-loop design gui
ss Create or convert to state-space system
step Calculate step response
tf Create a transfer function, convert to transfer function.
tf(’s’) Create Laplace variable
zero Calculate zeros
sys.a Extract A (B, C, D) matrix of system sys
Some general advice:
Use “File” “New” “Blank M file” to work with the file editor
Use “%%” comments in an m-file to enable cell mode; with Ctrl+Enter, a cell is pasted into the Matlab
window and evaluated

version 1.4 28/06/2018

You might also like