MATLAB Simulink Tutorial
MATLAB Simulink Tutorial
ECEN 2060
Spring 2008
MATLAB/Simulink
• MathWorks tools for technical computing and simulations, widely used
across various engineering and science disciplines
• MATLAB
Programming language and interactive environment well suited for
computing, algorithms, data processing and visualization
• Simulink
Environment for graphical, model-based simulation of dynamic systems
• Version 2007a (or 2007b) available in all computer labs in the
Engineering building
• Personal copy (full version, but for students only) can be purchased at
www,mathworks.com for $99. This is not required for ECEN2060
• Tutorial objectives: very basic introduction to the tools at the level
sufficient to understand ECEN2060 simulation models and do homework
assignments
ECEN2060 2
Start MATLAB, then start Simulink
Click here to start Simulink Choose Current Directory
MATLAB commands
and scripts can be
executed
interactively in the
“Command Window”
ECEN2060 3
Simulink Library Browser
• Library Browser gives access to various
standard or additional blocks that are
used to build more complicated models
• ECEN2060 models will be constructed
using standard Simulink blocks from the
Simulink library
• Click File - New – Model (or Ctrl-N) to
start a new model window
ECEN2060 4
Constructing and simulating a simple circuit model
Autoscale
ECEN2060 7
Another example: HW 3 Simulation problem
Set MATLAB
Make sure you have downloaded pv1.mdl and findMPP.m
Current
from HW3 assignment to a working folder
Directory to
the folder
where you
downloaded
pv1.mdl and
findMPP.m
Double-
click
pv1.mdl to
open the
PV cell
Simulink
model
ECEN2060 8
Simple PV cell Simulink model pv1.mdl
Circuit model Model equations input
iPV
ISC
iD +
vD
+
vPV
( )
i D = I o e vD / VT − 1 , v D = v PV
− − i PV = I SC − i D
output
Repeating Vpv
sequence Ppv
Ppv
Ipv PV
Output power Ppv, current iPV, voltage vPV, and simulation time are
stored in a “structure” variable PV, which is made available (using the
“To Workspace” block) for further processing in the MATLAB
Command Window
ECEN2060 10
Example of MATLAB processing of simulation results
Type “findMPP” and Enter in the MATLAB Command Window. This runs
the MATLAB script findMPP.m, which takes the simulation results and
finds the maximum power point (power, voltage and current) and again
plots power Ppv and Ipv as functions of Vpv.
Double-click on the
findMPP.m file to open
the script and examine
the MATLAB code
ECEN2060 11
More notes
• Simulink model and MATLAB Figure windows include a
“Copy” function in the “Edit” menu. This is useful for
reporting results: you can simply copy and paste your
models or graphical results into a Word or PowerPoint
document
• You may want to explore other options in the MATLAB
Figure window. For example, find out how add a grid,
change the line type, thickness or color, change the x-axis or
y-axis scales, etc.
• This tutorial is very limited in scope, just to get you started
with the tools we will be using to model and test various
electrical or electro-mechanical energy systems in
ECEN2060. You may want to browse through
Simulink/MATLAB HELP documentation to further explore
the tool capabilities
ECEN2060 12