Table of Contents
1
............................................ .......................... .......................... .......................... ...........................1 ..............1 −1 Introduction to Simulink ............................... 1.1 1.2 1.3 1.4 1.5 1.6
2
Mathematical Applications ............................. .......................................... .......................... .......................... .......................... .........................2 ............2 −1 2.1 2.2 2.3 2.4 2.5 2.6
3
An Application of Newton’s Second Law .............. ............................ ........................... ............................ .......................... ...........3-1 3-1 Ball Thrown Vertically Upward.................................... Upward................................................. .......................... ........................... ..................... .......3-3 3-3 Barge Pulled by Horse Teams ................... ................................ .......................... .......................... ........................... ........................... ............... 3-8 Rated Speed of an Automobile on a Highway Curve Curve ...................... ................................... .........................3-10 ............3-10 Train Traveling on a 3 Per Cent Grade....................... Grade.................................... ........................... ........................... ................... ......3-12 3-12 Spring with Upper Upper End Fastened to to a Rigid Support ........................... ......................................... .................... ......3-17 3-17
Thermodynamics and Fluid Mechanics Applications ...................................................4−1 4.1 4.2 4.3 4.4 4.5
5
Bouncing Ball .......................... ......................................... ............................ ........................... ........................... .......................... ............................ ................. 2 −1 Linear Programming ......................... ...................................... ............................ ............................... ................................ ............................ ..............2 ..2 −3 Moving Ladder .......................... .......................................... ............................. .......................... .......................... .......................... .........................2 ............2 −10 Conical Water Reservoir.............................. Reservoir............................................ ........................... ........................... ........................... .................... ....... 2 −12 Comparison of Alternate Proposals...................... Proposals................................... ........................... ............................ ......................... ...........2 2 −15 Valuation of a Depleting Asset Asset ........................... ........................................ .......................... ........................... ............................2 ..............2 −19
............................................ ............................. ............................. ............................ ...........................3 .............3 −1 Dynamics Applications .............................. 3.1 3.2 3.3 3.4 3.5 3.6
4
Simulink and its Relation Relation to MATLAB MATLAB ......................... ......................................... ............................. .......................... ............... ..1 1 −1 Modeling an Electric Circuit Circuit ............................ .......................................... ........................... .......................... .......................... .................. .....1 1 −1 Modeling a Fourth Fourth−Order Differential Equation............................... Equation............................................. .....................1 .......1 −14 Modeling the Solution Solution of Three Equations with Three Three Unknowns .......................1 .......................1 −18 Representing a Model Model as a Subsystem ............................ ............................................ ............................. ..........................1 .............1 −20 Simulink Demos .......................... ........................................ ............................ ........................... .......................... .......................... .......................1 ..........1 −20
Rise of a Liquid in a Capillary Tube ............... ............................ ............................. ................................ ............................ .............. ..4 4 −1 An Application of a Simplified Form of the Bernoulli Bernoulli Equation..................... Equation..............................4 .........4 −3 Takeoff Speed for an Aircraft ........................... ......................................... ........................... ........................... ........................... .................4 ....4 −4 An Application of the Bulk Modulus............................... Modulus............................................. ........................... .......................... ............... ..4 4 −6 Calculation of Fluid Fluid Flow in an Open Channel ............................. ........................................... ......................... ........... l4 −7
Assortment of Math and Engineering Applications ............................ ......................................... ..........................5 .............5 −1 5.1 5.2 5.3 5.4 5.5 5.6
Chemical Solutions ............................. .......................................... ........................... ........................... ........................... ........................... .................5 ....5 −1 Heat Flow............................... Flow............................................. ........................... .......................... .......................... ........................... ............................ ..................5 ....5 −3 Cantilever Beam Deflection Deflection ............................. ........................................... ........................... ........................... ........................... ................5 ...5 − 4 Tractrix Curve Example ........................... ......................................... ............................ ........................... .......................... .........................5 ............5 −6 Bessel Differential Equation ............................ .......................................... ........................... ........................... ........................... .................5 ....5 −8 Van der Pol Differential Equation.............. Equation ............................. ............................ .......................... .......................... ......................5 .........5 −9
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
i
5.7 Simple Pendulum..................................................................................................... 5 −11 5.8 Simple Oscillator...................................................................................................... 5 −13 5.9 Zero−Order Hold and First−Order Hold as Reconstructors .................................. 5 −14 5.10 Direct Form Realizations of a Digital Filter ........................................................... 5 −16 5.11 Series Form Realization of a Digital Filter ............................................................. 5 −18 5.12 Parallel Form Realization of a Digital Filter........................................................... 5 −20 5.13 3−bit Up / Down Counter..................................................................................... 5 −23 5.14 4−bit Ring Counter ................................................................................................ 5 −24 5.15 Mass−Spring-Dashpot............................................................................................. 5 −25 5.16 Cascaded Mass−Spring System............................................................................... 5 −28 5.17 Mechanical Accelerometer...................................................................................... 5 −29 5.18 Feedback Control Systems...................................................................................... 5 −30 5.19 Electric Circuit in Phasor Form ............................................................................. 5 −32 5.20 Application of the Superposition Principle ........................................................... 5 −34 5.21 Discrete Time Integration with Variable Amplitude Input................................... 5 −37 5.22 S−Function Example 1 ........................................................................................... 5 −39 5.23 S−Function Example 2 ........................................................................................... 5 −41 5.24 Concluding Remarks .............................................................................................. 5 −44
ii
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Appendixes A Introduction to MATLAB® .......................................................................................... A 1 −
A.1 MATLAB® and Simulink®..................................................................................... A −1 A.2 Command Window.................................................................................................. A −1 A.3 Roots of Polynomials................................................................................................ A −3 A.4 Polynomial Construction from Known Roots......................................................... A −4 A.5 Evaluation of a Polynomial at Specified Values....................................................... A −5 A.6 Rational Polynomials................................................................................................ A −7 A.7 Using MATLAB to Make Plots ................................................................................. A −9 A.8 Subplots .................................................................................................................. A −16 A.9 Multiplication, Division, and Exponentiation....................................................... A −17 A.10 Script and Function Files ......................................................................................A −25 A.11 Display Formats ..................................................................................................... A −29
B
Masked Subsystems ......................................................................................................... B −1 B.1 B.2 B.3 B.4
C
Masks Defined .......................................................................................................... B −1 Advantages Using Masked Subsystems..................................................................... B −1 Mask Features ........................................................................................................... B −1 Creating a Masked Subsystem .................................................................................. B −2
Commonly Used .............................................................................................................. C −1 C.1 Inport, Outport, and Subsystem .............................................................................. C −1 C.2 Ground..................................................................................................................... C −4 C.3 Terminator ............................................................................................................... C −6 C.4 Constant and Product.............................................................................................. C −7 C.5 Scope ........................................................................................................................ C −9 C.6 Bus Creator and Bus Selector ................................................................................ C −10 C.7 Mux and Demux .................................................................................................... C −18 C.8 Switch ..................................................................................................................... C −21 C.9 Sum......................................................................................................................... C −23 C10 Gain........................................................................................................................ C −25 C.11 Relational Operator .............................................................................................. C −26 C.12 Logical Operator ................................................................................................... C −27 C.13 Saturation.............................................................................................................. C −28 C.14 Integrator............................................................................................................... C −30 C.15 Unit Delay ............................................................................................................. C −35 C.16 Discrete−Time Integrator...................................................................................... C −37 C.17 Data Types and Data Type Conversion................................................................ C −40 C.18 Vector Concatenate .............................................................................................. C −49
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
iii
D
Continuous−Time ........................................................................................................... D −1 D.1 Derivative ................................................................................................................. D −1 D.2 Integrator.................................................................................................................. D −6 D.3 Integrator Limited .................................................................................................... D −6 D.4 Integrator Second Order.......................................................................................... D −8 D.5 Integrator Second Order Limited.......................................................................... D −11 D.6 PID Controller ....................................................................................................... D −12 D.7 PID Controller (2DOF) ......................................................................................... D −14 D.8 State−Space ............................................................................................................ D −19 D.9 Transfer Fcn ........................................................................................................... D −22 D.10 Zero−Pole .............................................................................................................. D −25 D.11 Transport Delay, Variable Time Delay, Variable Transport Delay ...................... D−29
E
Discontinuities .................................................................................................................E −1 E.1 Saturation................................................................................................................... E −1 E.2 Saturation Dynamic ................................................................................................... E −4 E.3 Dead Zone .................................................................................................................. E −5 E.4 Dead Zone Dynamic .................................................................................................. E −6 E.5 Rate Limiter ............................................................................................................... E −8 E.6 Rate Limiter Dynamic.............................................................................................. E −10 E.7 Backlash....................................................................................................................E −11 E.8 Relay .........................................................................................................................E −13 E.9 Quantizer..................................................................................................................E −15 E.10 Hit Crossing............................................................................................................E −16 E.11 Coulomb and Viscous Friction .............................................................................. E −18 E.12 Wrap to Zero........................................................................................................... E −19 E.13 Nonlinear Systems − Describing Functions ........................................................... E −20
F
Discrete ............................................................................................................................. F −1 F.1 Unit Delay ................................................................................................................. F −1 F.2 Integer Delay ............................................................................................................. F −1 F.3 Tapped Delay ............................................................................................................ F −3 F.4 Discrete Time Integrator........................................................................................... F −4 F.5 Discrete Transfer Fcn Block ..................................................................................... F −5 F.6 Discrete Filter............................................................................................................ F −8 F.7 Discrete Zero−Pole .................................................................................................. F −10 F.8 Difference................................................................................................................ F −11 F.9 Discrete Derivative.................................................................................................. F −12 F.10 Discrete State−Space.............................................................................................. F −13 F.11 Transfer Fcn First Order........................................................................................ F −16
iv
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
F.12 Transfer Fcn Lead or Lag .......................................................................................F −17 F.13 Transfer Fcn Real Zero ...........................................................................................F −20 F.14 Discrete FIR Filter ..................................................................................................F −21 F.15 Memory...................................................................................................................F −24 F.16 First−Order Hold ...................................................................................................F −25 F.17 Zero−Order Hold ...................................................................................................F −26 F.18 Discrete PID Controller .........................................................................................F −26 F.19 Discrete PID Controller (2DOF) ...........................................................................F −28
G
Logic and Bit Operations ...............................................................................................G −1 G.1 Logical Operator ......................................................................................................G −1 G.2 Relational Operator..................................................................................................G −1 G.3 Interval Test .............................................................................................................G −2 G.4 Interval Test Dynamic .............................................................................................G −3 G.5 Combinatorial Logic................................................................................................G −4 G.6 Compare to Zero......................................................................................................G −6 G.7 Compare to Constant..............................................................................................G −7 G.8 Bit Set.......................................................................................................................G −8 G.9 Bit Clear...................................................................................................................G −8 G.10 Bitwise Operator.....................................................................................................G −9 G.11 Shift Arithmetic....................................................................................................G −11 G.12 Extract Bits............................................................................................................G −12 G.13 Detect Increase......................................................................................................G −13 G.14 Detect Decrease ....................................................................................................G −14 G.15 Detect Change ......................................................................................................G −14 G.16 Detect Rise Positive ..............................................................................................G −15 G.17 Detect Rise Nonnegative ......................................................................................G −16 G.18 Detect Fall Negative..............................................................................................G −17 G.19 Detect Fall Nonpositive........................................................................................G −18
H
Lookup Tables ................................................................................................................. H −1 H.1 H.2 H.3 H.4 H.5 H.6 H.7 H.8 H.9
Lookup Table.......................................................................................................... H −1 Lookup Table (2−D) ............................................................................................... H −4 Lookup Table (n−D).............................................................................................. H − 5 Prelookup................................................................................................................ H −8 Interpolation (n−D) Using PreLookup .................................................................. H −9 Direct Lookup Table (n−D).................................................................................. H −10 Lookup Table Dynamic ........................................................................................ H −15 Sine and Cosine.................................................................................................... H −16 Function Lookup Table Generation .................................................................... H −18
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
v
I
Math Operations .............................................................................................................. I −1 I.1 Sum ............................................................................................................................. I −1 I.2 Add ............................................................................................................................. I −1 I.3 Subtract.......................................................................................................................I −2 I.4 Sum of Elements.........................................................................................................I −3 I.5 Bias.............................................................................................................................. I −3 I.6 Weighted Sample Time Math ....................................................................................I −4 I.7 Gain ............................................................................................................................ I −5 I.8 Slider Gain .................................................................................................................. I −5 I.9 Product........................................................................................................................I −6 I.10 Divide.........................................................................................................................I −6 I.11 Product of Elements .................................................................................................. I −7 I.12 Dot Product ...............................................................................................................I −8 I.13 Sign ............................................................................................................................ I −9 I.14 Abs ........................................................................................................................... I −10 I.15 Unary Minus............................................................................................................I −10 I.16 Math Function.........................................................................................................I −11 I.17 Rounding Function ................................................................................................. I −12 I.18 Polynomial ............................................................................................................... I −13 I.19 MinMax....................................................................................................................I −14 I.20 MinMax Running Resettable ..................................................................................I −15 I.21 Trigonometric Function ..........................................................................................I −16 I.22 Sine Wave Function ................................................................................................I −17 I.23 Algebraic Constraint................................................................................................I −18 I.24 Assignment .............................................................................................................. I −19 I.25 Reshape....................................................................................................................I −20 I.26 Squeeze.....................................................................................................................I −20 I.27 Matrix Concatenate.................................................................................................I −22 I.28 Permute Dimensions ...............................................................................................I −23 I.29 Complex to Magnitude − Angle................................................................................I −23 I.30 Magnitude− Angle to Complex................................................................................I −24 I.31 Complex to Real−Imag............................................................................................ I −25 I.32 Real−Imag to Complex............................................................................................I −26 I.33 Sqrt...........................................................................................................................I −27 I.34 Signed Sqrt...............................................................................................................I −28 I.35 Reciprocal Sqrt ........................................................................................................I −29 I.36 Find Nonzero Elements........................................................................................... I −30 I.37 Vector Concatenate.................................................................................................I −33
vi
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
J
Model Verification ........................................................................................................... J −1 J.1 Check Static Lower Bound .........................................................................................J −1 J.2 Check Static Upper Bound.........................................................................................J −2 J.3 Check Static Range .....................................................................................................J −2 J.4 Check Static Gap.........................................................................................................J −3 J.5 Check Dynamic Lower Bound....................................................................................J −4 J.6 Check Dynamic Upper Bound ...................................................................................J −5 J.7 Check Dynamic Range................................................................................................J −6 J.8 Check Dynamic Gap ...................................................................................................J −7 J.9 Assertion......................................................................................................................J −8 J.10 Check Discrete Gradient............................................................................................J −9 J.11 Check Input Resolution...........................................................................................J −10
K Model−Wide Utilities ..................................................................................................... K K.1 K.2 K.3 K.4 K.5
L
−1
Trigger−Based Linearization .................................................................................... K −1 Time−Based Linearization........................................................................................ K −3 Model Info................................................................................................................ K −6 Doc Text ................................................................................................................... K −8 Block Support Table................................................................................................. K −8
Ports & Subsystems ...........................................................................................................L −1 L.1 Inport, Outport, and Subsystem .............................................................................. L −1 L.2 Trigger....................................................................................................................... L −1 L.3 Enable (description).................................................................................................. L −1 L.4 Function−Call Generator......................................................................................... L −2 L.5 Atomic Subsystem .................................................................................................... L −3 L.6 Virtual and Nonvirtual Subsystems.......................................................................... L −7 L.7 Code Reuse Subsystem............................................................................................. L −7 L.8 Enable (added to subsystem block)......................................................................... L −11 L.9 Model...................................................................................................................... L −16 L.10 Configurable Subsystem ........................................................................................ L −17 L.11 Triggered Subsystem.............................................................................................. L −23 L.12 Enabled Subsystem ................................................................................................ L −26 L.13 Enabled and Triggered Subsystem ........................................................................ L −28 L.14 Function−Call Subsystem...................................................................................... L −32 L.15 For Iterator Subsystem........................................................................................... L −35 L.16 While Iterator Subsystem ...................................................................................... L −36 L.17 If and If Action Subsystem .................................................................................... L −38 L.18 Switch Case and Switch Case Action Subsystem.................................................. L −40 L.19 Model Variants ...................................................................................................... L −42
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
vii
L.20 Variant Subsystem..................................................................................................L −49 L.21 For Each Subsystem ...............................................................................................L −52 L.22 Function−Call Split ...............................................................................................L −57 L.23 Function−Call Feedback Latch..............................................................................L −58 L.24 Subsystem Examples ..............................................................................................L −59 L.25 S−Function.............................................................................................................L −62
M Signal Attributes .............................................................................................................M
−1
M.1 Data Type Conversion............................................................................................M −1 M.2 Data Type Duplicate...............................................................................................M −4 M.3 Data Type Propagation...........................................................................................M −6 M.4 Data Type Scaling Strip ..........................................................................................M −7 M.5 Data Conversion Inherited ....................................................................................M −8 M.6 IC (Initial Condition).............................................................................................M −8 M.7 Signal Conversion ..................................................................................................M −9 M.8 Rate Transition.....................................................................................................M −10 M.9 Signal Specification ..............................................................................................M −12 M.10 Bus to Vector .......................................................................................................M −13 M.11 Data Type Propagation Examples .......................................................................M −14 M.12 Probe....................................................................................................................M −15 M.13 Weighted Sample Time.......................................................................................M −17 M.14 Width...................................................................................................................M −18
N Signal Routing ................................................................................................................. N
−1
N.1 Bus Creator..............................................................................................................N −1 N.2 Bus Selector..............................................................................................................N −1 N.3 Bus Assignment .......................................................................................................N −1 N.4 Mux ..........................................................................................................................N −4 N.5 Demux......................................................................................................................N −4 N.6 Selector.....................................................................................................................N −5 N.7 Index Vector ............................................................................................................N −8 N.8 Merge .......................................................................................................................N −9 N.9 Environmental Controller.....................................................................................N −10 N.10 Manual Switch ......................................................................................................N −12 N.11 Multiport Switch...................................................................................................N −13 N.12 Switch....................................................................................................................N −14 N.13 From......................................................................................................................N −14 N.14 Goto Tag Visibility................................................................................................N −15 N.15 Goto ......................................................................................................................N −16 N.16 Data Store Read....................................................................................................N −18 N.17 Data Store Memory...............................................................................................N −18
viii
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
N.18 Data Store Write ..................................................................................................N −18 N.19 Vector Concatenate..............................................................................................N −20
O
Sinks..................................................................................................................................O −1 O.1 O.2 O.3 O.4 O.5 O.6 O.7 O.8 O.9
P
Outport................................................................................................................... O −1 Terminator.............................................................................................................. O −1 To File..................................................................................................................... O −1 To Workspace......................................................................................................... O −3 Scope....................................................................................................................... O −4 Floating Scope ........................................................................................................ O −5 XY Graph................................................................................................................ O −9 Display .................................................................................................................. O −11 Stop Simulation.................................................................................................... O −12
Sources ...............................................................................................................................P −1 P.1 Inport ........................................................................................................................P −1 P.2 Ground......................................................................................................................P −1 P.3 From File ...................................................................................................................P −1 P.4 From Workspace .......................................................................................................P −1 P.5 Constant....................................................................................................................P −2 P.6 Enumerated Constant...............................................................................................P −2 P.7 Signal Generator .......................................................................................................P −7 P.8 Pulse Generator.........................................................................................................P −9 P.9 Signal Builder..........................................................................................................P −10 P.10 Ramp ......................................................................................................................P −12 P.11 Sine Wave...............................................................................................................P −12 P.12 Step.........................................................................................................................P −14 P.13 Repeating Sequence ...............................................................................................P −14 P.14 Chirp Signal ...........................................................................................................P −15 P.15 Random Number ...................................................................................................P −16 P.16 Uniform Random Number....................................................................................P −17 P.17 Band Limited White Noise....................................................................................P −18 P.18 Repeating Sequence Stair.......................................................................................P −21 P.19 Repeating Sequence Interpolated..........................................................................P −22 P.20 Counter Free−Running .........................................................................................P −23 P.21 Counter Limited ....................................................................................................P −24 P.22 Clock ......................................................................................................................P −25 P.23 Digital Clock ..........................................................................................................P −26
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
ix
Q
User −Defined Functions................................................................................................. Q −1 Q.1 Q.2 Q.3 Q.4 Q.5 Q.6 Q.7
R
Fcn........................................................................................................................... Q −1 Interpreted MATLAB Function ............................................................................. Q −2 MATLAB Function ................................................................................................ Q −2 S−Function.............................................................................................................. Q −6 Level−2 MATLAB S−Function............................................................................... Q −6 S−Function Builder ................................................................................................ Q −9 S−Function Examples ........................................................................................... Q −10
Additional Discrete ..........................................................................................................R −1 R.1 Transfer Fcn Direct Form II.....................................................................................R −1 R.2 Transfer Fcn Direct Form II Time Varying ............................................................. R −2 R.3 Fixed-Point State −Space ...........................................................................................R −3 R.4 Unit Delay External IC ............................................................................................R −4 R.5 Unit Delay Resettable...............................................................................................R −5 R.6 Unit Delay Resettable External IC........................................................................... R −6 R.7 Unit Delay Enabled..................................................................................................R −7 R.8 Unit Delay Enabled Resettable ................................................................................R −8 R.9 Unit Delay Enabled External IC..............................................................................R −9 R.10 Unit Delay Enabled Resettable External IC .........................................................R −10 R.11 Unit Delay With Preview Resettable ....................................................................R −11 R.12 Unit Delay With Preview Resettable External RV ...............................................R −12 R.13 Unit Delay With Preview Enabled........................................................................R −13 R.14 Unit Delay With Preview Enabled Resettable ......................................................R −14 R.15 Unit Delay With Preview Enabled Resettable External RV .................................R −15
S
Additional Math − Increment / Decrement .................................................................. S −1 S.1 S.2 S.3 S.4 S.5 S.6
Increment Real World .............................................................................................. S −1 Decrement Real World ............................................................................................. S −1 Increment Stored Integer .......................................................................................... S −2 Decrement Stored Integer......................................................................................... S −3 Decrement to Zero Block .......................................................................................... S −3 Decrement Time To Zero ......................................................................................... S −4
T Simulink Extras................................................................................................................ T T.1 T.2 T.3 T.4 T.5
x
−1
Discrete Transfer Fcn with Initial States ..................................................................T −1 Discrete Transfer Fcn with Initial Outputs .............................................................. T −2 Discrete Zero−Pole (with initial states) ..................................................................... T −4 Discrete Zero−Pole (with initial outputs) ................................................................. T −5 Idealized ADC Quantizer ......................................................................................... T −7
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
T.6 Transfer Fcn (with initial states)............................................................................... T −8 T.7 Transfer Fcn (with initial outputs) ........................................................................... T −9 T.8 Zero−Pole (with initial states) ................................................................................. T −10 T.9 Zero−Pole (with initial outputs) ............................................................................. T −11 T.10 State−Space (with initial outputs) ......................................................................... T −11 T.11 Auto Correlator..................................................................................................... T −12 T.12 Cross Correlator.................................................................................................... T −13 T.13 Power Spectral Density.......................................................................................... T −14 T.14 Averaging Power Spectral Density......................................................................... T −16 T.15 Spectrum Analyzer................................................................................................. T −17 T.16 Averaging Spectrum Analyzer ............................................................................... T −17 T.17 Floating Bar Plot.................................................................................................... T −18 T.18 Clock...................................................................................................................... T −20 T.19 D Latch .................................................................................................................. T −20 T.20 D Flip Flop ............................................................................................................ T −21 T.21 S−R Flip Flop......................................................................................................... T −21 T.22 J−K Flip Flop ......................................................................................................... T −22 T.23 Switched Derivative for Linearization................................................................... T −23 T.24 Switched Transport Delay for Linearization......................................................... T −25 T.25 Polar to Cartesian Transformation ....................................................................... T −27 T.26 Cartesian to Polar Transformation ....................................................................... T −27 T.27 Spherical to Cartesian Transformation................................................................. T −28 T.28 Cartesian to Spherical Transformation................................................................. T −29 T.29 Fahrenheit to Celsius Transformation.................................................................. T −29 T.30 Celsius to Fahrenheit Transformation.................................................................. T −29 T.31 Degrees to Radians Transformation ..................................................................... T −30 T.32 Radians to Degrees Transformation ..................................................................... T −30
U Random Number Generation.........................................................................................U
−1
U.1 Random Numbers...................................................................................................U −1 U.2 An Example.............................................................................................................U −1
V Exercises............................................................................................................................ V
−1
W Solutions to the Exercises ...............................................................................................W
−1
X
Weighted Moving Average .............................................................................................. X −1
Y Table of Simulink Blocks ................................................................................................ Y Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
−1
xi
References.......................................................................................................................Ref −1 Index................................................................................................................................ IN −1
xii
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Chapter 1 Introduction to Simulink his chapter is an introduction to Simulink. This author feels that it is best to introduce Simulink in this chapter with a few examples. Tools for simulation and model−based designs are presented in the subsequent chapters. Some familiarity with MATLAB is essential in understanding Simulink, and for this purpose, Appendix A is included as an introduction to MATLAB.
1.1 Simulink and its Relation to MATLAB The MATLAB® and Simulink ® environments are integrated into one entity, and thus we can analyze, simulate, and revise our models in either environment at any point. We invoke Simulink from within MATLAB. We begin with a few examples and we will discuss generalities in subsequent chapters. Throughout this text, a left justified horizontal bar will denote the beginning of an example, and a right justified horizontal bar will denote the end of the example. These bars will not be shown whenever an example begins at the top of a page or at the bottom of a page. Also, when one example follows immediately after a previous example, the right justified bar will be omitted.
1.2 Modeling an Electric Circuit Example 1.1
For the electric circuit of Figure 1.1, u0 ( t ) *is the input and the initial conditions are i L ( 0 ) = 0 , −
−
and v c ( 0 ) = 0.5 V . We will compute v C ( t ) .
+ −
R
L
1Ω
1 ⁄ 4 H
+ C
vC ( t ) i(t)
4 ⁄ 3 F
vs ( t ) = u0 ( t )
−
Figure 1.1. Circuit for Example 1.1
For this example,
dv C i = i L = i C = C --------dt
(1.1)
and by Kirchoff’s voltage law (KVL),
* Throughout this text, the designation u0 ( t ) will be used to denote the unit step function. We will use u ( t ) to denote any other input to be consistent with the MATLAB and Simulink designations.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
1−1
Chapter 1 Introduction to Simulink The initials conditions [ x1 x2 ]' are specified at the MATLAB command prompt as x1=0; x2=0.5;
As before, to start the simulation we click the
icon, and to see the output waveform, we double
click the Scope block. Then we click on the Autoscale icon, and we scale the vertical axis as we did with the waveform of Figure 1.13. The waveform shown in Figure 1.16.
Figure 1.16. The waveform for the function v C ( t ) for Example 1.1 with the State−Space block.
1.3 Modeling a Fourth Order Differential Equation The state−space block is the best choice when we need to display the output waveform of three or more variables as illustrated by the following example. Example 1.2
A fourth−order network is described by the differential equation 4
3
2
d y d y d y dy --------- + a 3 --------- + a 2 -------- + a 1 ------ + a 0 y ( t ) = u ( t ) 4 3 2 dt dt dt dt
(1.27)
where y ( t ) is the output representing the voltage or current of the network, and u ( t ) is any input, and the initial conditions are y ( 0 ) = y' ( 0 ) = y'' ( 0 ) = y''' ( 0 ) = 0 . a . We will express (1.27) as a set of state equations b. It is known that the solution of the differential equation 4
2
d y d y -------- + 2 -------- + y ( t ) = sin t 4 2 dt dt
1−14
(1.28)
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Modeling a Fourth-Order Differential Equation subject to the initial conditions y ( 0 ) = y' ( 0 ) = y'' ( 0 ) = y''' ( 0 ) = 0 , has the solution 2
(1.29)
y ( t ) = 0.125 [ ( 3 – t ) – 3t cos t ]
In our set of state equations, we will select appropriate values for the coefficients a 3, a 2, a 1, and a 0 so that the new set of the state equations will represent the differential equation of (1.28) and using Simulink, we will display the waveform of the output y ( t ) . 1. The differential equation of (1.28) is of fourth−order; therefore, we must define four state variables that will be used with the four first−order state equations.
We denote the state variables as x 1, x 2, x 3 , and x4 , and we relate them to the terms of the given differential equation as x1 = y ( t )
We observe that
2
dy x 2 = -----dt
3
d y x 3 = --------2 dt
d y x4 = --------3 dt
x· 1 = x 2 x· 2 = x 3 x· = x 3
(1.30)
(1.31)
4
4
d y --------- = x· 4 = – a 0 x 1 – a1 x 2 – a 2 x 3 – a 3 x 4 + u ( t ) 4 dt
and in matrix form x· 1 x· 2
0
1
0
0
x1
0
0
1
0
x2
0
0
0
1
x3
0
– a 0 – a 1 – a 2 – a 3 x 4
1
=
x· 3 x· 4
0 +
0
(1.32)
u( t)
In compact form, (1.32) is written as Also, the output is
x· = Ax + bu
(1.33)
y = Cx + du
(1.34)
where
x· =
x· 1 x· 2
x· 3 x· 4
,
A=
0
1
0
0
0
0
1
0
0
0
0
1
–a 0 – a 1 – a 2 – a 3
x1 ,
x=
x2
0 ,
b=
0
x3
0
x4
1
,
and u = u ( t )
(1.35)
and since the output is defined as y ( t ) = x1
relation (1.34) is expressed as Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
1−15
Chapter 1 Introduction to Simulink x1 y = [ 1 0 0 0] ⋅
x2
(1.36)
+ [ 0 ]u( t)
x3 x4
2. By inspection the differential equation of (1.27) will be reduced to the differential equation of (1.28) if we let a3 = 0
a2 = 2
a1 = 0
a0 = 1
u ( t ) = sin t
and thus the differential equation of (1.28) can be expressed in state −space form as x· 1 x· 2
x· 3 x· 4
=
0 1 0 0 x1 0 0 1 0 x2 0 0 0 1 x3 – a 0 0 – 2 0 x 4
0 + 0 sin t 0
(1.37)
1
where
x· =
x· 1 x· 2
x· 3 x· 4
x1
0 1 0 0 ,
A=
0 0 1 0 0 0 0 1
,
x=
x2
0 ,
x3
– a 0 0 – 2 0
b= 0, 0
and u = sin t
(1.38)
1
x4
Since the output is defined as y ( t ) = x1
in matrix form it is expressed as x1 y = [ 1 0 0 0] ⋅
x2 x3
+ [ 0 ] sin t
(1.39)
x4
We invoke MATLAB, we start Simulink by clicking on the Simulink icon, on the Simulink Library Browser, we click the Create a new model (blank page icon on the left of the top bar), and we save this model as Example_1_2. On the Simulink Library Browser we select Sources, we drag the Signal Generator block on the Example_1_2 model window, we click and drag the State−Space block from the Continuous on Simulink Library Browser, and we click and drag the Scope block from the Commonly Used Blocks on the Simulink Library Browser. We also
1−16
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Modeling a Fourth-Order Differential Equation add the Display block found under Sinks on the Simulink Library Browser. We connect these four blocks and the complete block diagram is as shown in Figure 1.17.
Figure 1.17. Model for Example 1.2 with the parameters specified below
We now double−click the Signal Generator block and we enter the following in the Function Block Parameters dialog box the following: Wave form: sine Time (t): Use simulation time Amplitude: 1 Frequency: 2 Units: Hertz Next, we double−click the State−Space block and we enter the following parameter values in the Function Block Parameters: A: [0 1 0 0; 0 0 1 0; 0 0 0 1; −a0 −a1 −a2 −a3] B: [0 0 0 1]’ C: [1 0 0 0] D: [0]
Initial conditions: x0 Absolute tolerance: auto Now, we switch to the MATLAB command window and at the command prompt we type the following values: a0=1; a1=0; a2=2; a3=0; x0=[0 0 0 0]’;
We change the Simulation Stop time to 25 , and we start the simulation by clicking on the icon. To see the output waveform, we double−click the Scope block, then we click the Autoscale icon, and we obtain the waveform shown in Figure 1.18.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
1−17
Chapter 1 Introduction to Simulink
Figure 1.18. Waveform for Example 1.2
The Display block in Figure 1.17 shows the value at the end of the simulation time. Examples 1.1 and 1.2 have clearly illustrated that the State−Space is indeed a powerful block. We could have also obtained the solution of Example 1.2 using four Integrator blocks.
1.4 Modeling the Solution of Three Equations with Three Unknowns Example 1.3
We will create a model that will produce the simultaneous solution of three equations with three unknowns using Algebraic Constraint blocks found in the Math Operations library, Display blocks found in the Sinks library, and Gain blocks found in the Commonly Used Blocks library. The model will display the values for the unknowns z1 , z 2 , and z 3 for the system of the equations a 1 z 1 + a 2 z 2 + a 3 z 3 + k 1 = 0 a 4 z 1 + a 5 z 2 + a 6 z 3 + k 2 = 0
(1.40)
a 7 z 1 + a 8 z 2 + a 9 z 3 + k 3 = 0
The model is shown in Figure 1.19.
1−18
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Modeling the Solution of Three Equations with Three Unknowns
Figure 1.19. Model for Example 1.3 with the entries specified below
Next, at the MATLAB command prompt we enter the following values: a1=2; a2=−3; a3=−1; a4=1; a5=5; a6=4; a7= −6; a8=1; a9=2; k1= −8; k2=−7; k3=5;
After clicking on the simulation icon, we obtain the values of the unknowns as z1 = 2 , z 2 = – 3 , and z3 = 5 as shown in the Display blocks in Figure 1.19. An Algebraic Constraint block constrains the input signal f ( z ) to zero, outputs a value for z , and this value eventually produces a zero at the input. Thus, output is fed back to the input via a feedback path. We can improve the efficiency of the algebraic loop solver by providing an initial guess for the algebraic state z that is close to the final solution value. By default, the initial guess value is zero.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
1−19
Chapter 1 Introduction to Simulink 1.5 Representing a Model as a Subsystem An outstanding feature in Simulink is the representation of a large model consisting of many blocks and lines, to be shown as a single Subsystem block. Example 1.4
For instance, to group all blocks and lines in the model of Figure 1.19 except the display blocks, from the Edit drop menu we choose Create Subsystem and this model will be shown as in Figure 1.20* where at the MATLAB command prompt we have entered the following values: a1=5; a2=−1; a3=4; a4=11; a5=6; a6=9; a7= −8; a8=4; a9=15; k1=14; k2= −6; k3=9;
Figure 1.20. The model in Figure 1.19 represented as a subsystem
The Display blocks in Figure 1.20 show the values of z 1 , z 2 , and z 3 for the values that we specified at the MATLAB command prompt above.
1.6 Simulink Demos At this time, the reader with no prior knowledge of Simulink, should be ready to learn Simulink’s additional capabilities. We will explore other features in the subsequent chapters. However, it is highly recommended that the reader becomes familiar with the block libraries found in the Simulink Library Browser. Then, the reader can follow the steps delineated in The MathWorks Simulink User’s Manual to run the Demo Models beginning with the thermo model. This model can invoked by typing thermo at the MATLAB command prompt.
* The contents of the Subsystem block are not lost. We can double−click on the Subsystem block to see its contents. The Subsystem block replaces the inputs and outputs of the model with Inport and Outport blocks. These blocks along with the Subsystem block are described in Section 2.1, Chapter 2, Page 2−2.
1−20
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Chapter 2 Mathematical Applications
Clock
20 Constant 1
Sum 1
Scope Mux
24 Constant 2
Sum 2
1/3 Constant 3
Product
Figure 2.4. Simulink model for the constraints
aa
Figure 2.5. Plot of the constraints as displayed in Scope block in Figure 2.4
2−6
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Chapter 2 Mathematical Applications With the model in Figure 2.18 2.18 open, o pen, we enter the following followi ng values valu es at the MATLAB command comma nd prompt: PP=90000; SV=45000; n=15; AE=40950; i=0.045;
and the Display block in Figure 2.19 displays the value of the cost if Route A is chosen.
Figure 2.1 2.19. Model for Comparison of Alternate Proposals Proposals - Route Route A
Next we enter the following values at the MATLAB command prompt: PP=155000; SV=30000; n=15; AE=9400; i=0.045;
Figure Figure 2.20. Model for for Comparison Comparison of Alternate Alternate Proposals Proposals - Route Route B
2−18
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Ball Thrown Vertically Upward
Figure Figure 3.4. Model for for the ball thrown thrown vertically vertically upwar upwardd
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
3−7
Chapter 4 Thermodynamics and Fluid Mechanics Applications
Figure 4.2. Model for the rise of water in a capillary tube at temperature temperature
T
in
o
C
For the model in Figure 4.2, we have entered the values temp_table=[ 0
4−2
5
10
15
20
30
40
50
60
70
80
90 100];
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Chapter 5 Assortment of Math and Engineering Applications
Figure 5.6. The MATLAB Function block with the user −defined function
To the MATLAB Function block model we add the Clock block from the Sources library, and the Scope block from the Sinks library. We connect the three blocks and the model is now as shown in Figure 5.7, and we execute the simulation command.
Figure 5.7. Model for the beam deflection example
The waveform indicates the maximum def lection occurs when x ≈ 0.58 L . The exact result is obtained by taking the first derivative of the given function and setting it equal to zero as shown below. 3
2
2
2
2
d y ⁄ d x = 8x – 15 Lx + 6L x = x ( 8x – 15Lx + 6L ) = 0
Since x = 0 is not a viable solution, with L = 100 , we obtain 2
8x – 1500x + 60000 = 0 2
x – 187.5x + 7500 = 0
and syms x y; y=solve('x^2 −187.5*x+7500')
yields x = 57.85 , and y = 2.5997
5.4 Tractrix Curve A heavy object P is dragged along a rough horizontal plane by a string PQ of length a as shown in Figure 5.8.
5−6
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Discrete Time Integration with Variable Amplitude Input The final step is to add V ' C2 with V '' C2 . This addition is performed with the model in Figure 5.53 where the models of Figures 5.51 and 5.52 have been converted to Subsystems 1 and 2 respectively.
Figure 5.53. Model for the addition of V'C2 with V''C2
The model in Figure 5.53 can now be used with the circuit of Figure 5..48 for any values of the impedances Z .
5.21 Discrete Time Integration with Variable Amplitude Input It is showm in Appendix V, Exercise 16, that when the input signal is a pulse, a Discrete Forward Euler Integrator and a Discrete Trapezoidal Integrator will produce the same result. The model in Figure 5.54 uses an input that varies in amplitude during a sample period.
Figure 5.54. Model for Discrete Time Integration with variable amplitude input
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
5−37
S Function Example 2 The syntax for the diode_sfcn.m file above is the similar to that in Example L.20, Page L −62, Appendix L Next, we open a new model window, from the User−Defined Functions Library we drag an S−Function block into it, we double−click this block, in the Function Block Parameters dialog box we name it diode_sfcn , and we add and interconnect the other blocks shown in Figure 5.74.
Scope 1
Scope 2
Figure 5.56. Model and waveforms for temperature coefficients in semiconducto diodes using an S−Function block
5.23 S−Function Example 2 Equation (5.50) below is same as equation (5.20) in Section 5.7, Page 5 −12 2
d θ dθ M = J --------2 + c ------ + mg L sin θ dt dt
or
(5.50)
2
d θ 1 dθ --------2 = --- M – c ------ – mgL sin θ J dt dt ·
·
2
(5.51) 2
Let θ = x1 , and d θ ⁄ dt = x 2 . Then x 1 = x 2 , and x 2 = d θ ⁄ dt = ( 1 ⁄ J ) ( M – cx2 – mg Lx 1 ) . For this example we let J = 2 , M = 1 , c = 0.2 , and mgL = 2 . Then, our state−space equations are:
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
5−41
Appendix A Introduction to MATLAB® 600
400 Z 200 f o t r a p 0 y r a n i g a m-200 I
-400
-600
0
200
400
600
800 1000 1200 radian frequency w
1400
1600
1800
2000
Figure A.12. Plot for the imaginary part of the impedance in Example A.15
% The last six statements (next five lines) below produce the polar plot of z mag=abs(z);% Computes |Z|;... rndz=round(abs(z));% Rounds |Z| to read polar plot easier;... theta=angle(z);% Computes the phase angle of impedance Z;... polar(theta,rndz);% Angle is the first argument ylabel('Polar Plot of Z'); grid 90
1500
120
60 1000
150 Z f o t o l P r a l o P
30 500
180
0
210
330
240
300 270
Figure A.13. Polar plot of the impedance in Example A.15
Example A.15 clearly illustrates how powerful, fast, accurate, and flexible MATLAB is.
A −24
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Appendix B Masked Subsystems
Figure B.9. The Function Block Parameters window with the values of the constants
With the variables defined as above, the masked subsystem implements the quadratic equation 2
y = x – 5x + 6
and the roots of this equation are x 1 = 2 and x 2 = 3 . Our model is tested for the first root as shown in Figure B.10.
Figure B.10.
The Mask Editor also contains the Initialization tab that allows us to enter MATLAB commands that initialize the masked subsystem, and the Documentation tab that lets us define or modify the type description and help text for a masked subsystem. These tabs are not used in this example.
B−8
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Appendix C Commonly Used Example C.10
For the model in Figure C.26, at the MATLAB command prompt we have entered the statement T=75; the Function Block Parameters dialog box for the Switch block has been set for u2>Threshold , Threshold =T, in the Source Block Parameters dialog box for the y = 75 + sin x function block we have entered Am pl itud e= 1, Bias=75, Frequency =1 , Phase = 0 , and for the z = 75 – sin x function block we have entered Amplitude=1, Bias=75, Frequency =1 , Phase = – π . Unlisted parameters are left in their default states. With the simulation time set at 10 sec , the waveforms indicated on the Scope block in Figure C.27 show that at the end of the simulation time the z = 75 – sin x function has attained the value of 75.54 and the y = 75 + sin x function has attained the value of 74.46 . Since the Threshold value is set at 75 and the criterion is u2>Threshold , the Switch block outputs the value of 75.54 , that is, the value of the Display 3 block at the end of the simulation time.
Figure C.26. Switch block set for u2>Threshold, Threshold T=75
Figure C.27. Input waveforms for the model in Figure C.26
C−22
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Vector Concatenate
Figure C.59. Model for Example C.21
The Data Type Demonstration Simulink demo is another model using Data Type Conversion blocks. It can be accessed by typing datatypedemo at the MATLAB command prompt. Note: The MATLAB and Simulink built −in integer data types are limited to 32 bits. If we want to output fixed −point numbers in the range 33 and 53 bits, we can break the number into pieces using Gain blocks. For details please refer to the Simulink Help menu for an example.
C.18 Vector Concatenate The Vector Concatenate block is a special case of the Matrix Concatenate block described in Appendix I, where the block operates in Vector Concatenation Mode, Horizontal Matrix Concatenation Mode, or Vertical Matrix Concatenation Mode. In Vector Concatenation Mode, all input signals must be either row vectors ( 1 × m matrices) or column vectors (m × 1 matrices) or a combination of vectors and either row or column vectors. The output is a vector if all inputs are vectors. The output is a row or column vector if any of the inputs are row or column vectors, respectively.
Example C.22
We will create a model using a Vector Concatenate block to concatenate vertically the column vec-
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
C−49
PID Controller absence of an integral value prevents the system from reaching its target value due to the control action. In general, we add a proportional control to improve the rise time, we add a derivative control to improve the overshoot, and we add an integral control to eliminate the steady-state error. Then, we adjust each of Kp, Ki, and Kd until we obtain a desired overall response.
Example D.4
The model in Figure D.18 produces the outputs of a transfer function without and with PID control. The output waveforms are shown in Figure D19.
Figure D.18. Model for Example D.4
Figure D.19. Output waveforms for the model in Figure D.18 without and with PID control
The Simulink documentation contains the Anti-Windup Control Using a PID Controller , and Bumpless Control Transfer Between Manual and PID Control demos.They can be accessed by typing sldemo_antiwindup and sldemo_bumpless at the MATLAB command prompt. Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
D−13
PID Controller (2DOF) La s
R a
Jm s T m ( s ) = K I a ( s ) i
Va ( s )
Ia ( s )
ω m ( s )
V b ( s ) = K b ω m ( s )
θm ( s ) ( sha ft angle )
Bm
Armature circuit
Inertial load Figure D.20. Armature circuit and inertial load for a DC motor
Figure D.21 is the block diagram of the DC motor where T L ( s ) = load torque , i.e., the torque that the motor has to overcome for motion to occur, and Figure D.22 is a model for this block diagram where the integrator block on the right side has been omitted for simplicity. TL ( s ) Va ( s )
1 Ia ( s ) ---------------------L a s + R a
+
K i
Tm ( s )
−
1 ---------------------Jm s + Bm
ω m ( s )
1 --s
θm ( s )
− V b ( s )
K b
Figure D.21. Block diagram of a DC motor
Figure D.22. Model for the block diagram in Figure D.21
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
D−15
Appendix D Continuous Time
Figure D.45. Model to illustrate the use of the Variable Time Delay block
Figure D.46. Input and output waveforms for the model in Figure D.45
Example D.12
The model in this example compares the distance traveled by two automobiles that departed from point A, one three hours after the other at different speeds, and stopped at point B ten hours later.
D−30
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Appendix E Discontinuities
his appendix is an introduction to the Discontinuities Blocks library. This is the third library in the Simulink group of libraries and contains the blocks shown below. Their functions are illustrated with examples. In this appendix we will briefly describe the function of each block included in this group, and their application will be illustrated with examples. The complete description of each block can be found in the Simulink documentation. For emphasis, the icon of each Simulink block described in its section is shown in drop shadows.
E.1 Saturation The Saturation block sets upper and lower bounds on a signal. When the input signal is within the range specified by the Lower limit and Upper limit parameters, the input signal passes through unchanged. When the input signal is outside these bounds, the signal is clipped to the upper or lower bound. When the Lower limit and Upper limit parameters are set to the same value, the block outputs that value. This block is also described in Section 2.13, Chapter 2, Page 2−21.
Example E.1 *
The model shown in Figure E.1 uses a Saturation block whose upper limit is clipped at +0.25 and the lower limit is clipped at – 0.25 . The input is a sine function with amplitude 1 and frequency 0.25 Hz . The input and output waveforms are shown in Figure E.2.
Figure E.1. Model for Example E.1
* Another example with the Saturation block is presented as Example 2.13, Chapter 2, Page 2−21.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
E−1
Appendix E Discontinuities E.11 Coulomb and Viscous Friction As we know from physics, friction is a force that resists the relative motion or tendency to such motion of two bodies in contact. Friction is undesirable in some parts of rotating machinery such as bearings and cylinders, but very beneficial in the automotive industry such as the design of brakes and tires. Theoretically, there should be no friction in a motor with zero velocity, but in reality, a small amount of “static” (no velocity) friction known as Coulomb friction, is always present even in roller or ball type anti −friction bearings. Viscous friction, on the other hand, is friction force caused by the viscosity of lubricants. The Coulomb friction function, the Viscous friction function, and the combined Coulomb plus Viscous friction functions are illustrated in Figure E.21. Friction force F fc
Friction force
μC Fn
Friction force
F fc v
μV v Fn
v Sliding velocity
v Sliding velocity
(a) Coulomb friction
F fv
(b) Viscous friction
v Sliding velocity
(c) Coulomb plus Viscous friction
Figure E.31. Coulomb friction and Viscous friction functions
The Coulomb friction function is defined as F fc = ± μ C F n
(E.4)
where μ C is the Coulomb friction coefficient. The Viscous friction function is defined as F fv = μ v vF n
(E.5)
and the Coulomb plus Viscous friction is defined as F fc + fv = μ v vF n ± μ C F n
(E.6)
The Coulomb and Viscous Friction block produces an offset at zero and a linear gain elsewhere. The offset corresponds to the Coulombic friction; the gain corresponds to the viscous friction. Coulomb friction force can be represented by at least four different continuous functions. Each of these functions involves one constant that controls the level of accuracy of that function's representation of the friction force. Simulink uses the default values [ 1 3 2 0 ] for the offset (Coulomb friction value). For the signal gain (coefficient of viscous friction) at nonzero input points the default is 1. For a detailed description, please refer to the Simulink documentation.
E−18
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Transfer Fcn Lead or Lag ans = (5*z + 5)/(6*z + 4)
or 2.5 ( z + 1 ) -----------------------3z + 2
The model and the outputs are shown in Figure F.22.
Figure F.22. Model and waveforms for Example F.11
F.12 Transfer Fcn Lead or Lag Lead and lag compensators are used quite extensively in control systems. A lead compensator can increase the stability or speed of response of a system; a lag compensator can reduce (but not eliminate) the steady state error. Depending on the effect desired, one or more lead and lag compensators may be used in various combinations. Lead, lag, and lead/lag compensators are usually designed for a system in transfer function form. The Transfer Fcn Lead or Lag block is a discrete−time lead or lag compensator. The instantaneous gain of the compensator is unity, and the DC gain is equal to ( 1 – z ) ⁄ ( 1 – p ) , where z is the zero and is the pole of the compensator. The block performs as a lead compensator when 0 < z < p < 1 , and performs as a lag compensator when 0 < p < z < 1 . In general, the transfer function of a lead compensator is defined as
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
F−17
Discrete FIR Filter That is, the number of moving average sequence is equal to n – k + 1 values. Thus, with k = 4 of a ten-value ( n = 10 ) sequence, the moving average sequence has n – k + 1 = 10 – 4 + 1 = 7 values.
Example F.14
The price of a particular security (stock) over a 10−day trading period is as follows: 77 80 82 85 90 84 81 82 86 79
where the last value is the most recent. We will create a model of moving averages with k = 5 over this 10 − day trading perio d. For this example, the moving av erage sequen ce has n – k + 1 = 10 – 5 + 1 = 6 values. The model is shown in Figure F.30, and the settings for the Function Block Parameters dialog box for the Discrete FIR Filter 1 block is shown in Figure F.31. The settings for the remaining Discrete FIR Filter blocks are shown in the model.
Figure F.30. Model for Example F.14
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
F−23
Appendix G Logic and Bit Operations Example G.2
Let
x
represent an array of numbers or a time-varying signal. The model in Figure G.2 proves that
in general,
a v e( x
2
2
) ≠ ( xav e ) . The term on the left implies that x must first be squared and the
average value is then to be found. The term on the right implies that the average value of x must be found first, and then the average must be squared. For this model each of the elements of the array [1 2 3 4 5] is first squared and the mean (average) value is found to be 11 . Then, the mean is first found and its square is computed and found to be 9 . Since the results are different, the Relational Operator block outputs logical 0 .
Figure G.2. Model for Example G.2
G.3 Interval Test The Interval Test block performs a test to determine if a signal is in a specified interval. The block outputs TRUE if the input is between the values specified by the Lower limit and Upper limit parameters. The block outputs FALSE if the input is outside those values. The output of the block when the input is equal to the Lower limit or the Upper limit is determined by whether the boxes next to Interval closed on left and Interval closed on right are selected in the dialog box.
Example G.3
For the model shown in Figure G.3 the Upper limit parameter for the Interval Test block is set to the binary value [ 01111111 ] , the Lower limit is set to the binary value [ 10000000 ] , and the boxes next to Interval closed on left and Interval closed on right are selected in the dialog box. The largest positive value and the smallest negative value have been selected and the Interval Test block outputs TRUE (1).
G−2
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Appendix H Lookup Tables
his appendix is an introduction to the Lookup Tables Group of blocks and only a brief description is given. A complete description of each block can be found in the The Math Works Simulink documentation. Their functions are illustrated with examples. The terminology monotonically increasing * is used throughout this chapter, and it is defined in the footnote below.
H.1 Lookup Table The Lookup Table block computes an approximation to a function y = f ( x ) where the data vectors x and y are given, and it is required that the x data vector must be monotonically increasing. Moreover, the length of the x and y data vectors must be the same. The Simulink documentation states that in a future release, the Lookup Table block will be removed from the Lookup Tables library and replaced with a 1 −D version of the Lookup Table (n−D) block. Existing models that contain the Lookup Table block continue to work for backward compatibility. Example H.1
The model in Figure H.1 uses a Lookup Table block to find the radioactive material left after 5
1.5 × 10 yr if a U
234
isotope† initially containing 3 × 10
– 3
the half −life ( T 1 ⁄ 2 ) of the Uranium isotope 234 ( U – 14
234
gm of that material. It is known that 5
) is approximately 2.48 × 10 yr and has a
– 1
disintegration constant λ = 8.8 × 10 sec . The number of radioactive atoms of the original kind still present at any time t is computed from the relation – λ t
N = N0 e
– t ⁄ τ
= N 0 e
(H.1)
* Monotonically increasing and monotonically decreasing sequences are sequences in which the successive values either consistently increase or decrease but do not oscillate in relative value. Each value of a monotonic increasing sequence is greater than, or equal to the preceding value; likewise, each value of a monotonic decreasing sequence is less than, or equal to the preceding value. Stated in other words, a monotonically increasing function is one resulting from a partially ordered domain to a partially ordered range such that x ≤ y implies that f ( x ) ≤ f ( y ) . Likewise, a monotonically decreasing function is one resulting from a partially ordered domain to a partially ordered range such that x ≤ y implies that f ( x ) ≥ f ( y ) . † Isotopes are atoms which have the same atomic number (number of protons) but different number of neutrons. The sum of the number of protons and neutrons in the nucleus is referred to as the mass number. The superscript 234 represents the mass num- ber .
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
H−1
Lookup Table
Figure H.1. Model for Example H.1
Another example using this block appears in the Simulink Modeling Anti−Lock Braking System demo. It can be accessed by typing sldemo_absbrake at the MATLAB command prompt.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
H−3
Sum of Elements I.4 Sum of Elements The Sum of Elements block is another form of the Add block described above with one input and one output. Example I.4
The model in Figure I.4 illustrates Gibbs phenomenon. *
Figure I.4. Model for Example I.4
I.5 Bias The Bias block adds a bias (offset) to the input signal.
* The Gibbs phenomenon shows that Fourier series sums overshoot at a jump discontinuity, and that this overshoot does not disappear as the number of harmonics increases. For a detailed discussion please refer to Chapter 7, Signals and Systems, ISBN 978-1-934404-11-9.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
I−3
Polynomial
Figure I.17. Model for Example I.17
I.18 Polynomial The Polynomial block accepts the real coefficients a polynomial in the Parameters dialog box and at the input we specify real values at which the polynomial will be evaluated. It is equivalent to the MATLAB polyval function.
Example I.18
We will create a model using the Polynomial block to evaluate the polynomial 6
5
3
2
p ( x ) = x – 3x + 5x – 4x + 3x + 2
at x = – 3.7 , x = 4.0 , and x = 8.1 . The model is shown in Figure I.18 where at the MATLAB command prompt we have entered the coefficients of p ( x ) , i.e., px=[1 −3 0 5 −4 3 2];
and in the Parameters dialog box for the Polynomial block we have typed px. Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
I−13
Check Dynamic Upper Bound value of – 1 volt .
1 volt .
This model is configured to display error messages when the amplitude exceeds
The Signal Generator block has been specified as a sine waveform with the amplitude set at 1.1, frequency at 0.1 Hz, Constant block with the value shown, in the Check Dynamic Lower Bound block the Enable assertion and Output assertion signal are checked, and the icon type is selected as graphic. The Convert block was inserted to convert the Boolean output of the Lower Bound block to double as required by the Mux block.
Figure J.5. Model for Example J.5
J.6 Check Dynamic Upper Bound The Check Dynamic Upper Bound block performs checks to verify that the amplitude of a test signal is greater than the amplitude of a reference signal. The test signal is the signal connected to the input labeled sig. If the verification condition is true, the block takes no action. If not, simulation is halted and an error message is displayed. Example J.6
For the model in Figure J.6 the amplitude of a sinusoidal signal may vary ± 10% from its nominal value of 1 volt . The model is configured to display error messages when the amplitude exceeds +1 volt .
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
J−5
Appendix K Model− Wide Utilities
his appendix presents a brief description of the Simulink Model− Wide Utilities group. The function of each block and their input −output signals are illustrated with examples. For more information please refer to the Simulink documentation for each block.
K.1 Trigger−Based Linearization The Trigger−Based Linearization block, when triggered (by an external signal, e.g., a Pulse Generator), invokes the MATLAB functions linmod or dlinmod to create a linear model for the system at the current operating point. No trimming* is performed. The linear model is stored in the base workspace with the name of the model appended by _Trigger_Based_Linearization, for instance, Example01_Trigger_Based_Linearization . The structure has the fields shown in the Help menu for this block. Example K.1
We will use a Trigger−Based Linearization block to extract the linear model for the model shown in Figure K.1.
Figure K.1. Model for Example K.1
This is the same model as that in Figure D.4, Example D.3, Page D −4, Appendix D, where with the execution of the command [A,B,C,D]=linmod('Fig_D_04') the linear model in the form of the state−space MATLAB displayed the four matrices as
* The trim function uses a Simulink model to determine steady −state points of a dynamic system that satisfy input, out- put, and state conditions that we can specify. For details please type help trim at the MATLAB command prompt.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
K −1
Enable (added to subsystem block)
Figure L.18. Outputs when the Pulse Generator block is removed from the subsystem of Figure L.17
Figure L.19. The Enable block with the Show output selected
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
L −15
Appendix L Ports & Subsystems The library is saved, and a Configurable Subsystem block in the library which now appears as shown in Figure L.28.
Figure L.28. The library with the addition of the Configurable Subsystem
We double click on Configurable Subsystem block in Figure L.28 and in the Configuration dialog box we place check marks in the Member squares as shown in Figure L.29. The Port names pane shows the inputs indicated as Inports. To see the outputs, we click the Outports tab.
Figure L.29. The Configuration dialog for the library of Example L.6
The Configurable Subsystem block now appears as shown in Figure L.30.
Figure L.30. Inports and outports of the Configurable subsystem block
We can now select either Subsystem 1A or Subsystem 2A from the Configuration dialog to implement the 4−bit Adder by cascading four one−bit adders. For this example we choose Subsystem 1A.
L −20
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Configurable Subsystem This is done by unselecting Subsystem 2A on the Configuration dialog box of Figure L.29 which now appears as shown in Figure L.31.
Figure L.31. Configuration dialog box with Subsystem 1A selected
Now, a new model is created as shown in Figure L.32 by dragging the Configurable Subsystem 1A block * from this library into this model, copy and paste this block three times, and we interconnect these as shown in Figure L.32.
Figure L.32. Four−bit binary adder for Example L.6 with Subsystem 1A blocks
In the model of Figure L.32, the carry bit of the right−most one−bit adder is set to zero since there is no previous one−bit adder. We observe that Simulink displays small arrows on the bottom left corner of each of the subsystem blocks. A small arrow indicates that each subsystem block represents a library link in the model, and it is only visible if the Library Link Display option of the Format menu is selected All. * All four subsystem and constant blocks are flipped to indicate that the addition begins at the right side and proceeds to the left.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
L −21
Bus to Vector
Figure M.19. Model with the Signal Specification block acting as a virtual block
Figure M.20. Model where the attributes (sample times) of the Signal Specification block do not agree
M.10 Bus to Vector The Bus to Vector block converts a virtual bus signal to a vector signal. The input bus signal must consist of scalar, 1−D, or either row or column vectors having the same data type, signal type, and sampling mode. If the input bus contains row or column vectors, this block outputs a row or column vector, respectively; otherwise, it outputs a 1 −D array. Example M.11
The Model (a) in Figure M.21 below uses the Bus Creator 1 block to Display the Pulse Generator 1 and Repeating Sequence 1 blocks in Scope 1 where we observe that the input to that Scope block is a signal bus. In Model (b) the Bus Creator 1 block is replaced by a Mux block and we observe that the input in Scope 2 block is a vector. In Model (c), instead of replacing the Bus Creator 3 block with a Mux block, we have inserted the Bus to Vector block so that the input to the Scope 3 block is now a vector. The parameters are as annotated in the model and all three Scope blocks display the waveforms shown in Figure M.22.
Introduction to Simulink with Engineering Applications , Third Edition Copyright © Orchard Publications
M−13
Appendix N Signal Routing Example N.3
The model in Figure N.9 computes and displays the 5-day moving averages of three particular securities. It performs the same function as the model in Example L.17, Section L.21, Page L-52, Appendix, using three Selector blocks, one for the moving average of each security.
Figure N.9. Model for Example N.3
For this model, the row vectors A, B, and C are entered at the MATLAB command prompt as follows: A=[90 85 82 80 77]; B=[84 90 85 82 80]; C=[81 84 90 86 82];
The parameter dialog box for the Selector 1 block is shown in Figure N.10.
Figure N.10. Parameter dialog box for the Selector 1 block in Figure N.9
N−6
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Appendix O Sinks
Figure O.12. Updated waveform for the model in Figure O.11
Example O.7
The model in Figure O.13 produces the curve in Figure O.15 and it is known as nephroid. It is described by the equations x = 0.5a ( 3 cos φ – cos 3 φ ) y = 0.5a ( 3 sin φ – sin 3 φ )
For this model, the value of a is entered at the MATLAB command prompt as a=2;
Figure O.13. Model for Example O.7
Two more examples with the XY Graph block presented in Section 5.1.6, Page 5−12, Chapter 5, and Section 5.1.7, Page 5−15, Chapter 5.
O−10
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Signal Builder 7. When we select a line segment on the time axis (x −axis) we observe that at the lower end of the waveform display window the Left Point and Right Point fields become visible. We can then reshape the given waveform by specifying the Time (T) and Amplitude ( Y ) points. 8. We can choose one of several waveforms listed in New under the Signal drop menu.
The menu bar at the top contains several icons that we could use to choose from and/or modify our waveform. Example P.5
We begin with a new model, we drag a Signal Builder block, we click it, and on the top bar we click Signal>Replace with>Triangle wave>OK . We would like to change it to a symmetric triangle with Period 2, and Amplitude varying from −1 to +1 as shown in Figure P.16 where we have specified that the Time (T) and Amplitude ( Y ) points as (0,−1), (1,1), (2,−1), (3,1), (4,−1), (5,1), (6,−1), (7,1), (8,−1), (9,1), and (10, −1). We could also use the Repeating Sequence block discussed in Section P.13.
Figure P.16. Triangular waveform for Example P.4
To this model we add an Integrator block and a Scope block, and after the simulation command is executed, the model of Figure P.17 displays the triangular waveform and its integrated waveform in as shown.
Figure P.17. Model for Example P.5
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
P−11
Appendix Q User Defined Functions y=−(1/4)*cos(2*u(1))*log(sec(2*u(1))+tan(2*u(1))) +υ(2)*cos(2*u(1)) +υ(3)*cos(2*u(1));
The Simulink documentation includes the Modeling Engine Timing Using Triggered Subsystems demo. It can be accessed by typing sldemo_engine at the MATLAB command prompt, and clicking the Combustion block.
Q.2 Interpreted MATLAB Function The MATLAB Fcn block applies the specified MATLAB function or expression to the input. For a detailed description please refer to the Simulink documentation. Example Q.2
In the model of Figure Q.2, the function in the parameters dialog box for the Interpreted MATLAB Function block is specified as eig and outputs the eigenvalues of Matrix A defined at the MATLAB command prompt as: A=[1 2 3; 2 3 4; 3 5 7];
Figure Q.2. Model for Example Q.2
Q.3 MATLAB Function The MATLAB Function block contains a MATLAB language function in a Simulink model. For more information and an example, please refer to the Simulink documentation. Example Q.3
This example requires that a C or C++ compiler is installed in your system. To locate one or to determine whether one is installed, at the MATLAB command prompt type mex −setup
For this example, the author used the Microsoft Visual C++ 2010 compiler. In this example we will create a model using a MATLAB Function block to accept a and output the value of its determinant and its inverse matrix.
Q−2
3
× 3 matrix
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Appendix R Additional Discrete his appendix presents a brief description of the Simulink Additional Discrete group. The function of each block and their input −output signals are illustrated with examples. For more information please refer to the Simulink documentation for each block.
R.1 Transfer Fcn Direct Form II The Transfer Fcn Direct Form II block implements a Direct Form II realization of the transfer function specified by the Numerator coefficients and the Denominator coefficients without the leading* coefficient in the Denominator.
Example R.1
The model in Figure R.1 implements the discrete −time function – 1
– 2
0.5276 – 1.5828z + 1.5828z --------------------------H ( z ) = ----------------------------------------------- – 1 – 2 1 – 1.7600z + 1.1829z
(R.1)
Figure R.1. Model for Example R.1
In Figure R.1, the Sample time for the Sine Wave block is specified as 0.1. The numerator and denominator coefficients for the Transfer Fcn Direct Form II block are entered in the parameters dialog box and the leading coefficient 1 in the denominator is excluded, that is, it is entered as [ – 1.7600 1.1829 ] . The input and output waveforms are shown in Figure R.2.
– 1
* By lead we mean that the leading coefficient 1 in the denominator which has the form 1 + z
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
+
– 2
z
.
R −1
Appendix S Additional Math
Increment / Decrement
Figure S.2. Model for Example S.2
S.3 Increment Stored Integer The Increment Stored Integer block increases the stored integer value of a signal by one. Example S.3
The model of Figure S.3 implements the function y = ( 2 + x ) sin x – 1 for 0 ≤ x ≤ 10
Figure S.3. Model for Example S.3
S−2
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Cross Correlator
Figure T.11. Model for Example T.11
The auto correlation signal above justifies the following two properties of the auto correlation function: 1. The auto correlation function is an even function, i.e., R xx ( – τ ) = R xx ( τ ) 2. The auto correlation function is maximum at the origin, i.e., R xx ( 0 ) ≥ R xx ( τ ) . T.12 Cross Correlator
The cross−correlation is similar in nature to the convolution* of two functions. Whereas convolution involves reversing a signal, then shifting it and multiplying by another signal, correlation only involves shifting it and multiplying. The cross correlation of two signals x and y denoted as R xy ( τ ) where τ represents a time delay is defined as 1 R xy ( τ ) = lim --t p → ∞ t p
t p
x ( t ) y ( t – τ ) dt
(19.2)
0
The cross correlation R xy ( τ ) is an indication of how well the signals x and y are correlated for a particular value of the delay τ . If the cross correlation function peaks for a particular value of τ , this would indicate a very good correlation, which means that the two signals match each other very
* Convolution is discussed in Signals and Systems with MATLAB Computing and Simulink Modeling, ISBN 978−1− 934404−11−9, Chapter 6.
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
T−13
Appendix U Random Number Generation
his appendix is a short tutorial on Random Number Generation. An example is presented to illustrate the sequence which most random generators use.
U.1 Random Numbers Random numbers are used in many applications. Random number generation is the production of an unpredictable sequence of numbers in which no number is any more likely to occur at a given time or place in the sequence than any other. Truly random number generation is generally viewed as impossible. The process used in computers would be more properly called pseudorandom number generation.
U.2 An Example A typical random number generator creates a sequence in accordance with the following recurrence: x n + 1 = P 1 x n + P 2 ( mod N ) n=0,1,2,…
x 0 = seed
(U.1)
where mod N is used to indicate that the sum P 1 x n + P 2 is divided by N and then is replaced by the remainder of that division. The values of x0 (seed), P1 , P 2 , and N must be specified. As an example, let x0 = 1
P 1 = 281
P 2 = 123
N = 75
then, in MATLAB notation x0=1, P1=281, P2=123, N=75 x1=P1*x0+P2, y1=mod(x1,N) x2=P1*y1+P2, y2=mod(x2,N) ............. xn=P1*y(n-1)+P2, yn=mod(xn,N)
To find the sequence of numbers for the random number generator, we use the following MATLAB script: P1=281; P2=123; N=75; x=1:100; y=zeros(100,2); y(:,1)=x'; y(:,2)=mod((P1.*x+P2),N)'; fprintf(' x y \n'); disp(' ------'); fprintf('%3.0f\t %3.0f\n',y')
MATLAB outputs the following table:
Introduction to Simulink with Engineering Applications , Third Edition Copyright © Orchard Publications
U−1
Appendix V Exercises Dear Reader: The solutions to the exercises in this appendix can be found in Appendix W. You must, for your benefit, make an honest effort to solve these exercises without first looking at the solutions. You may need to review Appendices C through U and / or the blocks in the Simulink documentation to locate suitable blocks for your models. 1. Use Simulink with the Step function block, the Continuous−Time Transfer Fcn block, and the Scope block shown, to simulate and display the output waveform
shown below where
u0 ( t )
vC
of the electric RLC circuit*
is the unit step function, and the initial conditions are
iL ( 0 ) = 0
, and
vC( 0 ) = 0 .
R 1
Ω
L
+ −
1H
u0 t
C iL
+
vC
1F −
2. Repeat Exercise 1 using integrator blocks in lieu of the transfer function block.
*
The electric circuits presented in this texts can be easily converted to their mechanical equivalent circuits where a volt- age source can be replaced by a force f, a resistor can be replaced by a dashpot B, an inductor can be replaced by a mass M, and a capacitor can be replaced by an inverse spring constant 1/K. Thus the mechanical analog of the elec- tric circuit above can be converted to the mechanical system shown below. 1 ⁄ K
B f
M
x1
x2
x3
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
V −1
Appendix W Solutions to the Exercises 1.
The s−domain equivalent circuit is shown below. 1 1 -s
+
Ls
− V IN ( s )
+
V C ( s ) = V OU T ( s )
1/sC −
and by substitution of the given circuit constants, 1 1 -s
+
s
− V IN ( s )
+
V C ( s ) = V OU T ( s )
1/s −
By the voltage division expression, ( s ⋅ 1 ⁄ s ) ⁄ ( s + 1 ⁄ s ) V OU T ( s ) = -------------------------------------------------------( s ⋅ 1 ⁄ s ) ⁄ ( s + 1 ⁄ s ) + 1
from which
s
⋅ VIN ( s ) = ---2------------------- ⋅ VIN ( s ) s +s+1
V OU T ( s ) s T ra ns fe r f un ct io n = G ( s ) = -------------------- = ---------------------2 VIN ( s ) s +s+1
We invoke Simulink from the MATLAB environment, we open a new file by clicking on the blank page icon at the upper left on the task bar, we name this file Fig_W_01, and from the Sources , Continuous, and Commonly Used Blocks in the Simulink Library Browser, we select and interconnect the desired blocks as shown below.
As we know, the unit step function is undefined at t = 0 . Therefore, we double click the Step block, and in the Source Block Parameters dialog box shown below we enter the values indicated. Likewise, we double click the Transfer Fcn block and in the Source Block Parameters dialog box we enter the values indicated.
Introduction to Simulink with Engineering Applications , Third Edition Copyright © Orchard Publications
W −1
Appendix X Weighted Moving Average 2 Exponential Percentage = --------------------------------------------Time Periods + 1
(X.2)
For example, if we wanted a 20 period EMA, we would use 2 --------------- = 9.52 % 20 + 1
(X.3)
Example X.1
The price of a particular security (stock) over a 5−day period is as follows: 77 80 82 85 90
where the last value is the most recent. We will create single-input / single output (SISO) model with a Discrete FIR Filter block to simulate the weighted moving average over this 5−day period. For this example, we will represent the SISO output as follows: y 1 ( k ) = a 1 u ( k ) + b 1 u ( k – 1 ) + c 1 u ( k – 2 ) + d 1 u ( k – 3 ) + e 1 u ( k – 4 )
(X.4)
u ( k ) = 5 ⁄ 15 u ( k – 1 ) = 4 ⁄ 15 u ( k – 2 ) = 3 ⁄ 15 u ( k – 3 ) = 2 ⁄ 15 u ( k – 4 ) = 1 ⁄ 15
(X.5)
where
The model is shown in Figure X.1 where in the Function Block Parameters dialog box for the Discrete FIR Filter block we have entered the parameters shown in Figure X.2.
Figure X.1. Model for Example X.1
Figure X.2. Parameters for the Discrete FIR Filter block in Figure X.1
X −2
Introduction to Simulink with Engineering Applications, Third Edition Copyright © Orchard Publications
Index Symbols
Bus Selector block C-10, N-1
control input N-13
Bus to Vector block M-13
control signal L-1
C
conv(a,b) function in MATLAB A-6
% (percent) symbol in MATLAB A-2 10^u I-11
controller 5-30
3-bit Up / Down Counter model 5-23 4-bit Ring Counter model 5-24 A
correlation time P-19 C MEX-file S-function Q-9
cosh I-16
c2d function in MATLAB F-14
cosine block H-16
callback methods Q-8
cosine I-16
canonical form 5-31
Coulomb and Viscous Friction E-18
Abs block I-10
cantilever beam deflection 5-4
Coulomb Friction E-18
abs(z) function in MATLAB A-22
capillary tube 4-1
Counter Free-Running block P-23
accuracy J-10
capital investment 2-20
Counter Limited block P-24
acos I-16
Cartesian to Polar Transformation T-27
critically damped motion 3-19
acosh I-16
Cartesian to Spherical Transformation T-29
cross correlator T-13
acquisition costs 2-19
Cascade Form Realization 5-18
Add block I-1
cascaded mass-spring system
algebraic constraint block I-18
Celsius to Fahrenheit Transformation T-29
algebraic loop C-33
Check Discrete Gradient block J-9, K-8
D Flip Flop T-21
analog-to-digital conversion 2-9, 5-1, 5-3
Check Dynamic Gap block J-7
D Latch T-20
angle(z) function in MATLAB A-22
Check Dynamic Lower Bound block J-4
data inputs N-13
annuity 2-16
Check Dynamic Range block J-6
data points in MATLAB A-13
applications to differential
Check Dynamic Upper Bound block J-5
Data Store Memory block N-18
Check Input Resolution block J-10
Data Store Read block N-18
asin I-16
Check Static Gap block J-3
Data Store Write block N-18
asinh I-16
Check Static Lower Bound block J-1
Data Type Conversion block C-40, M-1
Assertion block J-8, L-17
Check Static Range Block J-2
data type conversion inherited M-8
Assignment block I-19
Check Static Upper Bound block J-2
data type duplicate M-4
atan I-16
chemical solutions example 5-1
Data Type Propagation block M-6
equations 3-3, 4-1
D
atan2 I-16
Chirp Signal block P-15
Data Type Propagation Examples M-14
atanh I-16
clc command in MATLAB A-2
Data Type Scaling Strip block M-7
Atomic Subsystem block L-3
clear command in MATLAB A-2
data types C-40
auto correlator T-12
Clock block P-25
dead zone block E-5
autoscale icon 1-12
Clock for digital systems block T-20
Dead Zone Dynamic block E-6
Averaging Power Spectral Density T-16
closed-loop control systems 5-30
decimal-to-bcd encoder L-8
Averaging Spectrum Analyzer T-17
Code Reuse Subsystem block L-7
deconv(c,d) function in MATLAB A-6, 7
axis command in MATLAB A-15
column vector in MATLAB A-17
Decrement Real World block S-1
B
backlash E-11
Combinatorial Logic block G-4
Decrement Stored Integer block S-3
command screen in MATLAB A-1
Decrement Time To Zero block S-4
command window in MATLAB A-1
Decrement To Zero block S-3
commas in MATLAB A-7
default color in MATLAB A-14
ball thrown vertically upward 3-3
comment line in MATLAB A-2
default in MATLAB A-11
Band-Limited White Noise P-18
commonly used blocks C-1
default line in MATLAB A-14
barge pulled by two horse groups 3-8
compare to constant block G-7
default marker in MATLAB A-14
Bernoulli’s equation, example of 4-3
compare to zero block G-6
Degrees to Radians Transformation T-30
Bessel functions 5-8
comparison of alternate proposals 2-15
demo in MATLAB A-2
bias block I-3
complex conjugate in MATLAB A-4
Demux block C-18, N-4
bilinear transformation F- 9, P-19
complex numbers in MATLAB A-2
depreciation 2-16
bilinear(Z,P,K,Fs) function P-20
complex to magnitude-angle block I-23
Derivative block D-1
Bit Clear block G-8, H-16
complex to real-imag block I-25
Derivative for Linearization block D-5
Bit Set block G-8
configurable subsystem block L-17
describing functions E-20
Bitwise Operator block G-9
Configuration Parameters 1-12
Detect Change block G-14
Block Support Table block K-8, L-17
configuration parameters C-15
Detect Decrease block G-14
bouncing ball 2-1
conical reservoir 12
Detect Fall Negative block G-17
box command in MATLAB A-12
conj (complex conjugate) I-11
Detect Fall Nonpositive block G-18
bulk modulus 4-6
Constant block C-7, P-2
Detect Increase block G-13
Bus Assignment block N-1
Contents Pane 1-7
Detect Rise Nonnegative block G-16
Bus Creator block C-10, N-1
continuous mode I-17
Detect Rise Positive block G-15
bus editor C-16
control element 5-30
development costs 2-19
IN-1
Difference block F-11
F
Increment Stored Integer block S-2
differential equations 2-1 Direct Form Realizations of a Digital Filter 5-16
increments between points in MATLAB A-13 Fahrenheit to Celsius Transformation T-29
Index Vector block N-8
Fcn block Q-1
infinite impulse response (IIR)
Digital Clock block P-26
Feedback Control Systems 5-30
digital filter F-8
Digital Filter Realization Forms 5-16
figure window in MATLAB A-13
infinite series 2-1
digital multiplexer L-3
Find Nonzero Elements block I-30
Inport block C-1, L-1, P-1
Direct Form-II Realization 5-17
finite impulse response (FIR)
insurance costs 2-16
Direct Lookup Table (n-D) block H-10
digital filter F-8
Integer delay block F-1, F-3
Discrete Derivative block F-12
first harmonic 16
Integrator block C-30, D-6
Discrete Filter block F-8
First-Order Hold block F-25
Integrator limited block D-6
discrete FIR filter F-21
Fixed-Point State-Space block R-3
Integrator second order D-8
discrete mode I-17
flip block command 1-11
Integrator second order limited D-11
Discrete PID Controller block F-26
Floating Bar Plot T-18
interest 2-16
Discrete PID Controller (2DOF) F-28
Floating Scope block O-5
Interpolation (n-D) using prelookup block H-9
Discrete State-Space block F-13
For Each Subsystem block L-52
Interpreted MATLAB Function block Q-2
Discrete Time Integration model 5-37
For Iterator Subsystem block L-35
Interval test block G-2
discrete time system transfer function C-35
format command in MATLAB A-29
Interval test dynamic block G-3
Discrete Transfer Fcn block F-5
fplot command in MATLAB A-25
Discrete Transfer Fcn with Initial Outputs T-2
From block N-14
Di scr ete Transfer Fcn wi th Ini ti al States T-1
Fr om Fi le block P-1
Discrete Zero-Pole (with initial outputs) T-5
From Workspace block P-1
Discrete Zero-Pole (with initial states) T-4
Function Block Parameters 1-9
Discrete Zero-Pole block F-10
Function Call Split block L-57
Discrete-Time Integrator block C-37
function file in MATLAB A-25
Discrete-Time Integrator block F-4
Function Lookup Table Generation
Display block 1-18, O-11
block H-17
J
J-K Flip Flop T-22 L
labor costs 2-16 lag compensator F-18
display formats in MATLAB A-29
Function-Call Feedback Latch L-58
lead compensator F-17
Divide block I-6
Function-Call Generator block L-2
lead-lag compensator F-18
Doc Text block K-8
Function-Ccall Subsystem block L-32
Legendre’s equation 5-9
dot multiplication operator in MATLAB A-19
fundamental frequency H-16
Level-1 M-file S-functions L-59, Q-7
Dot Product block I-8
fzero command in MATLAB A-25, 27
Level-2 M-file S-functions L-59, Q-7
E
G
linearization. D-2
economic analysis 2-15
Gain block 1-18, C-25, I-5
linmod(‘x’) D-2, D-4
editor window in MATLAB A-1
geometric series 2-1
linspace command in MATLAB A-13
editor/debugger in MATLAB A-1, 2
Goto block N-16
liquid in a capillary tube 4-1
linear programming 2-3 Electric Circuit in Phasor Form
link library display L-21
effective purchase price 2-16
Goto tag visibility block N-15
log I-11
electrical and mechanical
grid command in MATLAB A-11
log(x) function in MATLAB A-12
components - analogies of 5-25 element-by-element division
Ground block C-4, P-1
log10 function I-11
gtext(‘string’) command in MATLAB A-13
log10(x) function in MATLAB A-12
in MATLAB A-20 element-by-element exponentiation
log2(x) function in MATLAB A-12 H
loglog(x,y) command in MATLAB A-12
in MATLAB A-20 element-by-element multiplication in MATLAB A-17, A-19
Logical operator block C-27, G-1
half-wave symmetry H-17
Lookup table block H-1
heat flow example 5-3
Lookup table (2-D) block H-4
Enable (added to subsystem block) L -11
help matlab ofun command in MATLAB A-2
Lookup table (n-D) block H-5
Enable (description) L-1
hermitian function I-11
Lookup table dynamic block H-15
Enable Subsystem block L-26
hide name C-2
Enabled and Triggered Subsystem
Hit Crossing block E-16
block L-28
hypot function I-11
Enumerated Constant block P-2 Environmental Controller block N-10
M
magic sinewaves H-17 I
eps in MATLAB A-21, 25
magnitude^2 function I-11 Magnitude-Angle to Complex block I-24
execution context bars L-32
IC (Initial Condition) block M-8
maintenance costs 2-16
execution context indicators L-31
Idealized ADC Quantizer block T-7
Manual switch block N-12
exit command in MATLAB A-2
If Action Subsystem block L-38
mask B-1
exp function I-11
If block L-38
mask editor B-1
exploration costs 2-19
imag(z) function in MATLAB A-22
mask icon B-1
exponential moving average F-22
impulse response duration F-8
mask parameters B-1
Extract Bits block G-12
Increment Real World block S-1
masked subsystem B-1
IN-2
mass-spring-dashpot 5-25
Polar to Cartesian Transformation
materials costs 2-16
block T-27
Math function block I-11
polar(theta,r) function in MATLAB A-22
MATLAB demos A-2
poly(r) function in MATLAB A-4
MATLAB Fcn block Q-2
polyder(p) function in MATLAB A-6, 7
Matrix Concatenation block I-22
Polynomial block I-13
matrix multiplication in MATLAB A-17
polynomial construction from known
mechanical accelerometer 5-29
roots in MATLAB A-4
row vector in MATLAB A-3, 17 Running Simulink 1-7 rwv (real world value) C-41 S
Saturation block C-28, E-1 Saturation Dynamic block E-4
polyval(p,x) function in MATLAB A-5
Scope block 1-12, C-9, O-4
port data types C-43, M-1
script file in MATLAB A-25
Memory block F-24
pow (power) function I-11
second harmonic H-16
Merge block N-9
Power Spectral Density block T-14
seed U-1
mesh(x,y,z) command in MATLAB A-15
precedence over C-28
Selector block N-5
meshgrid(x,y) command in MATLAB A-16
Prelookup Index Search block H-8
semicolons in MATLAB A-7
Method of Frobenius 5-8
Probe block M-15
semilogx command in MATLAB A-12
Method of Picard 5-8
Product block C-7, I-6
semilogx(x,y) command in MATLAB A-12
m-file in MATLAB A-1, 25
Product of Elements block I-7
semilogy command in MATLAB A-12
M-file S-Functions L-59
pseudocode L-40
semilogy(x,y) command in MATLAB A-12
MinMax block I-14
pseudorandom number generation. U-1
Series Form Realization of a Digital Filter
MinMax Running Resettable block I-15
Pulse Generator block C-39, P-9
mechanical and electrical components - analogies of 5-25
mod I-11 Model block L-16, L-42
S-Function block L-62, Q-6 S-Function Builder block Q-9 S-Function Examples block Q-10
Q
Model Info block K-6
S-Function Examples 5-39, 5-41
Model Variants L-42
Quantizer block E-15
S-functions L-59
moving average F-22
quarter wave symmetry H-16
Shift Arithmetic block G-11
moving ladder 2-10
quit command in MATLAB A-2
Multiport Switch block N-13
SI (Stored Integer) C-41 Sign block I-9
Mux block C-18, N-4
R
Signal Builder block P-10
N
Radians to Degrees Transformation T-30
signal displays C-43, M-1
Ramp block P-12
Signal Generator block P-7
Random Number block P-16
Signal Specification block M-12
Signal Conversion block M-9
NaN in MATLAB A-25 nephroid O-10
random number generation example U-1
signals in the bus N-1
Newton’s Second Law 3-1
Random Number Generation U-1
signals that are being assigned N-1
nonlinear systems E-20
Random numbers U-1
Signed Sqrt blockI-28
non-recursive realization
rate limiter block E-8
simout To Workspace block 1-13, C13
rate limiter dynamic block E-10
simple oscillator 5-13
Rate Transition block M-10
simple pendulum 5-11
rated speed of an automobile on a
Simulation drop menu 1-12
digital filter F-8 nonvirtual subsystems L-7, L-62
highway curve 3-10
O
simulation start icon 1-12
real world value C-41
Simulink icon 1-7
open--loop control systems 5-30
real(z) function in MATLAB A-22
Sine Lookup block H-16
oscillatory motion 3-20
Real-Imag to C omplex block I-26
sine trig function I-16
Outport block C-1, L-1, O-1
real-time workshop L-62
Sine Wave block P-12
overdamped motion 3-20 P
Parallel Form Realization of a Digital Filter 5-20 paste duplicate inport C-4
reciprocal I-11
Sine Wave function block I-17
reciprocal sqrt I-29
sinh function-16
recursive realization digital filter F-8
Sinks library 1-18
refresh button N-1
slew rate E-8
Relational Operator block C-26, G-1
Slider Gain block I-5
relay block E-13
Spectrum Analyzer block T-17
rem I-11
Spherical to Cartesian Transformation
Permute Dimensions block I-23
repairs costs 2-16
PID Controller Block D-12
Repeating Sequence block P-14
spring fastened to a rigid support 3-17
PID Controller (2DOF) Block D-14
Repeating Sequence Interpolation
Sqrt block I-27
plant 5-30
block P-22
block T-28
Square bIock I-11
plot(x,y) command in MATLAB A-9, 12
Repeating Sequence Stair block P-21
Squeeze block I-20
plot(x,y,'m*') command in MATLAB A-14
Reshape block I-20
S-R Flip Flop T-21
plot(x,y,'rs') command in MATLAB A-14
resolution J-10
start simulation 1-12, C-8
plot(x,y,'rs-') command in MATLAB A-14
restoration costs 2-19
State-Space (with initial outputs)
plot(x,y,s) command in MATLAB A-14
roots of polynomials in MATLAB A-3
plot3 command in MATLAB A-14
roots(p) function in MATLAB A-3, 7, 8
State-Space block 1-12, D-9
plot3(x,y,z) command in MATLAB A-14
round(n) function in MATLAB A-22
Step block P-14
polar plot in MATLAB A-23
Rounding Function block I-12
Stop Simulation block O-12
block T-11
IN-3