An Introduction To MatLAB & Simulink
An Introduction To MatLAB &
Simulink
Basic MatLAB CommandsMatLAB Syntax:Do Not Display Results: Comma
after command
Matrix Creation: [1 2; 3 4] = ⎥⎦
⎤⎢⎣
⎡4321
Basic MatLAB PlottingPlotting x and y: plot(x(),y())
Transfer FunctionTf([ Numerator Coefficients],[ Denominator Coefficients])
i.e. sys = tf([1],[1 3 2]);
231
2 ++=
sssys
Basic MatLAB CommandsConversionsTransfer Function To State Space [A,B,C,D] = tf2ss([Num],[Den]);
State Space To Transfer Function [Num, Den] = ss2tf(A,B,C,D);
Transfer Function To Zero/Poles [z,p,k] = tf2zp([Num],[Den]);
Zero/Poles To Transfer Function [Num, Den] = zp2tf(z,p,k);
State Space To Zero/Poles [z,p,k] = ss2zp(A,B,C,D,iu);
Zero/Poles To State Space [A,B,C,D] = zp2ss(z,p,k);
Basic MatLAB Commands
Basic MatLAB CommandsSymbolic Variables syms variable;
i.e. syms tLaplace Transforms laplace(function);
i.e. syms t;f = sin(t);laplace(f)
Inverse Laplace Transforms ilaplace(function);i.e. syms s;
f = (s+1)/(s^2+3s+2);ilaplace(f)
Basic MatLAB CommandsIntegration int(function, variable)
i.e. syms x;f = sin(x);int(f,x)
Differentiation diff(function, variable)i.e. syms x;
f = sin(x);diff(f,x)
Basic MatLAB Commands: Examples
MatLAB: Special
Characters
Basic MatLAB Plots
For the next three plots and simulink models, this is the system used:
Spring-Dashpot Mass Systemm=1 Input Sineb=4 Amp=50k=2 Freq=5
Fkxxbxm =++ &&&
( )( ) 24
12 ++
=sssF
sX
[ ] [ ]
[ ][ ] Fxy
Fxx
0011/1
01/41/2
10
+=
⎥⎦
⎤⎢⎣
⎡+⎥
⎦
⎤⎢⎣
⎡−−
=&
M
k
F
b
x
Basic MatLAB Plots – Bode Diagrams
A graphical wayof representingsystems througha magnitude andphase plot. Usingthe frequency domainthese plots can beobtained. Thesecan be used in:
Control Systems DynamicsElectronics
MatLAB Command: bode(sys) or bode(tf([Num],[Den]))
Basic MatLAB Plots – Root Locus Diagram
A diagram of the poles andzeros of a system,using a real andimaginary axes.
rlocus(sys) orrlocus(tf([Num],[Den]))
Basic MatLAB Plots – NyquistDiagram
This allows the prediction ofstability and Performanceusing the systemsopen loop form.
nyquist(sys) ornyquist(tf([Num],[Den]))
Introduction To Simulink
Simulink is a graphical representation of systems, differential equations, or problems encountered in engineering fields. Blocks can be assembled to reproduce almost anything as long as it can be modeled mathematically. Simulink has become an important part of aeronautical, astronautical, computer, electrical, and mechanical engineering programs and industries.
Simulink: Computer Integrated
Simulink can be used to control systems with the correct hardware and software. Texas Instruments and other electronic equipment manufacturers creates circuit boards for integration with a PC running Simulink. Output can be directly saved to a computer and analyzed to improve the model or write the report, more efficiently than in the past.
Simulink Toolboxes
These are some of the toolboxes simulink has.
We will use only the firsttoolbox ‘Simulink’ and‘Simulink Extras’ furtherdown.
Simulink: Most Commonly Used Blocks
These are the most commonly used blocks for Mechanical Engineers.
Simulink: Most Commonly Used Blocks
These are the most commonly used blocks for Electrical Engineers.
Simulink: Creation Of A Model1. A mathematical model has to be finished or a
prior simulation had to been performed.2. Create the block diagram by opening a new
model sheet and grabbing and dropping the blocks onto the model sheet.
3. Arrange blocks in the order that the model shows and connect them by dragging the arrow coming out of the block to the next block or clicking on both blocks while holding down ‘control’.
4. Make sure the model is correct before running the simulation. Then run the simulation.
Simulink: Creation Of A Model
Simulink: Model ParametersChanging the simulation parameters will help or hurt your model depending on what is changed.
Simulink: Output Of The Model
There are several ways to use or view the data received from the model.
Simulink: Example 1 & 2
Simulink: Example 3
Simulink: Lab 2 Diagram
Simulink: Moderate to Advanced Models
Research Model: Modeling and control of swimming robotic fish
An Introduction To MatLAB& Simulink