An Introduction To MatLAB & Simulink
Basic MatLAB Commands MatLAB Syntax: Do Not Display Results: Comma after command Matrix Creation: [1 2; 3 4] =
⎡1 2⎤ ⎢3 4⎥ ⎣ ⎦
Basic MatLAB Plotting Plotting x and y: plot(x(),y())
Transfer Function Tf([ Numerator Coefficients],[ Denominator Coefficients]) i.e. sys = tf([1],[1 3 2]);
1 sys = 2 s + 3s + 2
Basic MatLAB Commands Conversions Transfer 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 Commands Symbolic Variables syms variable; i.e. syms t Laplace 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 Commands Integration i.e. syms x; f = sin(x); int(f,x) Differentiation i.e. syms x; f = sin(x); diff(f,x)
int(function, variable)
diff(function, variable)
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 System m=1 Input Sine b=4 Amp=50 k=2 Freq=5 x
k
M b
F
m&x& + bx& + kx = F X (s ) 1 = 2 F (s ) s + 4 s + 2 1 ⎤ ⎡ 0 ⎡0⎤ [x& ] = ⎢ [x] + ⎢ ⎥ F ⎥ ⎣− 2 / 1 − 4 / 1⎦ ⎣1 / 1⎦ y = [1 0][x ] + 0 F
Basic MatLAB Plots – Bode Diagrams A graphical way of representing systems through a magnitude and phase plot. Using the frequency domain these plots can be obtained. These can be used in: Control Systems Dynamics Electronics MatLAB Command: bode(sys) or bode(tf([Num],[Den]))
Basic MatLAB Plots – Root Locus Diagram A diagram of the poles and zeros of a system, using a real and imaginary axes. rlocus(sys) or rlocus(tf([Num],[Den]))
Basic MatLAB Plots – Nyquist Diagram This allows the prediction of stability and Performance using the systems open loop form. nyquist(sys) or nyquist(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 first toolbox ‘Simulink’ and ‘Simulink Extras’ further down.
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 Model 1. 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 Parameters Changing 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