bruce mayer, pe licensed electrical & mechanical engineer bmayer@chabotcollege
DESCRIPTION
Engr/Math/Physics 25. Chp10: SimuLink-1. Bruce Mayer, PE Licensed Electrical & Mechanical Engineer [email protected]. Learning Goals. Implement Mathematical Operations in MATLAB using SimuLink InterConnected Functional Blocks - PowerPoint PPT PresentationTRANSCRIPT
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt1
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PELicensed Electrical & Mechanical Engineer
Engr/Math/Physics 25
Chp10: SimuLink-
1
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt2
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Learning Goals Implement Mathematical Operations in
MATLAB using SimuLink InterConnected Functional Blocks
Employ FeedBack in the SimuLink Environment to numerically Solve ODEs
Create Simulations of Dynamic Control Systems using SimuLink Block Models• Export Simulation result to MATLAB
WorkSpace for Further Analysis
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt3
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
What is SIMULINK? SIMULINK is a tool for modeling,
analyzing, and simulating a wide variety of physical & mathematical systems, including those with nonlinear elements and those which make use of continuous and discrete time
Applications Can be found in Dynamic Control Systems, Signal Processing, Communications, and other time-varying systems.
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt4
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
More on SimuLink SimuLink is a Graphical Environment
where Math Operations are represented by BLOCK Icons• Allows for FEEDBACK of Control Vars
Since SimuLink is used to Analyze Dynamic (time-varying) Systems, there are many References to the Variable, ‘s‘• s follows from LaPlace Transforms
–Studied in 3rd year courses on Electrical, or Dynamic Mechanical, Systems-Control
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt5
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink Some More Since LaPlace Transforms, and
Dynamic-System Control Theory are beyond the scope of this Class, we will learn SimuLink by example
The Least intuitive Concept Employed will be FEEDBACK
0F dtetfstfL stThe LaPlace
Transform
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt6
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.2 Solution (book typo) Use FEEDBACK to Find y(t) for ODE
3
ydot7
y
1/5
Integ Scale
1s
2nd Integ
1s
1st Integ
secmol 3
735
mol 50
0
tdtdy
tfyyy
y
tf
y7
y3
ytf 7 yytf 73
yytf 7351
y ty
dtyytf 7351
dtdtyytf 7351
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt7
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-1 00sin10 ytdtdy
Fire Up Simulink Library Browser
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt8
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-2 00sin10 ytdtdy
Open “Model” Window/File
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt9
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-3 00sin10 ytdtdy
The “Untitled” Model” Window
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt10
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-4 00sin10 ytdtdy
Select “Sources” Library
Drag SineWave icon to Model Window
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt11
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-5 00sin10 ytdtdy
DoubleClick SineWave icon to Open Block-
Parameters Dialog Box
No ChangesNeeded
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt12
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-6 00sin10 ytdtdy
Select “Math Ops” Library
Drag Gain icon to Model Window
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt13
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-7 00sin10 ytdtdy
DoubleClick Gain icon to Open Block-Parameters
Dialog Box
Set Gainto 10
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt14
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-8 00sin10 ytdtdy
Set IC to Zero
Select Continous Library
Drag Integrator Block to Model Window
2X-Click the Icon to Open the DiaLog Box
Set the IC to Zero
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt15
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-9 00sin10 ytdtdy
Select “Sinks”Library Drag Scope Block to
Model Window
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt16
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-10 00sin10 ytdtdy
Connect The Block OutPuts & InPuts
Turns to Cross when Clik’d
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt17
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-11 00sin10 ytdtdy
Open the Config Parameters Dialog Box
Set 13s Stop-Time
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt18
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-12 00sin10 ytdtdy
Start Simulation Opens the Scope Display
Wait for “Bell” to Sound
2X Click Scope Clik Binoc’s to AutoScale
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt19
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink-13 00sin10 ytdtdy
Simulation Result
tz
zzdzyty
0sin100
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt20
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX 10.2-1 (1) Export Simulation
to WorkSpace for Plotting
Add/Subtract icons
2X-Clik “To WorkSpace” icon
00sin10 ytdtdy
SINKS Library
SOURCES Library
SIGNALROUTING
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt21
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX 10.2-1 (2) Export Result Plot the Result
t ty
0 2 4 6 8 10 12 140
2
4
6
8
10
12
14
16
18
20
t
y
Example 9.2-3: Soln to dy/dy = 10sin(t) • y(0) = 0
>> plot(y(:,1),y(:,2)), xlabel('t'), ylabel('y'), grid
00sin10 ytdtdy
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt22
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX 10.2-3 (1) (with a few mods) SimuLink Model
for Thus Simulate
204sin210 ytydtdy
Integrating, Find dzyzdy
tz
z
ty
02104sin2
Note that the variables are NOT Separable• y is on BOTH sides
dzyz
tyytz
z
ty
0
2
104sin2
2
Then The Model
Sine Wave Scope
1s
Integrator
10
Gain
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt23
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX 10.2-3 (2) → Model Parameters
Sine Wave Scope
1s
Integrator
10
Gain
Chg to 2
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt24
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
10.2-3 (3) → Scope Result (IC=2)
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt25
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
10.2-3 (4) → Scope Result (IC=0)
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt26
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX 10.2-3 (5) → OutPut Summary
plot(y_of_t(:,1), y_of_t(:,2)),grid0 2 4 6 8 10 12 14 16 18
-3
-2.5
-2
-1.5
-1
-0.5
0
0.5
1
304sin41 ytydtdy
ODE Parameters Changed
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt27
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX 10.2-3 (6) → Misc 204sin210 yty
dtdy
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt28
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLinkHelp
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt29
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink Help
3 Choices
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt30
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Naming SimuLink Blocks Double-Click on the BlockName
PlaceHolder Type in a DESCRIPTIVE Name
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt31
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX 10.4-1 (1)
10s Simulation
1s
Vt
1s
THETAtt
1s
THETAt Scope
80/9
Gain
cos
Cos Fcn
pi/50
Ang Accel
100s Simulation
100cos980 2tv
The SimuLink Model
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt32
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Caveat: Hidden Functions Many math Functions do NOT have
their own block. Instead they “Hide” in a PullDown menu in another icon.
ExamineSome of These.
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt33
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
TRIG Function Pull Down Box On MATH
OPRERATIONS can find SIN but not COS or TAN• They are HIDDEN in
the “TRIG” icon which just happens to have the label SIN– All the other Major
Trig Function reside in this block on a pull Down menu
Start with
• Change the Lower Function to COS
ty 3sin
ty 3cos : toChange
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt34
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Sin to Cos by PullDown 2X clik the “sin” icon to Reveal PullDown
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt35
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Sin to Cos by PullDown Clik on Cos
Changes Icon to the Cos Function• That was easy
Run Sin & Cos
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt36
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
All Done for Today
Running aHouse
Furnace
AVERAGE RESIDENTIAL
CUSTOMER
Nov. 2005
Oct. 2005
Percentage Change
from Oct. 2005
Nov. 2004
Percentage Change
from Nov. 2004
Therms of Gas Used
46 25 84.0% 46 0.0%
Cost of Gas Procurement (per therm)
$1.294 $1.231 5.1% $0.743 74.2%
Average Transportation Charge (per therm)
$0.41 $0.412 -0.3% $0.395 4.0%
Total Rate $1.704 $1.643 3.7% $1.137 49.8%
Public Purpose Program (PPP) Surcharge
$0.041 $0.041 0.0% $0.030 39.0%
Total Rate (including PPP Surcharge)
$1.746 $1.684 3.7% $1.167 49.6%
Total Natural Gas Bills (including PPP Surcharge)
$80.30 $42.10 90.7% $53.69 49.6%
One THERM is a unit of heating equal to 100,000 BTU.
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt37
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Bruce Mayer, PELicensed Electrical & Mechanical Engineer
Engr/Math/Physics 25
Appendix 6972 23 xxxxf
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt38
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Problem 10.15 ThermoStat
Control of Bldg Temp The Governing ODE
aTqRTdtdTCR Also Solve-For, and
Plot, T(t) for Given Parameters Where did this Eqn
Come from?
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt39
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (1) RELAY Block
• Relay Switch output between two constants
• Library → Discontinuities
Relay Parameters
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt40
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (2) T-Stat Temp Gain
• Gain Multiply the input by a constant
• Library → Math Operations
• For Case-2 will change Gain to 40
Fnce Gain
Parameter for Case-1
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt41
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (3) Ambient
Temperature Model• Sine Wave
Generate a sine wave
• Library → Sources
The Input Parameters for
t
hrFFTa 12
sin1050
Bias
Amplitude
Frequency
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt42
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (4) Sin Fcn
Parameters The Summing Node
• Sum Add or subtract inputs
• Library → Math Operations
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt43
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (6) Sum Parameters
1/RC Gain Block• 0.5 per HR
COPY the R*qm Gain Block in Model Space and change Parameters
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt44
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (7) Now the LaPlace
Integrator• Integrator
Integrate a signal • Library →
Continuous
Integ Parameters
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt45
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (8) MUX (Many-to-
One) for Ta and T• Mux Combine
several input signals into a vector or bus output signal
• Library → Signal Routing
MUX Parameters for
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt46
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (9) Use
ToWorkSpace to Send Ta & T to WorkSpace for Plotting• To Workspace
Write data to the workspace
• Library → Sinks
The ToWorkSpace Parameters
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt47
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (10) Connect the Dots
• Be sure to Include FeedBack Link to the ThermoStat
• Scope Added for Diagnostic PurposesBack Link to the ThermoStat
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt48
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15 (11) Compare Cases
• Small Furnace • Large Furnace
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt49
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15a (12) – Small Fnce% plot(tout, simout), xlabel('t (Hr)'), ylabel('T (°F)'), grid
0 5 10 15 20 25 30 35 40 45 5040
45
50
55
60
65
70
75Prob 9.15 • Thermostatic Control - Small Furnace
t (Hr)
T (°
F)
Ambient TempInside Temp
Unstable Inside Temp
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt50
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15a (13) – Large Fnce
0 5 10 15 20 25 30 35 40 45 5040
45
50
55
60
65
70
75
t (Hr)
T (°
F)
Prob 9.15 • Thermostat Control - Large Furnace
Ambient TempIInside temp
T-S
tat
Sco
pesi
mo
ut
Plo
t T
a &
T(t
)
1 s
Inte
gra
tor
IC =
70
°F
40 Fn
ce
R*q
m
Am
bie
nt
Te
mp
, T
a
0.5 1/R
CSTABLEInsideTemp
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt51
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15b (14) Part (B) → For
Stable Temp Control Find Energy Used
The Modify Previous Model
Separate Gain Blok R*qm to gain Access to qm
Scale qm to get scale comparable to T(t)
Copy & Modify Bloks• Gain• Integrator
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt52
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15b (15) The Energy Integrator Model
1028
qm
1s
TotalEnergy
T-Stat
1/100
Scale Output
0.0389
Rsimout
Plot Ta & T(t)
1s
IntegratorIC = 70°F
DeBugScope
AmbientTemp, Ta
0.5
1/RC
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt53
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.15b (16) – Energy Use
0 5 10 15 20 250
20
40
60
80
100
120
140Prob 9.15b • Total Energy Used - Large Furnace
t (Hr)
T (°
F), E
/100
(BTU
/Hr)
Inside TempFurnace Energy Use
Daily Use = 12400 BTU/Day = 0.124 Therm/Day → 21.7 ¢/DayBut This Fnce is Microscopic; My Fnce rating is 80 kBTU/Hr
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt54
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
10.2
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt55
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
10.2
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt56
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
10.2
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt57
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Prob 10.2
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt58
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink ↔ ODE45
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt59
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt60
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
SimuLink ↔ ODE45
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt61
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Problem 10.2-1
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt62
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Problem 10.2-1
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt63
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
Problem 10.2-1
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt64
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
0 2 4 6 8 10 12 14 16 18 20-1
0
1
2
3
4
5
6
t
y(t)
Bruce Mayer, PEENGR25 * 30Apr13
y(t)
1s
To yDotIC = 2
1s
To yIC = 5
yoft
To Workspace
Product
eu
MathFunction
13
Gain3
3
Gain2
7
Gain1
1/5
Gain-1/20
Constant
Clock
2013735 teyyy
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt65
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
P10.2 with various forcing fcns
2013
717.73.4sin50
:fcns Forcingte
ttt
tf
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt66
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
mck Exmpl (1) 2X Mass, Spring,
Damper System
How Do x1 & x2 respond to the SUDDEN Application of a UNIT Pull (1lb or 1N)?
C1
C2
x1
x2
f(Pull Force)
k1
k2
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt67
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX mck (2) m1 = 5 m2 = 3 c1 = 4 c2 = 8 k1 = 1 k2 = 2
C1
C2
x1
x2
f(Pull Force)
k1
k2
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt68
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX mck (3) 2X Mass, Spring,
Damper System
Set Simulation Time and check by 2X click Scope
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt69
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX mck (4) Simulation
Time = 10s
Auto Scaling the Axes
Positions have NOT Yet Stabilized• Try 100s StopTime
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt70
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
EX mck (5) StopTime = 100s
Stabilizes after about 25s• Use 25s for Stop
Final Offsets• x1 = 1.0• x2 = 1.25
[email protected] • ENGR-25_Lec-25_SimuLink-1.ppt71
Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
P10.2 with various forcing fcns
20137.73.4sin50
:fcns Forcingtett
tf