Session 1. Getting started with MATLAB/ Simulink
Lecture notes for Advanced modeling and Control
General functions: | |
cd |
Change subdirectory |
demo |
Launch the demo (introduction) |
dir (what) |
Listof files in currentdirectory (or only M-files) |
help, helpwin |
Help! Help window |
load |
Load workspace |
lookfor |
Keyword search |
print |
Printgraph; can use pull-down menu |
quit |
Quit! |
save |
Save workspace |
who, whos |
Listof variables in workspace |
Calculation functions: | |
conv |
Convolution function to multiply polynomials |
size, length |
Size of an array, length of a vector |
Plotting functions: | |
axis |
Override axis defaultof plot |
grid |
Add grid to plot |
hold |
Hold a figure to add more plots (curves) |
legend |
Add legend to plot |
plot |
Make plots |
text (gtext) |
Add text (graphical control) to plot |
title |
Add title to plot |
xlabel, ylabel |
Add axis labels to plot |
Partial fraction and transfer functions: | |
poly |
Construct a polynomial from its roots |
residue |
Partial-fraction expansion |
roots |
Find the roots to a polynomial |
tf2zp |
Transfer function to zero-pole form conversion |
zp2tf |
Zero-pole form to transfer function conversion |
tf |
Create a transfer function object |
get |
Listthe objectproperties |
pole |
Find the poles of a transfer function |
zpk |
Create a transfer function in pole-zero-gain form |
Activities
Explore MATLAB user interface
Define a vector
x = [1 2 3 4 5 6 7 8 9 10]
.What are different ways you can define x? What happens when you put ; at the end?
Convert vector
x
into a column vector.Create vector
y = [0, 0.1, 0.2, ...., 2.0]
Create a 3 x 3 matrix.
Print the size of the matrix and lengths of vectors defined so far.
Define 3 polynomials
\[p_1(s) = s^2 - 5s + 4 \tag{1}\]
\[p_2(s) = s^2 + 4 \tag{2}\]
\[p_3(s) = s^2 - 5s \tag{3}\]
Calculate \(p_1(s)p_2(s)\)
Perform some mathematical computations on the vectors, matrices, and polynomials defined so far.
Solve Ax = b
A = [ 4 -2 -10; 2 10 -12; -4 -6 16];
b = [-10; 32; -16];
Check the solution
Calculate eigenvalues and eigenvectors.
Consider data:
x = [ 0 1 2 4 6 10];
y = [ 1 7 23 109 307 1231];
Fit a third-order polynomial. Plot the results
Explore MATLAB plotting capabilities
Create a MATLAB script, save, and load it to plot data in item 13.
Find roots of polynomial defined by
p = [1 5 4]
Search for a function to find roots of a nonlinear equation.
Find polynomial for the roots (-4, -1)
For the following transfer functions find partial fractions.
\[G(s) = \frac{q(s)}{p(s)}=\frac{2}{s^2+5s+4} \tag{4}\]
\[G(s) = =\frac{2}{s (s + 1) (s + 2) (s + 3)} \tag{5}\]
\[G(s) = =\frac{s^3 + 4s + 3}{s^4 - 7s^3 + 11s^2 + 7s -12} \tag{6}\]
Have fun with
zp2tf
,tf2zp
, andtf
commandsResponse of first order system: Compute and plot step response of following first order systems
\[y(s) = \frac{1}{5s + 1} \tag{7}\] \[y(s) = \frac{5e^{-10s}}{2.5s + 1} \tag{8}\]
Response of second order system: Compute and plot step response of following second order system. Show effect of \(\xi\) on response.
\[ G_p(s) = \frac{Y(s)}{U(s)} = \frac{K_p e^{-\theta s}}{\tau^2 s^2 + 2 \xi \tau s + 1} \tag{9}\]
\(K_p = 1\); \(\tau = 1\); \(\theta = 10\)
Solve differential equations using Simulink
An object falling under gravity
\[\frac{d^2 y}{dt^2}=-g \tag{10}\]
Compare the result with analytical solution \(y = -gt^2/2\)
Systems of ODEs
\[\frac{d^2 y}{dt^2} + 2\frac{dy}{dt} + 5y = 1 \tag{11}\]
\[\dot{y}(0) = y(0) = 0 \tag{12}\]
\[ \begin{bmatrix} \dot{x} \\ \dot{y} \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix} + \begin{bmatrix} -2 & -5 \\ 1 & 0 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \tag{13}\]
Citation
@online{utikar2023,
author = {Utikar, Ranjeet},
title = {Session 1. {Getting} Started with {MATLAB/} {Simulink}},
date = {2023-07-08},
url = {https://amc.smilelab.dev//content/notes/01-recap/in-class-activities.html},
langid = {en}
}