simulink model-based and system-based design

846
Modeling Simulation Implementation S IMULINK Model-Based and System-Based Design ® Using Simulink Version 4

Upload: veera-chaitanya

Post on 20-Nov-2015

119 views

Category:

Documents


25 download

DESCRIPTION

simulinkk

TRANSCRIPT

  • Modeling

    Simulation

    Implementation

    SIMULINKModel-Based and System-Based Design

    Using SimulinkVersion 4

  • How to Contact The MathWorks:

    www.mathworks.com Webcomp.soft-sys.matlab Newsgroup

    [email protected] Technical [email protected] Product enhancement [email protected] Bug [email protected] Documentation error [email protected] Order status, license renewals, [email protected] Sales, pricing, and general information

    508-647-7000 Phone

    508-647-7001 Fax

    The MathWorks, Inc. Mail3 Apple Hill DriveNatick, MA 01760-2098

    For contact information about worldwide offices, see the MathWorks Web site.

    Using Simulink COPYRIGHT 1990 - 2001 by The MathWorks, Inc. The software described in this document is furnished under a license agreement. The software may be used or copied only under the terms of the license agreement. No part of this manual may be photocopied or repro-duced in any form without prior written consent from The MathWorks, Inc.

    FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by or for the federal government of the United States. By accepting delivery of the Program, the government hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part 252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain to the governments use and disclosure of the Program and Documentation, and shall supersede any conflicting contractual terms or conditions. If this license fails to meet the governments minimum needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to MathWorks.

    MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and Target Language Compiler is a trademark of The MathWorks, Inc.

    Other product or brand names are trademarks or registered trademarks of their respective holders.

    Printing History: November 1990 First printing New for Simulink 1December 1996 Second printing Revised for Simulink 2January 1999 Third Printing Revised for Simulink 3 (Release 11)November 2000 Fourth printing Revised for Simulink 4 (Release 12)June 2001 Online only Revised for Simulink 4.1 (Release 12.1)

  • iContents

    1Getting Started

    To the Reader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2What Is Simulink? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2How to Use This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3

    Related Products List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5

    2Quick Start

    Running a Demo Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2Description of the Demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3Some Things to Try . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4What This Demo Illustrates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5Other Useful Demos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

    Building a Simple Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6

    Setting Simulink Preferences . . . . . . . . . . . . . . . . . . . . . . . . . 2-16Simulink Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16

    3How Simulink Works

    What Is Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2

    Modeling Dynamic Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3Block Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3

  • ii Contents

    States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4System Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-5Continuous Versus Discrete Blocks . . . . . . . . . . . . . . . . . . . . . . 3-6Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6Custom Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8

    Simulating Dynamic Systems . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9Model Initialization Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9Model Execution Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9Processing at Each Time Step . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10Determining Block Update Order . . . . . . . . . . . . . . . . . . . . . . . 3-11Atomic Versus Virtual Subsystems . . . . . . . . . . . . . . . . . . . . . . 3-13Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13Zero Crossing Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15Algebraic Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19

    Modeling and Simulating Discrete Systems . . . . . . . . . . . . . 3-24Discrete Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24Sample Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24Purely Discrete Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24Multirate Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-25Determining Step Size for Discrete Systems . . . . . . . . . . . . . . 3-25Sample Time Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27Invariant Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28Mixed Continuous and Discrete Systems . . . . . . . . . . . . . . . . . 3-29

    4Creating a Model

    Starting Simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2Creating a New Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3Editing an Existing Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3Entering Simulink Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4

  • iii

    Simulink Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-5

    Selecting Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8Selecting One Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8Selecting More than One Object . . . . . . . . . . . . . . . . . . . . . . . . . 4-8

    Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10Block Data Tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10Virtual Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10Copying and Moving Blocks from One Window to Another . . 4-11Moving Blocks in a Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13Copying Blocks in a Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-13Setting Block-Specific Parameters . . . . . . . . . . . . . . . . . . . . . . 4-14Block Properties Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15Deleting Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16Changing the Orientation of Blocks . . . . . . . . . . . . . . . . . . . . . 4-17Resizing Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17Manipulating Block Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-18Displaying Parameters Beneath a Blocks Icon . . . . . . . . . . . . 4-19Disconnecting Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20Assigning Block Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20Displaying Block Execution Order . . . . . . . . . . . . . . . . . . . . . . 4-21Using Drop Shadows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21Specifying Block Diagram Colors . . . . . . . . . . . . . . . . . . . . . . . 4-22Sample Time Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23Associating User Data with Blocks . . . . . . . . . . . . . . . . . . . . . . 4-24State Properties Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24

    Connecting Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25Autoconnecting Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25Connecting Blocks Manually . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27

    Working with Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32About Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32Signal Buses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34Signal Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35Determining Output Signal Dimensions . . . . . . . . . . . . . . . . . 4-36Signal and Parameter Dimension Rules . . . . . . . . . . . . . . . . . . 4-37Scalar Expansion of Inputs and Parameters . . . . . . . . . . . . . . 4-39

  • iv Contents

    Working with Complex Signals . . . . . . . . . . . . . . . . . . . . . . . . . 4-41Checking Signal Connections . . . . . . . . . . . . . . . . . . . . . . . . . . 4-41Setting Signal Display Options . . . . . . . . . . . . . . . . . . . . . . . . . 4-42Signal Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42Signal Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42Displaying Signals Represented by Virtual Signals . . . . . . . . 4-43Setting Signal Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44Signal Properties Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44

    Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47

    Working with Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-49Data Types Supported by Simulink . . . . . . . . . . . . . . . . . . . . . 4-49Block Support for Data and Numeric Signal Types . . . . . . . . . 4-50Specifying Block Parameter Data Types . . . . . . . . . . . . . . . . . 4-50Creating Signals of a Specific Data Type . . . . . . . . . . . . . . . . . 4-51Displaying Port Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-51Data Type Propagation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-51Data Typing Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-52Enabling Strict Boolean Type Checking . . . . . . . . . . . . . . . . . . 4-53Typecasting Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-53Typecasting Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-53

    Working with Data Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-55Data Object Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-55Creating Data Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56Accessing Data Object Properties . . . . . . . . . . . . . . . . . . . . . . . 4-57Invoking Data Object Methods . . . . . . . . . . . . . . . . . . . . . . . . . 4-57Saving and Loading Data Objects . . . . . . . . . . . . . . . . . . . . . . . 4-58Using Data Objects in Simulink Models . . . . . . . . . . . . . . . . . . 4-58Creating Data Object Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 4-60The Simulink Data Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-72

    Summary of Mouse and Keyboard Actions . . . . . . . . . . . . . . 4-74

    Creating Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-77Creating a Subsystem by Adding the Subsystem Block . . . . . 4-77Creating a Subsystem by Grouping Existing Blocks . . . . . . . . 4-78Model Navigation Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 4-80

  • vWindow Reuse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-80Labeling Subsystem Ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-81Controlling Access to Subsystems . . . . . . . . . . . . . . . . . . . . . . . 4-81

    Using Callback Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-83Tracing Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-83Model Callback Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-84Block Callback Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-85Port Callback Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-87

    Tips for Building Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-88

    Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-89Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-89Simulink Block Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-89Creating a Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-90Modifying a Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-90Creating a Library Link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-90Disabling Library Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-91Modifying a Linked Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . 4-91Propagating Link Modifications . . . . . . . . . . . . . . . . . . . . . . . . 4-92Updating a Linked Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-92Breaking a Link to a Library Block . . . . . . . . . . . . . . . . . . . . . 4-93Finding the Library Block for a Reference Block . . . . . . . . . . . 4-93Library Link Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-93Displaying Library Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-94Getting Information About Library Blocks . . . . . . . . . . . . . . . 4-95Browsing Block Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-95Adding Libraries to the Library Browser . . . . . . . . . . . . . . . . . 4-97

    Modeling Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-99Converting Celsius to Fahrenheit . . . . . . . . . . . . . . . . . . . . . . . 4-99Modeling a Simple Continuous System . . . . . . . . . . . . . . . . . 4-100

    Saving a Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-103

    Printing a Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-105Print Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-105Print Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-106

  • vi Contents

    Specifying Paper Size and Orientation . . . . . . . . . . . . . . . . . . 4-107Positioning and Sizing a Diagram . . . . . . . . . . . . . . . . . . . . . . 4-108

    Searching and Browsing Models . . . . . . . . . . . . . . . . . . . . . . 4-109Searching for Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-109The Model Browser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-115

    Managing Model Versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-120Specifying the Current User . . . . . . . . . . . . . . . . . . . . . . . . . . 4-120Model Properties Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . . 4-122Creating a Model Change History . . . . . . . . . . . . . . . . . . . . . . 4-126Version Control Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-128

    Ending a Simulink Session . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-130

    5Running a Simulation

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2Using Menu Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2Running a Simulation from the Command Line . . . . . . . . . . . . 5-3

    Running a Simulation Using Menu Commands . . . . . . . . . . . 5-4Setting Simulation Parameters and Choosing the Solver . . . . . 5-4Applying the Simulation Parameters . . . . . . . . . . . . . . . . . . . . . 5-4Starting the Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-4Simulation Diagnostics Dialog Box . . . . . . . . . . . . . . . . . . . . . . . 5-6

    The Simulation Parameters Dialog Box . . . . . . . . . . . . . . . . . 5-8The Solver Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8The Workspace I/O Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19The Diagnostics Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-26The Advanced Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-30

    Improving Simulation Performance and Accuracy . . . . . . 5-35Speeding Up the Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-35Improving Simulation Accuracy . . . . . . . . . . . . . . . . . . . . . . . . 5-36

  • vii

    Running a Simulation from the Command Line . . . . . . . . . 5-37Using the sim Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-37Using the set_param Command . . . . . . . . . . . . . . . . . . . . . . . . 5-37model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-39sim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-41simplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-43simset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-45simget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-49

    6Analyzing Simulation Results

    Viewing Output Trajectories . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2Using the Scope Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2Using Return Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2Using the To Workspace Block . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3

    Linearization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4

    Equilibrium Point Determination . . . . . . . . . . . . . . . . . . . . . . 6-7linmod, dlinmod, linmod2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9trim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-12

    7Using Masks to Customize Blocks

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2

    A Sample Masked Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3Creating Mask Dialog Box Prompts . . . . . . . . . . . . . . . . . . . . . . 7-4Creating the Block Description and Help Text . . . . . . . . . . . . . 7-6Creating the Block Icon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6

    The Mask Editor: An Overview . . . . . . . . . . . . . . . . . . . . . . . . . 7-8

  • viii Contents

    The Initialization Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9Prompts and Associated Variables . . . . . . . . . . . . . . . . . . . . . . . 7-9Control Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-11Default Values for Masked Block Parameters . . . . . . . . . . . . . 7-13Tunable Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-13Initialization Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14

    The Icon Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-17Displaying Text on the Block Icon . . . . . . . . . . . . . . . . . . . . . . 7-17Displaying Graphics on the Block Icon . . . . . . . . . . . . . . . . . . . 7-19Displaying Images on Masks . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-20Displaying a Transfer Function on the Block Icon . . . . . . . . . . 7-21Controlling Icon Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-22

    The Documentation Pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26The Mask Type Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26The Block Description Field . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-26The Block Help Field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-27

    Creating Self-Modifying Masked Blocks . . . . . . . . . . . . . . . . 7-28

    Creating Dynamic Dialogs for Masked Blocks . . . . . . . . . . 7-29Setting Masked Block Dialog Parameters . . . . . . . . . . . . . . . . 7-29Predefined Masked Dialog Parameters . . . . . . . . . . . . . . . . . . 7-30

    8Conditionally Executed Subsystems

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2

    Enabled Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3Creating an Enabled Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . 8-3Blocks an Enabled Subsystem Can Contain . . . . . . . . . . . . . . . 8-5

    Triggered Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8Creating a Triggered Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . 8-9Function-Call Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10

  • ix

    Blocks That a Triggered Subsystem Can Contain . . . . . . . . . . 8-11

    Triggered and Enabled Subsystems . . . . . . . . . . . . . . . . . . . . 8-12Creating a Triggered and Enabled Subsystem . . . . . . . . . . . . . 8-12A Sample Triggered and Enabled Subsystem . . . . . . . . . . . . . 8-13Creating Alternately Executing Subsystems . . . . . . . . . . . . . . 8-14

    Control Flow Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16Creating Conditional Control Flow Statements . . . . . . . . . . . . 8-16Creating Iterator Control Flow Statements . . . . . . . . . . . . . . . 8-19Comparing Stateflow and Control Flow Statements . . . . . . . . 8-23Using Stateflow with the Control Flow Blocks . . . . . . . . . . . . 8-24

    9Block Reference

    What Each Block Reference Page Contains . . . . . . . . . . . . . . 9-2

    Simulink Block Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3Abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13Action Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14Action Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-17Algebraic Constraint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-18Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-20Backlash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-25Band-Limited White Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-29Bitwise Logical Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-31Bus Creator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-35Bus Selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-39Chirp Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-41Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-43Combinatorial Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-45Complex to Magnitude-Angle . . . . . . . . . . . . . . . . . . . . . . . . . . 9-48Complex to Real-Imag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-49Configurable Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-50Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-54Coulomb and Viscous Friction . . . . . . . . . . . . . . . . . . . . . . . . . . 9-56

  • x Contents

    Data Store Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-58Data Store Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-60Data Store Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-62Data Type Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-64Dead Zone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-66Demux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-68Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-74Digital Clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-76Direct Look-Up Table (n-D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-77Discrete Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-83Discrete State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-85Discrete-Time Integrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-87Discrete Transfer Fcn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-95Discrete Zero-Pole . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-97Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-99Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-102Enable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-104Enabled and Triggered Subsystem . . . . . . . . . . . . . . . . . . . . . 9-106Enabled Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-107Fcn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-108First-Order Hold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-111For Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-113For Iterator Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-118From . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-119From File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-121From Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-124Function-Call Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-128Function-Call Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-130Gain, Matrix Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-131Goto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-134Goto Tag Visibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-137Ground . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-138Hit Crossing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-139IC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-141If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-142Inport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-146Integrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-150Interpolation (n-D) Using PreLook-Up . . . . . . . . . . . . . . . . . . 9-156Logical Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-159Look-Up Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-161

  • xi

    Look-Up Table (2-D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-164Look-Up Table (n-D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-167Magnitude-Angle to Complex . . . . . . . . . . . . . . . . . . . . . . . . . 9-172Manual Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-174Math Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-175MATLAB Fcn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-177Matrix Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-179Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-181Merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-183MinMax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-187Model Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-189Multiport Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-192Mux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-194Outport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-196Polynomial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-200Prelook-Up Index Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-202Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-205Probe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-208Pulse Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-210Quantizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-214Ramp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-216Random Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-218Rate Limiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-220Real-Imag to Complex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-222Relational Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-224Relay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-226Repeating Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-228Reshape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-230Rounding Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-233Saturation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-235Scope, Floating Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-236Selector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-250S-Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-254S-Function Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-256Sign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-258Signal Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-259Signal Specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-262Sine Wave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-264Slider Gain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-269State-Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-271

  • xii Contents

    Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-274Stop Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-276Subsystem, Atomic Subsystem . . . . . . . . . . . . . . . . . . . . . . . . 9-277Sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-281Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-284Switch Case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-286Terminator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-290To File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-291To Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-293Transfer Fcn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-297Transport Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-300Trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-303Triggered Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-305Trigonometric Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-306Uniform Random Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-308Unit Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-310Variable Transport Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-312While Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-315While Iterator Subsystem . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-320Width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-321XY Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-322Zero-Order Hold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-324Zero-Pole . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-325

    10Model Construction Commands

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2How to Specify Parameters for the Commands . . . . . . . . . . . . 10-3How to Specify a Path for a Simulink Object . . . . . . . . . . . . . . 10-3add_block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4add_line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-5add_param . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-7bdclose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8bdroot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-9close_system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-10delete_block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12

  • xiii

    delete_line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13delete_param . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-14find_system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15gcb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-20gcbh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-21gcs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22get_param . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23new_system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-25open_system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-26replace_block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-27save_system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-29set_param . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-30simulink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-32

    11Simulink Debugger

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2

    Starting the Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3

    Starting the Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-4

    Using the Debuggers Command-Line Interface . . . . . . . . . 11-6About Block Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6Accessing the MATLAB Workspace . . . . . . . . . . . . . . . . . . . . . 11-6

    Getting Online Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7

    Running a Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8Continuing a Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8Running a Simulation Nonstop . . . . . . . . . . . . . . . . . . . . . . . . . 11-9Advancing to the Next Block . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-9Advancing to the Next Time Step . . . . . . . . . . . . . . . . . . . . . . 11-10

    Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11Setting Breakpoints at Blocks . . . . . . . . . . . . . . . . . . . . . . . . . 11-12

  • xiv Contents

    Setting Breakpoints at Time Steps . . . . . . . . . . . . . . . . . . . . . 11-13Breaking on Nonfinite Values . . . . . . . . . . . . . . . . . . . . . . . . . 11-14Breaking on Step-Size Limiting Steps . . . . . . . . . . . . . . . . . . 11-14Breaking at Zero-Crossings . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-14

    Displaying Information About the Simulation . . . . . . . . . 11-16Displaying Block I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-16Displaying Algebraic Loop Information . . . . . . . . . . . . . . . . . 11-18Displaying System States . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-19Displaying Integration Information . . . . . . . . . . . . . . . . . . . . 11-19

    Displaying Information About the Model . . . . . . . . . . . . . . 11-20Displaying a Models Block Execution Order . . . . . . . . . . . . . 11-20Displaying a Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-20

    Debugger Command Reference . . . . . . . . . . . . . . . . . . . . . . . 11-24ashow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-26atrace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-27bafter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-28break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-29bshow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-30clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-31continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-32disp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-33help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-34emode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-35ishow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-36minor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-37nanbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-38next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-39probe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-40quit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-41run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-42slist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-43states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-44systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-45status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-46step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-47stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-48tbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-49

  • xv

    trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-50undisp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-51untrace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-52xbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-53zcbreak . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-54zclist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-55

    12Performance Tools

    About the Simulink Performance Tools Option . . . . . . . . . 12-2

    The Simulink Accelerator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-3How Does It Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-3How to Run the Simulink Accelerator . . . . . . . . . . . . . . . . . . . 12-4Handling Changes in Model Structure . . . . . . . . . . . . . . . . . . . 12-5Increasing Performance of Accelerator Mode . . . . . . . . . . . . . . 12-6Blocks That Do Not Show Speed Improvements . . . . . . . . . . . 12-7Using the Simulink Accelerator with the Simulink Debugger 12-9Interacting with the Simulink Accelerator Programmatically 12-10Comparing Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-11Customizing the Simulink Accelerator Build Process . . . . . . 12-11Controlling S-Function Execution . . . . . . . . . . . . . . . . . . . . . . 12-12

    Graphical Merge Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-14Comparing Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-14The Graphical Merge Tool Window . . . . . . . . . . . . . . . . . . . . . 12-17Navigating Model Differences . . . . . . . . . . . . . . . . . . . . . . . . . 12-19Merging Model Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-20Generating a Model Differences Report . . . . . . . . . . . . . . . . . 12-21

    Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-22How the Profiler Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-22Enabling the Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-24The Simulation Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-25

    Model Coverage Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-28

  • xvi Contents

    How the Model Coverage Tool Works . . . . . . . . . . . . . . . . . . . 12-28Using the Model Coverage Tool . . . . . . . . . . . . . . . . . . . . . . . . 12-30Creating and Running Test Cases . . . . . . . . . . . . . . . . . . . . . 12-31The Coverage Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-32Coverage Settings Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . . 12-38HTML Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-40Model Coverage Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 12-41

    AModel and Block Parameters

    Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2

    Model Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-3

    Common Block Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-8

    Block-Specific Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-11

    Mask Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-26

    BModel File Format

    Model File Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-2Model Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-3BlockDefaults Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-3AnnotationDefaults Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-3System Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . B-3

  • 1

    Getting Started

    To the Reader . . . . . . . . . . . . . . . . . . . 1-2What Is Simulink? . . . . . . . . . . . . . . . . . . 1-2How to Use This Manual . . . . . . . . . . . . . . . 1-3

    Related Products List . . . . . . . . . . . . . . . . 1-5

  • 1 Getting Started

    1-2

    To the ReaderWelcome to Simulink! In the last few years, Simulink has become the most widely used software package in academia and industry for modeling and simulating dynamical systems.

    Simulink encourages you to try things out. You can easily build models from scratch, or take an existing model and add to it. Simulations are interactive, so you can change parameters on the fly and immediately see what happens. You have instant access to all of the analysis tools in MATLAB, so you can take the results and analyze and visualize them. We hope that you will get a sense of the fun of modeling and simulation, through an environment that encourages you to pose a question, model it, and see what happens.

    With Simulink, you can move beyond idealized linear models to explore more realistic nonlinear models, factoring in friction, air resistance, gear slippage, hard stops, and the other things that describe real-world phenomena. It turns your computer into a lab for modeling and analyzing systems that simply wouldnt be possible or practical otherwise, whether the behavior of an automotive clutch system, the flutter of an airplane wing, the dynamics of a predator-prey model, or the effect of the monetary supply on the economy.

    Simulink is also practical. With thousands of engineers around the world using it to model and solve real problems, knowledge of this tool will serve you well throughout your professional career.

    We hope you enjoy exploring the software.

    What Is Simulink?Simulink is a software package for modeling, simulating, and analyzing dynamical systems. It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a hybrid of the two. Systems can also be multirate, i.e., have different parts that are sampled or updated at different rates.

    For modeling, Simulink provides a graphical user interface (GUI) for building models as block diagrams, using click-and-drag mouse operations. With this interface, you can draw the models just as you would with pencil and paper (or as most textbooks depict them). This is a far cry from previous simulation packages that require you to formulate differential equations and difference equations in a language or program. Simulink includes a comprehensive block

  • To the Reader

    1-3

    library of sinks, sources, linear and nonlinear components, and connectors. You can also customize and create your own blocks. For information on creating your own blocks, see the separate Writing S-Functions guide.

    Models are hierarchical, so you can build models using both top-down and bottom-up approaches. You can view the system at a high level, then double-click on blocks to go down through the levels to see increasing levels of model detail. This approach provides insight into how a model is organized and how its parts interact.

    After you define a model, you can simulate it, using a choice of integration methods, either from the Simulink menus or by entering commands in MATLABs command window. The menus are particularly convenient for interactive work, while the command-line approach is very useful for running a batch of simulations (for example, if you are doing Monte Carlo simulations or want to sweep a parameter across a range of values). Using scopes and other display blocks, you can see the simulation results while the simulation is running. In addition, you can change parameters and immediately see what happens, for what if exploration. The simulation results can be put in the MATLAB workspace for postprocessing and visualization.

    Model analysis tools include linearization and trimming tools, which can be accessed from the MATLAB command line, plus the many tools in MATLAB and its application toolboxes. And because MATLAB and Simulink are integrated, you can simulate, analyze, and revise your models in either environment at any point.

    How to Use This ManualBecause Simulink is graphical and interactive, we encourage you to jump right in and try it.

    For a useful introduction that will help you start using Simulink quickly, take a look at Running a Demo Model in Chapter 2. Browse around the model, double-click on blocks that look interesting, and you will quickly get a sense of how Simulink works. If you want a quick lesson in building a model, see Building a Simple Model in Chapter 2.

    For a technical introduction to Simulink, see Chapter 3, How Simulink Works. This chapter introduces many key concepts that you will need to understand how to create and run Simulink models.

  • 1 Getting Started

    1-4

    Chapter 4, Creating a Model describes in detail how to build and edit a model. It also discusses how to save and print a model and provides some useful tips.

    Chapter 5, Running a Simulation describes how Simulink performs a simulation. It covers simulation parameters and the integration solvers used for simulation, including some of the strengths and weaknesses of each solver that should help you choose the appropriate solver for your problem. It also discusses multirate and hybrid systems.

    Chapter 6, Analyzing Simulation Results discusses Simulink and MATLAB features useful for viewing and analyzing simulation results.

    Chapter 7, Using Masks to Customize Blocks discusses methods for creating your own blocks and using masks to customize their appearance and use.

    Chapter 8, Conditionally Executed Subsystems describes subsystems whose execution depends on triggering signals.

    Chapter 9, Block Reference provides reference information for all Simulink blocks.

    Chapter 10, Model Construction Commands provides reference information for commands you can use to create and modify a model from the MATLAB command window or from an M-file.

    Chapter 11, Simulink Debugger explains how to use the Simulink debugger to debug Simulink models. It also documents debugger commands.

    Chapter 12, Performance Tools explains how to use the Simulink accelerator and other optional tools that improve the performance of Simulink models.

    Appendix A, Model and Block Parameters lists model and block parameters. This information is useful with the get_param and set_param commands, described in Chapter 10.

    Appendix B, Model File Format describes the format of the file that stores model information.

    Although we have tried to provide the most complete and up-to-date information in this manual, some information may have changed after it was completed. Please check the Known Software and Documentation Problems in the Release Notes delivered with your Simulink system.

  • Related Products List

    1-5

    Related Products ListThe MathWorks provides several products that are especially relevant to the kinds of tasks you can perform with .

    For more information about any of these products, see either:

    The online documentation for that product if it is installed or if you are reading the documentation from the CD

    The MathWorks Web site, at http://www.mathworks.com; see the products section

    Note The toolboxes listed below all include functions that extend MATLABs capabilities. The blocksets all include blocks that extend Simulinks capabilities.

    Product Description

    CDMA Reference Blockset

    Simulink block libraries for the design and simulation of the IS-95A wireless communications standard

    Communications Blockset

    Simulink block libraries for modeling the physical layer of communications systems

    Communications Toolbox MATLAB functions for modeling the physical layer of communications systems

    Control System Toolbox Tool for modeling, analyzing, and designing control systems using classical and modern techniques

  • 1 Getting Started

    1-6

    Developers Kit for Texas Instruments DSP

    Developers kit that unites MATLAB, Simulink, and Real-Time Workshop code generation with the Texas Instruments Code Composer Studio to provide DSP software/systems architects with suite of tools for DSP development, from simulating signal processing algorithms to optimizing and running code on Texas Instruments DSPs

    Dials & Gauges Blockset Graphical instrumentation for monitoring and controlling signals and parameters in Simulink models

    DSP Blockset Simulink block libraries for the design, simulation, and prototyping of digital signal processing systems

    Filter Design Toolbox Advanced filter design and analysis methods for real-world systems with stringent specifications, including support for bit-true simulation and analysis of quantized filters, signals, and FFTs

    Fixed-Point Blockset Simulink blocks that model, simulate, and automatically generate pure integer code for fixed-point applications

    Frequency Domain System Identification Toolbox

    Tool for frequency domain model identification and validation

    Image Processing Toolbox

    Complete suite of digital image processing and analysis tools for MATLAB

    Instrument Control Toolbox

    Tool for communicating with instruments that

    support the GPIB (IEEE-488, HPIB) interface, the VISA standard, or the serial port interface

    Product Description

  • Related Products List

    1-7

    LMI Control Toolbox Convex optimization algorithms for solving linear matrix inequalities (LMI), with application to robust control, multi-objective control, and gain scheduling

    MATLAB Integrated technical computing environment that combines numeric computation, advanced graphics and visualization, and a high-level programming language

    MATLAB Compiler Compiler for automatically converting MATLAB M-files to C and C++ code

    MATLAB C/C++ Math Library

    Library for automatically converting MATLAB applications that contain math and graphics to C and C++ code for stand-alone applications

    MATLAB C/C++ Graphics Library

    Library for automatically compiling MATLAB programs that contain graphics and graphical user interfaces (GUIs) into complete stand-alone applications

    MATLAB Report Generator

    Tool for documenting information in MATLAB in multiple output formats

    MATLAB Runtime Server

    MATLAB environment in which you can take an existing MATLAB application and turn it into a stand-alone product that is easy and cost-effective to package and distribute. Users access only the features that you provide via your applications graphical user interface (GUI) - they do not have access to your code or the MATLAB command line.

    MATLAB Web Server Tool for the development and distribution of Web-based MATLAB applications

    Product Description

  • 1 Getting Started

    1-8

    Motorola DSP Developers Kit

    Developer's kit for co-simulating and verifying Motorola 56300 and 56600 fixed-point DSP code. Combines the algorithm development, simulation, and verification capabilities of the MathWorks system-level design tools with the Motorola Suite 56 assembly language development and debugging tools

    -Analysis and Synthesis Toolbox

    Computational algorithms for the structured singular value, m, applicable to robustness and performance analysis for systems with modeling and parameter

    Nonlinear Control Design Blockset

    Simulink block libraries that provide a time-domain-based optimization approach to system design; automatically tunes parameters based on user-defined time-domain performance constraints

    Optimization Toolbox Tool for general and large-scale optimization of nonlinear problems, as well as for linear programming, quadratic programming, nonlinear least squares, and solving nonlinear equations

    Power System Blockset Simulink block libraries for the design, simulation, and prototyping of electrical power systems

    Real-Time Workshop Ada Coder

    Tool that allows you to automatically generate Ada 95 code. It produces the code directly from Simulink models and automatically builds programs that can be run in real time in a variety of environments.

    Real-Time Windows Target

    Tool that allows you to run Simulink models interactively and in real time on your PC under Windows

    Product Description

  • Related Products List

    1-9

    Real-Time Workshop Tool that generates customizable C code from Simulink models and automatically builds programs that can run in real time in a variety of environments

    Requirements Management Interface

    Tool for navigating back and forth between requirements in DOORS, Word, Excel, and HTML and their implementations in MATLAB, Simulink, and Stateflow

    Robust Control Toolbox Tools for modeling, analysis, and design of robust multivariable feedback control systems using H

    techniques

    Signal Processing Toolbox

    Tool for algorithm development, signal and linear system analysis, and time-series data modeling

    Simulink Interactive, graphical environment for modeling, simulating, and prototyping dynamic systems

    Simulink Report Generator

    Tool for documenting information in Simulink and Stateflow in multiple output formats

    Stateflow Tool for graphical modeling and simulation of complex control logic

    Stateflow Coder Tool for generating highly readable, efficient C code from Stateflow diagrams

    System Identification Toolbox

    Tool for building accurate, simplified models of complex systems from noisy time-series data

    Virtual Reality Toolbox Tool for viewing and animating 3-D worlds through MATLAB and Simulink

    Product Description

  • 1 Getting Started

    1-10

    xPC Target Tool for adding I/O blocks to Simulink block diagrams and downloading the code generated by Real-Time Workshop to a second PC that runs the xPC Target real-time kernel, for rapid prototyping and hardware-in-the-loop testing of control and DSP systems

    xPC Target Embedded Option

    Add-on to xPC Target to deploy the xPC Target operating system, together with embedded code, to external PCs

    Product Description

  • 2

    Quick Start

    Running a Demo Model . . . . . . . . . . . . . . . 2-2Description of the Demo . . . . . . . . . . . . . . . . 2-3Some Things to Try . . . . . . . . . . . . . . . . . . 2-4What This Demo Illustrates . . . . . . . . . . . . . . 2-5Other Useful Demos . . . . . . . . . . . . . . . . . 2-5

    Building a Simple Model . . . . . . . . . . . . . . . 2-6

    Setting Simulink Preferences . . . . . . . . . . . . . 2-16Simulink Preferences . . . . . . . . . . . . . . . . . 2-16

  • 2 Quick Start

    2-2

    Running a Demo ModelAn interesting demo program provided with Simulink models the thermodynamics of a house. To run this demo, follow these steps:

    1 Start MATLAB. See your MATLAB documentation if youre not sure how to do this.

    2 Run the demo model by typing thermo in the MATLAB command window. This command starts up Simulink and creates a model window that contains this model.

    3 Double-click the Scope block labeled Thermo Plots.

    The Scope block displays two plots labeled Indoor vs. Outdoor Temp and Heat Cost ($), respectively.

    4 To start the simulation, pull down the Simulation menu and choose the Start command (or, on Microsoft Windows, press the Start button on the Simulink toolbar). As the simulation runs, the indoor and outdoor

  • Running a Demo Model

    2-3

    temperatures appear in the Indoor vs. Outdoor Temp plot and the cumulative heating cost appears in the Heat Cost ($) plot.

    5 To stop the simulation, choose the Stop command from the Simulation menu (or press the Pause button on the toolbar). If you want to explore other parts of the model, look over the suggestions in Some Things to Try on page 2-4.

    6 When youre finished running the simulation, close the model by choosing Close from the File menu.

    Description of the DemoThe demo models the thermodynamics of a house using a simple model. The thermostat is set to 70 degrees Fahrenheit and is affected by the outside temperature, which varies by applying a sine wave with amplitude of 15 degrees to a base temperature of 50 degrees. This simulates daily temperature fluctuations.

    The model uses subsystems to simplify the model diagram and create reusable systems. A subsystem is a group of blocks that is represented by a Subsystem block. This model contains five subsystems: one named Thermostat, one named House, and three Temp Convert subsystems (two convert Fahrenheit to Celsius, one converts Celsius to Fahrenheit).

    The internal and external temperatures are fed into the House subsystem, which updates the internal temperature. Double-click on the House block to see the underlying blocks in that subsystem.

    House subsystem

  • 2 Quick Start

    2-4

    The Thermostat subsystem models the operation of a thermostat, determining when the heating system is turned on and off. Double-click on the block to see the underlying blocks in that subsystem.

    Both the outside and inside temperatures are converted from Fahrenheit to Celsius by identical subsystems.

    When the heat is on, the heating costs are computed and displayed on the Heat Cost ($) plot on the Thermo Plots Scope. The internal temperature is displayed on the Indoor Temp Scope.

    Some Things to TryHere are several things to try to see how the model responds to different parameters:

    Each Scope block contains one or more signal display areas and controls that enable you to select the range of the signal displayed, zoom in on a portion of the signal, and perform other useful tasks. The horizontal axis represents time and the vertical axis represents the signal value.

    The Constant block labeled Set Point (at the top left of the model) sets the desired internal temperature. Open this block and reset the value to 80 degrees. See how the indoor temperature and heating costs change. Also, adjust the outside temperature (the Avg Outdoor Temp block) and see how it affects the simulation.

    Adjust the daily temperature variation by opening the Sine Wave block labeled Daily Temp Variation and changing the Amplitude parameter.

    Thermostat subsystem

    Fahrenheit to Celsius conversion (F2C)

  • Running a Demo Model

    2-5

    What This Demo IllustratesThis demo illustrates several tasks commonly used when building models:

    Running the simulation involves specifying parameters and starting the simulation with the Start command, described in Running a Simulation Using Menu Commands on page 5-4.

    You can encapsulate complex groups of related blocks in a single block, called a subsystem. See Creating Subsystems on page 4-77 for more information.

    You can create a customized icon and design a dialog box for a block by using the masking feature, described in detail in Chapter 7, Using Masks to Customize Blocks. In the thermo model, all Subsystem blocks have customized icons created using the masking feature.

    Scope blocks display graphic output much as an actual oscilloscope does. See Scope, Floating Scope on page 9-236 for more information.

    Other Useful DemosOther demos illustrate useful modeling concepts. You can access these demos from the Simulink block library window:

    1 Type simulink3 in the MATLAB command window. The Simulink block library window appears.

    2 Double-click on the Demos icon. The MATLAB Demos window appears. This window contains several interesting sample models that illustrate useful Simulink features.

    The Demos icon

  • 2 Quick Start

    2-6

    Building a Simple ModelThis example shows you how to build a model using many of the model building commands and actions you will use to build your own models. The instructions for building this model in this section are brief. All of the tasks are described in more detail in the next chapter.

    The model integrates a sine wave and displays the result, along with the sine wave. The block diagram of the model looks like this.

    To create the model, first type simulink in the MATLAB command window. On Microsoft Windows, the Simulink Library Browser appears.

  • Building a Simple Model

    2-7

    On UNIX, the Simulink library window appears.

    To create a new model on UNIX, select Model from the New submenu of the Simulink library windows File menu. To create a new model on Windows, select the New Model button on the Library Browsers toolbar.

    New model button

  • 2 Quick Start

    2-8

    Simulink opens a new model window.

    To create this model, you will need to copy blocks into the model from the following Simulink block libraries:

    Sources library (the Sine Wave block) Sinks library (the Scope block) Continuous library (the Integrator block) Signals & Systems library (the Mux block)

    You can copy a Sine Wave block from the Sources library, using the Library Browser (Windows only) or the Sources library window (UNIX or Windows).

    To copy the Sine Wave block from the Library Browser, first expand the Library Browser tree to display the blocks in the Sources library. Do this by clicking on the Sources node to display the Sources library blocks. Finally click on the Sine Wave node to select the Sine Wave block.

  • Building a Simple Model

    2-9

    Here is how the Library Browser should look after you have done this.

    Now drag the Sine Wave block from the browser and drop it in the model window. Simulink creates a copy of the Sine Wave block at the point where you dropped the node icon.

    To copy the Sine Wave block from the Sources library window, open the Sources window by double-clicking on the Sources icon in the Simulink library window. (On Windows, you can open the Simulink library window by right-clicking the Simulink node in the Library Browser and then clicking the resulting Open Library button.)

    Simulink library

    Sources library

    Sine Wave block

  • 2 Quick Start

    2-10

    Simulink displays the Sources library window.

    Now drag the Sine Wave block from the Sources window to your model window.

    Copy the rest of the blocks in a similar manner from their respective libraries into the model window. You can move a block from one place in the model window to another by dragging the block. You can move a block a short distance by selecting the block, then pressing the arrow keys.

    The Sine Wave block

  • Building a Simple Model

    2-11

    With all the blocks copied into the model window, the model should look something like this.

    If you examine the block icons, you see an angle bracket on the right of the Sine Wave block and two on the left of the Mux block. The > symbol pointing out of a block is an output port; if the symbol points to a block, it is an input port. A signal travels out of an output port and into an input port of another block through a connecting line. When the blocks are connected, the port symbols disappear.

    Now its time to connect the blocks. Connect the Sine Wave block to the top input port of the Mux block. Position the pointer over the output port on the right side of the Sine Wave block. Notice that the cursor shape changes to cross hairs.

    Hold down the mouse button and move the cursor to the top input port of the Mux block.

    Output portInput port

  • 2 Quick Start

    2-12

    Notice that the line is dashed while the mouse button is down and that the cursor shape changes to double-lined cross hairs as it approaches the Mux block.

    Now release the mouse button. The blocks are connected. You can also connect the line to the block by releasing the mouse button while the pointer is inside the icon. If you do, the line is connected to the input port closest to the cursors position.

    If you look again at the model at the beginning of this section (see Building a Simple Model on page 2-6), youll notice that most of the lines connect output ports of blocks to input ports of other blocks. However, one line connects a line to the input port of another block. This line, called a branch line, connects the Sine Wave output to the Integrator block, and carries the same signal that passes from the Sine Wave block to the Mux block.

    Drawing a branch line is slightly different from drawing the line you just drew. To weld a connection to an existing line, follow these steps:

    1 First, position the pointer on the line between the Sine Wave and the Mux block.

  • Building a Simple Model

    2-13

    2 Press and hold down the Ctrl key (or click the right mouse button). Press the mouse button, then drag the pointer to the Integrator blocks input port or over the Integrator block itself.

    3 Release the mouse button. Simulink draws a line between the starting point and the Integrator blocks input port.

    Finish making block connections. When youre done, your model should look something like this.

    Now, open the Scope block to view the simulation output. Keeping the Scope window open, set up Simulink to run the simulation for 10 seconds. First, set the simulation parameters by choosing Simulation Parameters from the Simulation menu.

  • 2 Quick Start

    2-14

    On the dialog box that appears, notice that the Stop time is set to 10.0 (its default value).

    Close the Simulation Parameters dialog box by clicking on the OK button. Simulink applies the parameters and closes the dialog box.

    Choose Start from the Simulation menu and watch the traces of the Scope blocks input.

    The simulation stops when it reaches the stop time specified in the Simulation Parameters dialog box or when you choose Stop from the Simulation menu or press the Stop button on the model windows toolbar (Windows only).

    Stop time parameter

  • Building a Simple Model

    2-15

    To save this model, choose Save from the File menu and enter a filename and location. That file contains the description of the model.

    To terminate Simulink and MATLAB, choose Exit MATLAB (on a Microsoft Windows system) or Quit MATLAB (on a UNIX system). You can also type quit in the MATLAB command window. If you want to leave Simulink but not terminate MATLAB, just close all Simulink windows.

    This exercise shows you how to perform some commonly used model-building tasks. These and other tasks are described in more detail in Chapter 4, Creating a Model.

  • 2 Quick Start

    2-16

    Setting Simulink PreferencesThe MATLAB Preferences dialog box allows you to specify default settings for many Simulink options. To display the Preferences dialog box, select Preferences from the Simulink File menu.

    Simulink PreferencesThe Preferences dialog box allows you to specify the following Simulink preferences.

    Window reuseSpecifies whether Simulink uses existing windows or opens new windows to display a models subsystems (see Window Reuse on page 4-80).

    Model BrowserSpecifies whether Simulink displays the browser when you open a model and whether the browser shows blocks imported from subsystems and the contents of masked subsystems (see The Model Browser on page 4-115).

  • Setting Simulink Preferences

    2-17

    DisplaySpecifies whether to use thick lines to display nonscalar connections between blocks and whether to display port data types on the block diagram (see Setting Signal Display Options on page 4-42).

    Callback tracingSpecifies whether to display the model callbacks that Simulink invokes when simulating a model (see Using Callback Routines on page 4-83).

    Simulink FontsSpecifies fonts to be used for block and line labels and diagram annotations.

    SolverSpecifies simulation solver options (see The Solver Pane on page 5-8).

    WorkspaceSpecifies workspace options for simulating a model (see The Workspace I/O Pane on page 5-19).

    DiagnosticsSpecifies diagnostic options for simulating a model (see The Diagnostics Pane on page 5-26).

    AdvancedSpecifies advanced simulation preferences (see The Advanced Pane on page 530).

  • 2 Quick Start

    2-18

  • 3

    How Simulink Works

    What Is Simulink . . . . . . . . . . . . . . . . . . 3-2

    Modeling Dynamic Systems . . . . . . . . . . . . . . 3-3Block Diagrams . . . . . . . . . . . . . . . . . . . 3-3Blocks . . . . . . . . . . . . . . . . . . . . . . . 3-3States . . . . . . . . . . . . . . . . . . . . . . . 3-4System Functions . . . . . . . . . . . . . . . . . . 3-4Block Parameters . . . . . . . . . . . . . . . . . . 3-5Continuous Versus Discrete Blocks . . . . . . . . . . . 3-6Subsystems . . . . . . . . . . . . . . . . . . . . . 3-6Custom Blocks . . . . . . . . . . . . . . . . . . . . 3-7Signals . . . . . . . . . . . . . . . . . . . . . . . 3-7Data Types . . . . . . . . . . . . . . . . . . . . . 3-7Solvers . . . . . . . . . . . . . . . . . . . . . . . 3-8

    Simulating Dynamic Systems . . . . . . . . . . . . . 3-9Model Initialization Phase . . . . . . . . . . . . . . . 3-9Model Execution Phase . . . . . . . . . . . . . . . . 3-9Processing at Each Time Step . . . . . . . . . . . . . 3-10Determining Block Update Order . . . . . . . . . . . . 3-11Atomic Versus Virtual Subsystems . . . . . . . . . . . 3-13Solvers . . . . . . . . . . . . . . . . . . . . . . . 3-13Zero Crossing Detection . . . . . . . . . . . . . . . . 3-15Algebraic Loops . . . . . . . . . . . . . . . . . . . 3-19

    Modeling and Simulating Discrete Systems . . . . . . . 3-24Discrete Blocks . . . . . . . . . . . . . . . . . . . 3-24Sample Time . . . . . . . . . . . . . . . . . . . . 3-24Purely Discrete Systems . . . . . . . . . . . . . . . . 3-24Multirate Systems . . . . . . . . . . . . . . . . . . 3-25Determining Step Size for Discrete Systems . . . . . . . . 3-25Sample Time Propagation . . . . . . . . . . . . . . . 3-27Invariant Constants . . . . . . . . . . . . . . . . . 3-28Mixed Continuous and Discrete Systems . . . . . . . . . 3-29

  • 3 How Simulink Works

    3-2

    What Is SimulinkSimulink is a software package that enables you to model, simulate, and analyze systems whose outputs change over time. Such systems are often referred to as dynamic systems. Simulink can be used to explore the behavior of a wide range of real-world dynamic systems, including electrical circuits, shock absorbers, braking systems, and many other electrical, mechanical, and thermodynamic systems.

    Simulating a dynamic system is a two-step process with Simulink. First, you create a graphical model of the system to be simulated, using Simulinks model editor. The model depicts the time-dependent mathematical relationships among the systems inputs, states, and outputs (see Modeling Dynamic Systems on page 3-3). Then, you use Simulink to simulate the behavior of the system over a specified time span. Simulink uses information that you entered into the model to perform the simulation (see Simulating Dynamic Systems on page 3-9).

  • Modeling Dynamic Systems

    3-3

    Modeling Dynamic SystemsSimulink provides a library browser that allows you to select blocks from libraries of standard blocks (see Chapter 9, Block Reference) and a graphical editor that allows you to draw lines connecting the blocks (see Chapter 4, Creating a Model). You can model virtually any real-world dynamic system by selecting and interconnecting the appropriate Simulink blocks.

    Block DiagramsA Simulink block diagram is a pictorial model of a dynamic system. It consists of a set of symbols, called blocks, interconnected by lines. Each block represents an elementary dynamic system that produces an output either continuously (a continuous block) or at specific points in time (a discrete block). The lines represent connections of block inputs to block outputs. Every block in a block diagram is an instance of a specific type of block. The type of the block determines the relationship between a blocks outputs and its inputs, states, and time. A block diagram can contain any number of instances of any type of block needed to model a system.

    Note The MATLAB Based Books page on the MathWorks Web site includes texts that discuss the use of block diagrams in general, and Simulink in particular, to model dynamic systems.

    BlocksBlocks represent elementary dynamic systems that Simulink knows how to simulate. A block comprises one or more of the following: a set of inputs, a set of states, and a set of outputs.

    A blocks output is a function of time and the blocks inputs and states (if any). The specific function that relates a blocks output to its inputs, states, and time depends on the type of block of which the block is an instance.

    x(states)u

    (input)y

    (output)

  • 3 How Simulink Works

    3-4

    StatesBlocks can have states. A state is a variable that determines a blocks output and whose current value is a function of the previous values of the blocks states and/or inputs. A block that has a state must store previous values of the state to compute its current state. States are thus said to be persistent. Blocks with states are said to have memory because such blocks must store the previous values of their states and/or inputs in order to compute the current values of the states.

    The Simulink Integrator block is an example of a block that has a state. The Integrator block outputs the integral of the input signal from the start of the simulation to the current time. The integral at the current time step depends on the history of Integrator blocks input. The integral therefore is a state of the Integrator block and is, in fact, its only state. Another example of a block with states is the Simulink Memory block. A Memory block stores the values of its inputs at the current simulation time and outputs them at a later time. The states of a Memory block are the previous values of its inputs.

    The Simulink Gain block is an example of a stateless block. A Gain block outputs its input signal multiplied by a constant called the gain. The output of a Gain block is determined entirely by the current value of the input and the gain, which does not vary. A Gain block therefore has no states. Other examples of stateless blocks include the Sum and Product blocks. The output of these blocks is purely a function of the current values of their inputs (the sum in one case, the product in the other). Thus, these blocks have no states.

    System FunctionsEach Simulink block type is associated with a set of system functions that specify the time-dependent relationships among its inputs, states, and outputs. The system functions include:

    An output function, fo, that relates the systems outputs to its inputs, states, and time

    An update function, fu, that relates the future values of the systems discrete states to the current time, inputs, and states

    A derivative function, fd, that relates the derivatives of the systems continuous states to time and the present values of the blocks states and inputs

  • Modeling Dynamic Systems

    3-5

    Symbolically, the system functions may be expressed as follows

    where t is the current time, x is the blocks states, u is the blocks inputs, y is the blocks outputs, xd is the blocks discrete derivatives, and x'c is the derivatives of the blocks continuous states. During a simulation, Simulink invokes the system functions to compute the values of the systems states and outputs.

    Block ParametersKey properties of many standard blocks are parameterized. For example, the gain of Simulinks standard Gain block is a parameter. Each parameterized block has a block dialog that lets you set the values of the parameters when editing or simulating the model. You can use MATLAB expressions to specify parameter values. Simulink evaluates the expressions before running a simulation. You can change the values of parameters during a simulation. This allows you to determine interactively the most suitable value for a parameter.

    A parameterized block effectively represents a family of similar blocks. For example, when creating a model, you can set the gain parameter of each instance of the Gain block separately so that each instance behaves differently. Because it allows each standard block to represent a family of blocks, block parameterization greatly increases the modeling power of Simulinks standard libraries.

    Tunable ParametersMany block parameters are tunable. A tunable parameter is a parameter whose value can change while Simulink is executing a model. For example, the gain parameter of the Gain block is tunable. You can alter the blocks gain while a simulation is running. If a parameter is not tunable and the simulation is running, Simulink disables the dialog box control that sets the parameter. Simulink allows you to specify that all parameters are nontunable in your

    y fo t x u, ,( )=xdk 1+ fu t x u, ,( )=

    xc fd t x u, ,( )=

    xxcxdk

    =where

    Output function

    Update function

    Derivative function

  • 3 How Simulink Works

    3-6

    model, except for those that you specify. This can speed up execution of large models and enable generation of faster code from your model. See Model parameter configuration on page 530 for more information.

    Continuous Versus Discrete BlocksSimulinks standard block set includes continuous blocks and discrete blocks. Continuous blocks respond continuously to continuously changing input. Discrete blocks, by contrast, respond to changes in input only at integral multiples of a fixed interval called the blocks sample time. Discrete blocks hold their output constant between successive sample time hits. Each discrete block includes a sample time parameter that allows you to specify its sample rate. Examples of continuous blocks include the Constant block and the blocks in Simulinks Continuous block library. Examples of discrete blocks include the Discrete Pulse Generator and the blocks in the Discrete block library.

    Many Simulink blocks, for example, the Gain block, can be either continuous or discrete, depending on whether they are driven by continuous or discrete blocks. A block that can be either discrete or continuous is said to have an implicit sample rate. The implicit sample time is continuous if any of the blocks inputs are continuous. The implicit sample time is equal to the shortest input sample time if all the input sample times are integral multiples of the shortest time. Otherwise, the input sample time is equal to the fundamental sample time of the inputs, where the fundamental sample time of a set of sample times is defined as the greatest integer divisor of the set of sample times.

    Simulink can optionally color code a block diagram to indicate the sample times of the blocks it contains, e.g., black (continuous), magenta (constant), yellow (hybrid), red (fastest discrete), and so on. See Mixed Continuous and Discrete Systems on page 3-29 for more information.

    SubsystemsSimulink allows you to model a complex system as a set of interconnected subsystems each of which is represented by a block diagram.You create a subsystem using Simulinks Subsystem block and the Simulink model editor. You can embed subsystems with subsystems to any depth to create hierarchical models. You can create conditionally executed subsystems that are executed only when a transition occurs on a triggering or enabling input (see Chapter 8, Conditionally Executed Subsystems.).

  • Modeling Dynamic Systems

    3-7

    Custom BlocksSimulink allows you to create libraries of custom blocks that you can then use in your models. You can create a custom block either graphically or programmatically. To create a custom block graphically, you draw a block diagram representing the blocks behavior, wrap this diagram in an instance of Simulinks Subsystem block, and provide the block with a parameter dialog, using Simulinks block mask facility. To create a block programmatically, you create an M-file or a MEX-file that contains the blocks system functions (see Writing S-Functions ). The resulting file is called an S-function. You then associate the S-function with instances of Simulinks S-function block in your model. You can add a parameter dialog to your S-function block by wrapping it in a Subsystem block and adding the parameter dialog to the Subsystem block.

    SignalsSimulink uses the term signal to refer to the output values of blocks. S