Introduction to MATLAB and Simulink for ECEN 2060 Tutorial

undefined
 
M
A
T
L
A
B
/
S
i
m
u
l
i
n
k
 
t
u
t
o
r
i
a
l
 
 
ECEN
 
2060
 
undefined
 
M
A
T
L
A
B
/
S
i
m
u
l
i
n
k
 
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
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
undefined
 
S
t
a
r
t
 
M
A
T
L
A
B
,
 
t
h
e
n
 
s
t
a
r
t
 
S
i
m
u
l
i
n
k
 
Click here 
to
 
start
 
Simulink
 
Choose Current
 
Directory
 
MATLAB 
commands
and scripts can be
executed
interactively in the
“Command
 
Window”
 
ECEN2060
 
3
undefined
 
S
i
m
u
l
i
n
k
 
L
i
b
r
a
r
y
 
B
r
o
w
s
e
r
 
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
 
CEN2060
 
E
 
4
undefined
 
C
o
n
s
t
r
u
c
t
i
n
g
 
a
n
d
 
s
i
m
u
l
a
t
i
n
g
 
a
 
s
i
m
p
l
e
 
c
i
r
c
u
i
t
 
m
o
d
e
l
 
i
R
 
v
ac
 
+
 
v
R
 
Circuit
 
equation:
 
i
R 
= 
(1/
R
)
 
v
ac
 
Simulink:
 
“Sine
 
Wave”
block
 
from
 
 
M
 
V = 
1
 
V
 
R
10
 
 
output
 
“Gain”
Block
 
from
 
Math
 
Operations
 
Sources
 
Drag an
 
drop
Sine 
Wave
 
block
from Sources
 
in
the
 
Library
 
ECEN2060
 
5
 
Drag an drop
Gain block from
Math
 
Operations
in the
 
Library
 
Drag an drop
Scope block
from Sinks in
 
the
Library
 
Connect block inputs and outputs according to
the circuit
 
equation
Double-click a block to change parameter
values
To 
better document the model, double-click on
the block name or on the connection line to
change block and signal names as
 
desired
undefined
 
C
o
n
s
t
r
u
c
t
i
n
g
 
a
n
d
 
s
i
m
u
l
a
t
i
n
g
 
a
 
s
i
m
p
l
e
 
c
i
r
c
u
i
t
 
m
o
d
e
l
 
Total 
simulation time (10 seconds in
this example) can be changed
 
here
 
Click here to start
 
simulation
 
Autoscale
 
Scope
para
m
eters
 
Double-click on the
 
Scope
block to display the output
waveform (current
 
i
R
)
Explore various menu options, block
properties, etc. For
 
example:
Add another axis to the
 
Scope
and display both 
i
R 
and
 
v
R
Repeat simulations for different
values of the sinewave amplitude
or 
frequency, 
or different
 
R
 
ECEN2060
 
6
undefined
 
N
o
t
e
s
 
Simulink blocks have zero, one or more inputs and
zero, one or more
 
outputs
Inputs and outputs are all considered
 
“signals”
Unlike 
circuit-oriented simulators (e.g. Spice),
Simulink has no knowledge of whether a signal is
voltage, current, power, torque, speed, …,
 
which
makes 
it 
a very general tool for simulations of 
various
dynamical systems,
 
but
requires a user to decide which signals are inputs 
and
which signals are outputs, and make block connections to
correctly model system equations; as a result, 
Simulink
block diagrams may not be as intuitive as circuit
 
diagrams
 
ECEN2060
 
7
undefined
 
A
n
o
t
h
e
r
 
e
x
a
m
p
l
e
 
M
a
k
e
 
s
u
r
e
 
y
o
u
 
h
a
v
e
 
d
o
w
n
l
o
a
d
e
d
 
p
v
1
.
m
d
l
 
a
n
d
 
f
i
n
d
M
P
P
.
m
 
t
o
a
 
w
o
r
k
i
n
g
 
