Introduction to Simulink®
with Engineering Applications
Steven T. Karris
Orchard Publications
www.orchardpublications.com
Introduction to Simulink®
with Engineering Applications
Steven T. Karris
Orchard Publications
www.orchardpublications.com
Introduction to Simulink ® with Engineering Applications
Copyright ® 2006 Orchard Publications. All rights reserved. Printed in the United States of America. No part of this
publication may be reproduced or distributed in any form or by any means, or stored in a data base or retrieval system,
without the prior written permission of the publisher.
Direct all inquiries to Orchard Publications, info@orchardpublications.com
Product and corporate names are trademarks or registered trademarks of The MathWorks™, Inc. They are used only
for identification and explanation, without intent to infringe.
Library of Congress Cataloging-in-Publication Data
Library of Congress Control Number (LCCN) 2006926850
ISBN 0-9744239-8-X
ISBN 978-0-9744239-8-2
Disclaimer
The author has made every effort to make this text as complete and accurate as possible, but no warranty is implied.
The author and publisher shall have neither liability nor responsibility to any person or entity with respect to any loss
or damages arising from the information contained in this text.
Preface
This text is an introduction to Simulink ®, a companion application to MATLAB ®. It is written
for students at the undergraduate and graduate programs, as well as for the working professional.
Although some previous knowledge of MATLAB would be helpful, it is not absolutely necessary;
Appendix A of this text is an introduction to MATLAB to enable the reader to begin learning
both MATLAB and Simulink simultaneously, and to perform graphical computations and
programming.
Chapters 2 through 18 describe the blocks of all Simulink libraries. Their application is illustrated
with practical examples through Simulink models, some of which are supplemented with
MATLAB functions, commands, and statements. Some background information is provided for
lesser known definitions and topics. Chapters 1 and 19 contain several Simulink models to
illustrate various applied math and engineering applications. Appendix B is an introduction to
difference equations as they apply to discrete-time systems, and Appendix C introduces the reader
to random generation procedures.
This text supplements our Numerical Analysis with MATLAB and Spreadsheet Applications, ISBN
0−9709511−1−6. It is self-contained; the blocks of each library are described in an orderly fashion
that is consistent with Simulink’s documentation. This arrangement provides insight into how a
model is used and how its parts interact with each another.
Like MATLAB, Simulink can be used with both linear and nonlinear systems, which can be
modeled in continuous time, sample time, or a hybrid of these. Examples are provided in this text.
Most of the examples presented in this book can be implemented with the Student Versions of
MATLAB and Simulink. A few may require the full versions of these outstanding packages, and
these examples may be skipped. Some add−ons, known as Toolboxes and Blocksets can be
obtained from The MathWorks,™ Inc., 3 Apple Hill Drive, Natick, MA, 01760-2098, USA,
www.mathworks.com.
To get the most out of this outstanding application, it is highly recommended that this text is used
in conjunction with the MATLAB and Simulink User’s Guides. Other references are provided in
the reference section of this text.
The author wishes to express his gratitude to the staff of The MathWorks™, the developers of
MATLAB® and Simulink®, especially to Ms. Courtney Esposito, for the encouragement and
unlimited support they have provided me with during the production of this text.
This is the first edition of this title, and although every effort was made to correct possible
typographical errors and erroneous references to figures and tables, some may have been
overlooked. Accordingly, the author will appreciate it very much if any such errors are brought to
his attention so that corrections can be made for the next edition.
Orchard Publications
www.orchardpublications.com
info@orchardpublications.com
Table of Contents
1 Introduction to Simulink
1−1
1.1 Simulink and its Relation to MATLAB....................................................................1−1
1.2 Simulink Demos ......................................................................................................1−20
1.3 Summary..................................................................................................................1−28
1.4 Exercises ..................................................................................................................1−29
1.5 Solutions to End−of−Chapter Exercises ..................................................................1−30
2 The Commonly Used Blocks Library
2−1
2.1 The Inport, Outport, and Subsystem Blocks ..........................................................2−2
2.2 The Ground Block ...................................................................................................2−4
2.3 The Terminator Block ............................................................................................2−5
2.4 The Constant and Product Blocks .........................................................................2−6
2.5 The Scope Block .....................................................................................................2−7
2.6 The Bus Creator and Bus Selector Blocks ..............................................................2−7
2.7 The Mux and Demux Blocks ................................................................................2−11
2.8 The Switch Block ..................................................................................................2−14
2.9 The Sum Block .....................................................................................................2−15
2.10 The Gain Block .....................................................................................................2−16
2.11 The Relational Operator Block ............................................................................2−17
2.12 The Logical Operator Block .................................................................................2−18
2.13 The Saturation Block ............................................................................................2−19
2.14 The Integrator Block ............................................................................................2−20
2.15 The Unit Delay Block ...........................................................................................2−24
2.16 The Discrete−Time Integrator Block ...................................................................2−26
2.17 Data Types and The Data Type Conversion Block .............................................2−29
2.18 Summary ...............................................................................................................2−35
2.19 Exercises ................................................................................................................2−39
2.20 Solutions to End−of−Chapter Exercises ...............................................................2−41
3 The Continuous Blocks Library
3−1
3.1 The Continuous−Time Linear Systems Sub−Library................................................ 3−2
3.1.1 The Integrator Block....................................................................................... 3−2
3.1.2 The Derivative Block ...................................................................................... 3−2
3.1.3 The State−Space Block ................................................................................... 3−6
3.1.4 The Transfer Fcn Block .................................................................................. 3−6
3.1.5 The Zero−Pole Block....................................................................................... 3−8
3.2 The Continuous−Time Delays Sub−Library........................................................... 3−10
Introduction to Simulink with Engineering Applications
Copyright © Orchard Publications
i
3.2.1 The Transport Delay Block......................................................................... 3−10
3.2.2 The Variable Time Delay Block.................................................................. 3−11
3.2.3 The Variable Transport Delay Block .......................................................... 3−12
3.3 Summary............................................................................................................... 3−14
3.4 Exercises............................................................................................................... 3−16
3.5 Solutions to End−of−Chapter Exercises............................................................... 3−17
4 The Discontinuities Blocks Library
4−1
4.1 The Saturation Block ............................................................................................. 4−2
4.2 The Saturation Dynamic Block.............................................................................. 4−3
4.3 The Dead Zone Block............................................................................................. 4−4
4.4 The Dead Zone Dynamic Block ............................................................................. 4−5
4.5 The Rate Limiter Block .......................................................................................... 4−6
4.6 The Rate Limiter Dynamic Block .......................................................................... 4−8
4.7 The Backlash Block................................................................................................ 4−9
4.8 The Relay Block ................................................................................................... 4−11
4.9 The Quantizer Block ............................................................................................ 4−12
4.10 The Hit Crossing Block ........................................................................................ 4−13
4.11 The Coulomb and Viscous Friction Block ........................................................... 4−14
4.12 The Wrap to Zero Block....................................................................................... 4−16
4.13 Summary............................................................................................................... 4−17
4.14 Exercises ............................................................................................................... 4−19
4.15 Solutions to End−of−Chapter Exercises ............................................................... 4−20
5 The Discrete Blocks Library
5−1
5.1 The Discrete−Time Linear Systems Sub−Library.................................................... 5−2
5.1.1 The Unit Delay Block.................................................................................. 5−2
5.1.2 The Integer Delay Block.............................................................................. 5−2
5.1.3 The Tapped Delay Block ............................................................................. 5−3
5.1.4 The Discrete−Time Integrator Block........................................................... 5−4
5.1.5 The Discrete Transfer Fcn Block................................................................. 5−4
5.1.6 The Discrete Filter Block............................................................................. 5−5
5.1.7 The Discrete Zero−Pole Block ..................................................................... 5−8
5.1.8 The Difference Block................................................................................... 5−9
5.1.9 The Discrete Derivative Block .................................................................. 5−10
5.1.10 The Discrete State−Space Block .............................................................. 5− 11
5.1.11 The Transfer Fcn First Order Block .......................................................... 5−14
5.1.12 The Transfer Fcn Lead or Lag Block ......................................................... 5−15
5.1.13 The Transfer Fcn Real Zero Block ............................................................ 5−18
5.1.14 The Weighted Moving Average Block...................................................... 5−19
ii
Introduction to Simulink with Engineering Applications
Copyright © Orchard Publications
5.2 The Sample & Hold Delays Sub−Library ............................................................. 5−21
5.2.1 The Memory Block..................................................................................... 5−21
5.2.2 The First−Order Hold Block ...................................................................... 5−22
5.2.3 The Zero−Order Hold Block ...................................................................... 5−23
5.3 Summary ............................................................................................................... 5−25
5.4 Exercises................................................................................................................ 5−27
5.5 Solutions to End−of−Chapter Exercises ............................................................... 5−29
6 The Logic and Bit Operations Library
6−1
6.1 The Logic Operations Group Sub−Library.............................................................. 6−2
6.1.1 The Logical Operator Block......................................................................... 6−2
6.1.2 The Relational Operator Block.................................................................... 6−2
6.1.3 The Interval Test Block ............................................................................... 6−2
6.1.4 The Interval Test Dynamic Block................................................................ 6−3
6.1.5 The Combinational Logic Block .................................................................. 6−4
6.1.6 The Compare to Zero Block......................................................................... 6−9
6.1.7 The Compare to Constant Block ............................................................... 6−10
6.2 The Bit Operations Group Sub−Library............................................................... 6−11
6.2.1 The Bit Set Block ....................................................................................... 6−12
6.2.2 The Bit Clear Block.................................................................................... 6−13
6.2.3 The Bitwise Operator Block....................................................................... 6−14
6.2.4 The Shift Arithmetic Block........................................................................ 6−16
6.2.5 The Extract Bits Block ............................................................................... 6−17
6.3 The Edge Detection Group Sub−Library ............................................................. 6−18
6.3.1 The Detect Increase Block......................................................................... 6−18
6.3.2 The Detect Decrease Block........................................................................ 6−20
6.3.3 The Detect Change Block.......................................................................... 6−21
6.3.4 The Detect Rise Positive Block.................................................................. 6−22
6.3.5 The Detect Rise Nonnegative Block ......................................................... 6−23
6.3.6 The Detect Fall Negative Block................................................................. 6−24
6.3.7 The Detect Fall Nonpositive Block ........................................................... 6−25
6.4 Summary............................................................................................................... 6−27
6.5 Exercises ............................................................................................................... 6−31
6.6 Solutions to End−of−Chapter Exercises............................................................... 6−32
7 The Lookup Tables Library
7−1
7.1 The Lookup Table Block.........................................................................................7−2
7.2 The Lookup Table (2−D) Block..............................................................................7−3
7.3 The Lookup Table (n−D) Block .............................................................................7−5
7.4 The PreLookup Index Search Block .......................................................................7−7
Introduction to Simulink with Engineering Applications
Copyright © Orchard Publications
iii