Session 1. Getting started with MATLAB/ Simulink

Lecture notes for Advanced modeling and Control

Author
Published

July 8, 2023

Modified

July 26, 2024

Table 1: Useful functions
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

  1. Explore MATLAB user interface

  2. 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?

  3. Convert vector x into a column vector.

  4. Create vector y = [0, 0.1, 0.2, ...., 2.0]

  5. Create a 3 x 3 matrix.

  6. Print the size of the matrix and lengths of vectors defined so far.

  7. 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}\]

  8. Calculate \(p_1(s)p_2(s)\)

  9. Perform some mathematical computations on the vectors, matrices, and polynomials defined so far.

  10. Solve Ax = b

    A = [ 4 -2 -10; 2 10 -12; -4 -6 16];

    b = [-10; 32; -16];

  11. Check the solution

  12. Calculate eigenvalues and eigenvectors.

  13. Consider data:

    x = [ 0 1 2 4 6 10];

    y = [ 1 7 23 109 307 1231];

    Fit a third-order polynomial. Plot the results

  14. Explore MATLAB plotting capabilities

  15. Create a MATLAB script, save, and load it to plot data in item 13.

  16. Find roots of polynomial defined by p = [1 5 4]

  17. Search for a function to find roots of a nonlinear equation.

  18. Find polynomial for the roots (-4, -1)

  19. 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}\]

  1. Have fun with zp2tf, tf2zp, and tf commands

  2. Response 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}\]

  3. 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\)

  4. Solve differential equations using Simulink

  1. An object falling under gravity

    \[\frac{d^2 y}{dt^2}=-g \tag{10}\]

    Compare the result with analytical solution \(y = -gt^2/2\)

  2. Systems of ODEs

  1. \[\frac{d^2 y}{dt^2} + 2\frac{dy}{dt} + 5y = 1 \tag{11}\]

    \[\dot{y}(0) = y(0) = 0 \tag{12}\]

  2. \[ \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

BibTeX 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}
}
For attribution, please cite this work as:
Utikar, Ranjeet. 2023. “Session 1. Getting Started with MATLAB/ Simulink.” July 8, 2023. https://amc.smilelab.dev//content/notes/01-recap/in-class-activities.html.