f
o
l
d
e
r
 
(
f
i
l
e
s
 
a
r
e
 
a
v
a
i
l
a
b
l
e
 
o
n
 
t
h
e
 
c
o
u
r
s
e
 
w
e
b
s
i
t
e
,
M
A
T
L
A
B
/
S
i
m
u
l
i
n
k
 
p
a
g
e
)
 
Set
 
MATLAB
Current
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
undefined
 
S
i
m
p
l
e
 
P
V
 
c
e
l
l
 
S
i
m
u
l
i
n
k
 
m
o
d
e
l
 
p
v
1
.
m
d
l
 
+
 
v
PV
 
+
 
v
D
 
i
D
 
I
SC
 
Circuit
 
model
i
PV
 
Model
 
equations
 
PV
 
D
 
o
 
D
 
D
 
T
 
v
 
 
v
 
i
 
 
I
 
e
 
1
,
 
v
 
/
V
 
input
 
 
 
i
PV
 
 
I
SC 
 
i
D
 
output
 
Product block from
 
Math
 
ECEN2060
PV cell
 
characteristics
PV
 
PV
 
power
 
P
pv
 
V
pv
Ppv
Ipv
 
Operations
 
XY Graph
 
block
 
from
 
Sinks
 
Repeating
sequence
 
To
 
Workspace
 
Product
1e-9*(exp(u/26e-3)-1)
 
I-V
 
characteristic
 
V
p
v
 
Fcn block from
 
User-
Defined
 
Functions
 
block
 
from
Sources
 
Vpv
 
PN-junction
 
characteristic
 
1/1000
1000
 
Insolation
 
I
S
C
 
Id
 
I
pv
 
To 
Workspace
block from Sinks
sends
 
simulation
results to
MATLAB
workspace
 
for
further
 
Insolation 
to
ISC 
current
 
gain
 
processing
 
ECEN2060
 
9
 
Constant block from
 
Sources
p
v
1
.
m
d
l
 
S
i
m
u
l
i
n
k
 
m
o
d
e
l
 
Mux block from
Signal Routing
combines 3
signals into
 
one
 
vector
 
output
undefined
 
R
u
n
 
p
v
1
 
s
i
m
u
l
a
t
i
o
n
 
PV
 
Output
 
current
 
i
 
as a function
 
of
 
v
PV 
is immediately displayed in
another 
X-Y Plot
 
window
 
Output power 
P
pv 
(i.e the 
product
of 
i
PV 
and 
v
PV
) 
as a function of 
v
PV
is 
immediately displayed 
in a 
X-Y
Plot
 
window
 
Output power 
P
pv
, 
current 
i
PV
, 
voltage 
v
PV
, 
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
undefined
 
E
x
a
m
p
l
e
 
o
f
 
M
A
T
L
A
B
 
p
r
o
c
e
s
s
i
n
g
 
o
f
 
s
i
m
u
l
a
t
i
o
n
 
r
e
s
u
l
t
s
 
T
y
p
e
 
f
i
n
d
M
P
P
 
a
n
d
 
E
n
t
e
r
i
n
 
t
h
e
 
M
A
T
L
A
B
 
C
o
m
m
a
n
d
 
W
i
n
d
o
w
.
 
T
h
i
s
 
r
u
n
s
t
h
e
 
M
A
T
L
A
B
 
s
c
r
i
p
t
 
f
i
n
d
M
P
P
.
m
,
 
w
h
i
c
h
 
t
a
k
e
s
 
t
h
e
 
s
i
m
u
l
a
t
i
o
n
 
r
e
s
u
l
t
s
 
a
n
d
f
i
n
d
s
 
t
h
e
 
m
a
x
i
m
u
m
 
p
o
w
e
r
 
p
o
i
n
t
 
(
p
o
w
e
r
,
 
v
o
l
t
a
g
e
 
a
n
d
 
c
u
r
r
e
n
t
)
 
a
n
d
 
a
g
a
i
n
p
l
o
t
s
 
p
o
w
e
r
 
P
p
v
 
a
n
d
 
I
p
v
 
a
s
 
f
u
n
c
t
i
o
n
s
 
o
f
 
V
p
v
.
 
Double-click on the
findMPP.m 
file to 
open
the script and
 
examine
the 
MATLAB
 
code
 
ECEN2060
 
11
undefined
 
M
o
r
e
 
n
o
t
e
s
 
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
Slide Note
Embed
Share

MATLAB and Simulink are essential tools for technical computing and simulations in engineering and science fields. This tutorial provides a basic introduction to MATLAB and Simulink for ECEN 2060, covering topics such as programming, model-based simulation, and building simple circuit models. Students can learn to create and simulate models using standard Simulink blocks, execute MATLAB commands, and understand key functionalities to complete homework assignments effectively.

  • MATLAB
  • Simulink
  • ECEN 2060
  • Technical Computing
  • Engineering

Uploaded on Aug 03, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. MATLAB/Simulink tutorial ECEN 2060

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

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

  4. 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 E 4 CEN2060

  5. Constructing and simulating a simple circuit model Circuit equation: iR = (1/R)vac iR + SineWave block from Sources R 10 vR vac Simulink: output Gain Block from Math Operations V = 1 V M Connect block inputs and outputs according to the circuit equation Double-click a block to change parameter values To better document the model, double-click on the block name or on the connection line to change block and signal names as desired Drag an drop Sine Wave block from Sources in the Library Drag an drop Gain block from MathOperations in the Library Drag an drop Scope block from Sinks in the Library ECEN2060 5

  6. Constructing and simulating a simple circuit model Total simulation time (10 seconds in this example) can be changedhere Click here to start simulation Autoscale Double-click on the Scope block to display the output waveform (current iR) Scope parameters Explore various menu options, block properties, etc. For example: Add another axis to the Scope and display both iR andvR Repeat simulations for different values of the sinewave amplitude or frequency, or differentR ECEN2060 6

  7. Notes Simulink blocks have zero, one or more inputs and zero, one or more outputs Inputs and outputs are all considered signals Unlike circuit-oriented simulators (e.g. Spice), Simulink has no knowledge of whether a signal is voltage, current, power, torque, speed, , which makes it a very general tool for simulations of various dynamical systems, but requires a user to decide which signals are inputs and which signals are outputs, and make block connections to correctly model system equations; as a result, Simulink block diagrams may not be as intuitive as circuit diagrams ECEN2060 7

  8. Another example Make sure you have downloaded pv1.mdl and findMPP.m to a working folder (files are available on the course website, MATLAB/Simulink page) Set MATLAB Current 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

  9. Simple PV cell Simulink model pv1.mdl Circuit model Model equations 1) , iPV= ISC iD input iPV = I ( e v /V + =v + i v iD D T D o D PV ISC vPV vD output Product block fromMath Operations XY Graphblock fromSinks ECEN2060 PV cell characteristics PV power Repeating sequence blockfrom Sources Vpv Ppv PV Ipv Ppv Product To Workspace Fcn block fromUser- Defined Functions To Workspace block from Sinks sends simulation results to MATLAB workspacefor further processing I-V characteristic 1e-9*(exp(u/26e-3)-1) Vpv Vpv PN-junction characteristic Id Mux block from Signal Routing combines 3 signals into one vectoroutput 1/1000 1000 ISC Ipv Insolation to ISC current gain Insolation Constant block from Sources pv1.mdl Simulink model ECEN2060 9

  10. Run pv1 simulation Output power Ppv(i.e the product of iPVand vPV) as a function of vPV is immediately displayed in a X-Y Plot window Output current i vPV is immediately displayed in another X-Y Plot window as a function of 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

  11. 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 ofVpv. Double-click on the findMPP.m file to open the script and examine the MATLAB code ECEN2060 11

  12. 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

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#