Mathworks SIMULINK 7 Installation Guide

Simulink
®
7
Getting Started Guide
How to Contact The MathWorks
www.mathworks. comp.soft-sys.matlab Newsgroup www.mathworks.com/contact_TS.html Technical Support
suggest@mathworks.com Product enhancement suggestions
bugs@mathwo doc@mathworks.com Documentation error reports service@mathworks.com Order status, license renewals, passcodes
info@mathwo
com
rks.com
rks.com
Web
Bug reports
Sales, prici
ng, and general information
508-647-7000 (Phone)
508-647-7001 (Fax)
The MathWorks, Inc. 3 Apple Hill Drive Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
®
Simulink
© COPYRIGHT 1990–20 10 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 reproduced in any form without prior written consent from The MathW orks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government’s needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Docu mentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Getting Started Guide
Revision History
September 2005 Online only New for Version 6.3 (Release 14SP3) March 2006 Online only Revised for Simulink September 2006 Online only Revised for Simulink March 2007 First printing Revised for Simulink September 2007 Second printing Revised for Simulink March 2008 Third printing Revised for Simulink October 2008 Fourth printing Revised for Simulink March 2009 Fifth printing Revised for Simulink September 2009 Online only Revised for Simulink March 2010 Online only Revised for Simulink
®
6.4 (Release 2006a)
®
6.5 (Release 2006b)
®
6.6 (Release 2007a)
®
7.0 (Release 2007b)
®
7.1 (Release 2008a)
®
7.2 (Release 2008b)
®
7.3 (Release 2009a)
®
7.4 (Release 2009b)
®
7.5 (Release 2010a)
Introduction
1
Product Overview ................................. 1-2
Overview Tool for Model-Based Design Tool for Simulation Tool for Analysis How Simulink Software Interacts with the MATLAB
Environment
........................................ 1-2
........................ 1-3
................................ 1-4
.................................. 1-4
................................... 1-4
Contents
What Is Model-Based Design?
Model-Based Design Modeling Process
Related Products
............................... 1-5
.................................. 1-6
.................................. 1-9
....................... 1-5
Simulink Software Basics
2
Starting Simulink Software ........................ 2-2
Opening the Simulink Library Browser Opening a Model
Simulink User Interface
Simulink Library Browser Simulink Model Window
Getting Help with Sim ulin k Software
Simulink Online Help Simulink Demo Models Web Site Resources
.................................. 2-4
............................ 2-6
.......................... 2-6
............................ 2-9
.............................. 2-10
............................. 2-11
................................ 2-14
............... 2-2
............... 2-10
v
Creating a Simulink Model
3
Overview ......................................... 3-2
Creating a Simple Model
Overview Creating a New Model Adding Blocks to Your Model Moving Blocks in the Model Window Connecting Blocks in the Model Window Saving the Model
Simulating the Model
Overview Setting Simulation Options Running the Simulation and Observing Results
........................................ 3-3
.................................. 3-13
........................................ 3-14
........................... 3-3
............................. 3-3
........................ 3-5
.................. 3-8
............... 3-9
.............................. 3-14
......................... 3-14
......... 3-16
Modeling a Dynamic Control System
4
Overview ......................................... 4-2
Understanding the Demo M odel
Opening the Demo Model Anatomy of the Demo Model Using Subsystems Masking Subsystems
................................. 4-6
........................... 4-3
.............................. 4-9
..................... 4-3
........................ 4-5
vi Contents
Simulating the Model
Running the Simulation Modifying Simulation Parameters Importing Data from the MATLAB Workspace Exporting Simulation Data to the MATLAB Workspace
.............................. 4-11
............................ 4-11
.................... 4-13
......... 4-20
.. 4-25
Index
vii
viii Contents
Introduction
“Product Overview” on page 1-2
“What Is Model-Based Design ?” on page 1-5
“Related Products” on page 1-9
1
1 Introduction
Product Overview
Overview
Simulink®software models, simulates, and analyzes dynamic systems. It enables you to pose a question about a system, model the system, and see what happens.
In this section...
“Overview” on page 1-2
“Tool for Model-Based Design” on page 1-3
“Tool for Sim ulation” on page 1-4
“Tool for Analys is” on page 1-4
“How Simulink Software Interacts with the MATLAB Environment” on page 1-4
1-2
With Simulink, you can easily build models from scratch, or modify existing models to meet your needs. Simulink supports linear and nonlinear systems, modeled in continuous time, sampled time, or a hybrid of the two. Systems can also be multirate — having d ifferent parts that are sampled or updated at different rates.
Thousands of scientists and engineers around the world use Simulink to modelandsolverealproblemsinavariety o f industries, including:
Aerospace and Defense
Automotive
Communications
Electronics and Signal Processing
Medical Instrumentation
Product Overview
Tool for Model-Based Design
With Simulink, you can move beyond idealized linear models to explore more realistic nonlinear models, f actori ng in friction, air resistance, gear slippage, hard stops, and the other things that describe real-world phenomena. Simulink turns your computer into a laboratory for modeling and analyzing systems that would not be possible or practical otherwise.
Whether you are interested in the behavior of an automotive clutch system, the flutter of an airplane wing, or the effect of the monetary supply on the economy, Simulink provides you with the tools to model and simulate almost any real-world problem. Simulink also provides demos that model a wide variety of real-world phenomena (see “Simulink Demo Models” on page 2-11).
Simulink provides a graphical user interface (GUI) for building models as block diagrams, allowing you to draw models as you would with pencil and paper. Simulink also includes a comprehensive block library of sinks, sources, linear and nonlinear components, and connectors. If these blocks do not meet your needs, however, you can also create your own blocks. The interactive graphical environment simplifies the modeling process, eliminating the need to formulate differential and difference equations in a language or program.
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 blocks to see increasing levels of model detail. This approach provides insight into how a model is organized and how its parts interact.
1-3
1 Introduction
Tool for Simulation
After you define a model, you can simulate it, using a choice of mathematical integration methods, either from the Simulink menus or by entering commands in the MATLAB for interactive work, while the command line is useful for running a batch of simulations (for example, if you are doing Monte Carlo simulations or want to apply a parameter across a range of values).
Using scopes and other display blocks, you can see the simulation results while the simulation runs. You can then change many parameters and see what happens for “what if” exploration. The simulation results can be put in the MATLAB workspace for postprocessing and visualization.
®
Command Window. The menus are convenient
Tool for Analysis
Model analysis too ls include linearization and trimming tools, which can be accessed from the M ATLAB command line, plus the many tools in M ATLAB and its application toolboxes. Because MATLAB and Simulink are integrated, youcansimulate,analyze,andreviseyour models in either environment at any point.
1-4
How Simulink Software Interacts with the MATLAB Environment
Simulink software is tightly integrated with the MATLAB environment. It requires MATLAB to run, depending on it to define and evaluate model and block parameters. Simulink can also utilize many MATLAB features. For example, Simulink can use the MATLAB environment to:
Define model inputs.
Store model o utputs for analysis and visualization.
Perform functions within a model, through integrated calls to MATLAB
operators and functions.
What Is Model-Based Design?
In this section...
“Model-Based Design” on page 1-5
“Modeling Process” o n page 1-6
Model-Based Design
Model-Based Design is a process that enables faster, more cost-effective development of dynamic systems, includin g control systems, signal processing, and communications systems. In Model-Based Design, a system model is at the center of the development process, from requirements development, through design, implementation, and testing. The model is an executable specification that is continually refined throughout the dev elo pment process. After model development, simulation shows whether the model works correctly.
When software a nd hardware implementation requirements are included, such as fixed-point and timing behavior, you can automatically generate code for embedded deployment and create tes t benches for system verification, saving time and avoiding the introduction of manually coded errors.
What Is Model-Based Design?
Model-Based Design allows you to improve efficiency by :
Using a common design environment across project teams
Linking designs directly to requirements
Integrating testing with design to continuously identify and correct errors
Refining algorithms through multidomain simulation
Automatically generating embedded software code
Developing and reusing test suites
Autom atically generating documentation
Reusing d esigns to deploy systems across multiple processors and hardware
targets
1-5
1 Introduction
Modeling Proces
There are six ste
1 Defining the Sy
2 Identifying System Components
3 Modeling the System with Equations
4 Building the
5 Running the Simulation
6 Validating the Simulation Results
You perform the first three steps of this process outside of the Simulink software before you begin building your model.
Defining
The first step in modeling a dynamic system is to fully define the system. If you are modeling a large system that can be broken into parts, you should model each subcomponent on its own. The n, after building each component, you can integrate them into a complete model of the system.
ps to modeling any system:
Simulink Block Diagram
the System
s
stem
1-6
For example, the demo model used l ater in th is guide models the heating system of a house. This system can be broken down into three m ain parts:
Heater subsystem
Thermostat subsystem
Thermodynamic model subsystem
The most effective way to build a model of this system is to consider each of these subsystems independently.
ntifying System Components
Ide
The second step in the modeling process is to identify the system components. Three types of components define a system:
What Is Model-Based Design?
Parameters — System values that remain constant unless you change
them
States — Variables in the system that change over time
Signals — Input and output values that change dynamically during the
simulation
In Simulink, parameters and states are represented by blocks, while signals are represented by the lines that connect blocks.
For each subsystem that you identified, ask yourself the fo ll owing questions:
How many input signals does the subsystem have?
How many output signals does the subsystem have?
How many states (variables) does the subsystem have ?
What are the parameters (constants) in the subsystem?
Are there any intermediate (internal) s ignals in the subsystem?
Once you have answered these questions, you should have a comprehensive list of the system components, and are ready to begin modeling the system.
Modeling the System with Equations
The third step in modeling a system is to formu l ate the mathematical equations that describe the system.
For each subsystem, use the list of system compo nents you identified to describe the system mathematically. Your model may include:
Algebraic equations
Logical equations
Differential equations, for continuous systems
Difference equations, for discrete systems
You use these equations to create the block diagram in Simulink.
1-7
1 Introduction
Building the Simulink Block Diagram
After you have defined the mathematical equations that describe each subsystem, you can begin building a block diagram of your model in Simulink.
Build the block diagram for each of your subcomponents separately. After you have modeled each subcomponent, you can then integrate them into a complete model of the system.
See “Cre ating a S imple Model” on page 3-3 for more information on building the block diagram.
Running the Simulation
After you build the Simulink block diagram, you can simulate the m o del and analyze the results.
Simulink allows you to interactively define system inputs, simulate the model, and observe changes in behavior. This allows you to quickly evaluate your model.
1-8
See“SimulatingtheModel”onpage3-14formoreinformationonrunninga simulation.
Validating the Simulation Results
Finally, you must validate that the model accurately represents the physical characteristics of the system.
You can use the linearization and trimming tools available from the MATLAB command line, plus the many tools in MATLAB and its application toolboxes to analyze and validate your model.
Related Products
The MathWorks™ provides many additional products that extend the capabilities of Simulink software. F or information about these related products, see http://www.m athworks.com/products/simulink/.
Related Products
1-9
1 Introduction
1-10
Simulink Software Basics
“Starting Simulink Software” on page 2-2
“Simulink User Interface” on page 2-6
“Getting Help w ith Simulink Software” on page 2-10
2
2 Simulink
®
Software Basics
Starting Simulink Software
In this section...
“Opening the Simulink Library Browser” on page 2-2
“Opening a M odel” on page 2-4
Opening the Simulink Library Browser
Your M ATLAB environment must be running before you can open Simulink software. You start Simulink from within MATLAB.
To start Simulink and open the Simulink Library Browser:
1 Start MATLAB. For more information, see “Starting a MATLAB Session”
in the MATLAB Getting Started Gu ide.
2 Enter simulink in the MATLAB Command Window.
2-2
The Simulink Library Browser opens.
Starting Simulink®Software
Note You can also start Simulink by:
Clicking the Simulink icon
in the MATLAB toolbar
Clicking the MATLAB Start button, then selecting Simulink > Library
Browser
2-3
2 Simulink
®
Software Basics
Opening a Model
You can open e xis Simulink Librar
ting Simulink models or create new models from the
yBrowser.
To create a new m
Select File > N
Thesoftwareo
odel:
ew > Mode l in the Simulink Library Browser.
pens an empty model window.
2-4
Starting Simulink®Software
To open an existing model:
1 Select File > Open in the Simulink Library Browser.
The Open dialog box appears.
2 Select the model (.mdl file) you want to open, then click Open.
The software opens the selected model in the model window.
2-5
2 Simulink
®
Software Basics
Simulink User Interface
In this section...
“Simulink Library Browser” on page 2-6
“Simulink Model Window” on page 2-9
Simulink Library Browser
The Library Browser displays the Simulink block libraries installed on your system. You build models b y copying blocks from a library into a model window.
Block Search
2-6
Selected Library
Block Description
Simulink®Library Browser
Selected Block
Simulink®User Interface
Tips for Using the Library Browser
When using t h e Library Browser, note the following:
You can view the blocks in a library by selecting the library name on the
left side of the Library Browser, or by double-clicking the library.
When you select a block, a description of that block appears at the bottom
of the browser.
For more information on a block, select the block, then select Help > Help
on the Selected Block to display the help page for the block.
You can view the parameters for a block by right-clicking the block, then
selecting Block Parameters.
You can search for a specific block by entering the name of the block in the
block search field, then clicking the Find block icon
.
Standard Block Libraries
Simulink software provides 16 standard block libraries. The following table describes each of these libraries.
Block Library
Commonly Used Blocks
Continuous Contains blocks that model linear functions, such as
Discontinuities
Discrete
Logic and Bit Operations
Description
Contains a group of the most commonly used blocks, such as the Constant, In1, Out1, Scope,andSum blocks. Each of the blocks in this library are also included in other libra ries.
the Derivative and Integrator blocks.
Contains blocks with outputs that are discontinuous functions of their inputs, such as the Saturation block.
Contains blocks that represent discrete time functions, such as the Unit Delay block.
Contains blocks that perform logic or bit operations, such as the Logical Operator and Relational
Operator blocks.
2-7
2 Simulink
®
Software Basics
Block Library
LookUp Tables
Description
Contains blocks that use lookup tables to determine their outputs from their inputs, such as the Cosine and Sine blocks.
Math Operations Contains blocks that perform mathematical and
logical functions, such as the Gain, Product,and
Sum blocks.
Model Verification
Contains blocks that enable you to create self-validating models, such as the Check Input
Resolution block.
Model-Wide Utilities
Ports & Subsystems
Contains blocks that provide information about the model, such as the Model Info block.
Contains blocks that allow you to create subsystems, such as the In1, Out1,andSubsystem blocks.
Signal Attributes Contains blocks that modify the attributes of signals,
such as the Data Type Conversion block.
Signal Routing Contains blocks that route signals from one point in
a block diagram to another, such as the Mux and
Switch blocks.
Sinks Contains blocks that display or export output, such
as the Out1 and Scope blocks.
2-8
Sources Contains blocks that generate or import system
inputs, such as the Constant, In1,andSine Wave blocks.
User-Defined Functions
Contains blocks that allow you to define custom functions, such as the Embedded MATLAB
®
Function block.
Additional Math &Discrete
Contains two additional libraries for mathematical and discrete function blocks.
Simulink®User Interface
Simulink Model W
The model window in the model wind each block, and
The model window also allows you to:
contains the block diagram of the model. You build models
ow by arranging blocks logically, setting the parameters for
then connecting the blocks with signal lines.
indow
Set configuration parameters for the model, including the start and stop
time, type of solver to use, and data import/export settings.
Start and stop simulation of the model.
Save the model.
Print the block diagram.
2-9
2 Simulink
®
Software Basics
Getting Help with Simulink Software
In this section...
“Simulink Online Help” on page 2-10
“Simulink Demo Models” on page 2-11
“Web Site Resources” on page 2-14
Simulink Online Help
Simulink software provides comprehensive o nline help that describes Simulink features, blocks, and functions, and provides detailed procedures for common tasks. The help includes online versions of all Simulink documentation, including:
Simulink Getting Started Guide (this guide)
Simulink User’s Guide
2-10
Simulink Reference
Writing S-Functions
Simulink Release Notes
You access the online help from the Help menu of the Simulink Library Browser or model w indow .
Toaccesstheonlinehelp:
From the Simulink Library Browser, select Help > Simulink Help.
From the Simulink model window, select Help > Using Simulink.
Note To quickly access the help page for a specific block, right-click the
block and select Help.
Getting Help with Simulink®Software
Simulink Demo Mo
Simulink softwa modeling concep the MATLAB C omm
To access Simu
1 On the bottom l
Start button
The Start menu appears.
2 Select Simulink > Demos from the Start menu.
re provides a variety of demo models that illustrate key ts and Simulink features. You can access these dem os from
and Window.
link demos:
eft corner of the MATLAB Command Window, click the
.
dels
2-11
2 Simulink
®
Software Basics
2-12
Getting Help with Simulink®Software
3 From the Simulink demos page in the MATLAB Help browser, click the
demo model you want to open.
2-13
2 Simulink
®
Software Basics
Web Site Resourc
You can access ad site, including support.
To access the S
http://www.m
ditional Simulink resources on the MathWorks™ Web
Simulink related books, prerecorded webinars, and technical
imulink product page, go to:
athworks.com/products/simulink
es
2-14
3
Creating a Simulink Model
“Overview” on page 3-2
“Creating a Simple Model” on page 3-3
“Simulating the Model” on page 3-14
3 Creating a Simulink
Overview
®
Model
This chapter describes how to create a simple model using Simulink software, and h ow to simulate that model. The basic techniques you use to create and simulate this simple model are the same as those for more complex models.
The model described in this chapter integrates a sine wave and displays the result along with the original w a ve. When completed, the block diagram of the model should look similar to this:
3-2
The instructions for constructing and simulating the example model are brief. However, each task is described in more detail in Simulink User’s Guide.
Creating a Simple Model
In this section...
“Overview” on page 3-3
“Creating a New Model” on page 3-3
“Adding Blocks to Your Model” on page 3-5
“Moving Blocks in the Model Window” on page 3-8
“Connecting B locks in the Model Window” on page 3-9
“Saving the Model” on page 3-13
Overview
This section describes how to model a simple dynamic system using Simulink software. A fter you create the model, you can simulate it as described in “Simulating the Model” on page 3-14.
Creating a Simple Model
Creating a New Model
Before you can begin building your model, you must start Simulink and create an empty model.
To create a new model:
1 If Simulink is not running, enter simulink in the MATLAB Command
Window to open the Simulink Library Browser.
2 Select File>New>Modelin the Simulink Library Browser to create a
new model.
software opens an empty model window.
The
3-3
3 Creating a Simulink
®
Model
3-4
Creating a Simple Model
Adding Blocks to
To construct a mo to the model wind four blocks:
Sine Wave —Tog
Integrator —T
Scope —Tovis
Mux —Tomulti
scope
To add block
1 Select the
The Simulink Library Browser displays the Sources library.
del, you first copy blocks from the Simulink Library Browser
ow. To create the simple model in this chapter, you need
o process the input signal
ualize the signals in the model
s to your model:
Sources library in the Simulink Library Browser.
Your Model
enerate an input signal for the model
plex the input signal and processed signal into a single
3-5
3 Creating a Simulink
®
Model
3-6
2 Select the Sine Wave block in the Simulink Library Browser, then drag it
to the model window.
A copy of the Sine Wave block appears in the model window.
3 Select the Sinks library in the Simulink Library Browser.
Creating a Simple Model
4 Select th
e Scope block from the Sinks library, then drag it to the model
window.
A Scope block appears in the model window.
5 Select the Continuous library in the Simulink Library Browser.
6 Select
the mod
the Integrator block from the Continuous library, then drag it to
el window.
An Integrator block appears in the model window.
7 Select the Signal Routing library in the Simulink Library Browser.
ct the Mux block from the Sinks library, then drag it to the model
8 Sele
ow.
wind
A Mux block appears in the model window.
3-7
3 Creating a Simulink
®
Model
Moving Blocks in
Before you conne logically to mak
To move a block i
Drag the block
Select the blo
Arrange the b
ct the blocks in your model, you should arrange them
e the signal connections as straightforward as possible.
n the model window, you can either:
.
ck, then press the arrow keys on the keyboard.
locks in the model to look like the following figure.
the Model Window
3-8
Creating a Simple Model
Connecting Bloc
After you add blo the signal conne
Notice that eac brackets repr
The > symbol po
The
Input port Output port
The following sections describe how to connect blocks by drawing lines from output ports to input ports:
“Drawing Lines Between Blocks” on page 3-9
“Drawing a Branch Line” on page 3-11
> symbol p
ctions within the model.
h block has angle brackets on one or both sides. These angle
esent input and output ports:
ks in the Model Window
cks to the model window, you must connect them to represent
inting into a block is an input port.
ointing out of a block is an output port.
Drawing Lines Between Blocks
You connect the blocks in your model by drawing lines betwee n output ports and input ports.
To draw a line between two blocks:
1 Position the mouse pointer over the output port on the right side of the
Sine Wave block.
Notethatthepointerchangestoacrosshairs(+)shapewhileovertheport.
3-9
3 Creating a Simulink
®
Model
2 Drag a line from the output port to the top input port of the Mux block.
Note that the that the poin input port o
3 Release the mouse button over the output port.
line is dashed while you hold the mouse button down, and
ter changes to a double-lined cross hairs as it approaches the
ftheMuxblock.
The software connects the blocks with an arrow that indicates the direction of signal flow.
3-10
4 Drag
a line from the output port of the Integrator block to the bottom input
tontheMuxblock.
por
The software connects the blocks.
Creating a Simple Model
5 Select the Mux block, then Ctrl+click the Scope block.
The softw are automatically draws the connection line between the blocks.
Note The Ctrl+click shortcut is especially useful w h en you are conn ecti n g widely separated blocks, or when working with complex models.
The model should now look similar to the following figure.
Drawing a Branch Line
The model is almost complete, but on e connection is missing. To finish th e model, you must connect the Sine Wave block to the Integrator block.
This final connection is somewhat different from the other three, which all connect output ports to input ports. Because the output port of the Sine Wave block already has a connection, you must connect this existing line to the input port of the Integrator block. The new line, called a branch line, carries the same signal that passes from the Sine Wave block to the Mux block.
Toweldaconnectiontoanexistingline:
1 Position the mouse pointer on the line between the Sine W ave and the
Mux block.
3-11
3 Creating a Simulink
®
Model
2 Press and hold the Ctrl key, then drag a line to the Integrator block’s
input port.
3-12
Thesoftwaredrawsalinebetweenthestartingpointandtheinputportof the Integrator block.
The m odel is now complete. It should look similar to the following figure.
Saving the Model
After you comple
te the model, you should save it for future use.
Creating a Simple Model
To save the mode
1 Select File > S
2 Specify the location in wh ich you want to save the model.
3 Enter simple_model in the File name field.
4 Click Save.
The softw are saves the model with the file name
l:
ave in the model window.
simple_model.mdl.
3-13
3 Creating a Simulink
®
Model
Simulating the Model
In this section...
“Overview” on page 3-14
“Setting Simulation Options” on page 3-14
“Running the Simulation and Observing Results” on page 3-16
Overview
After you complete the model, you can simulate it and visualize the results. This section describes how to simulate the sample model you created in the previous section, “Creating a Simple Model” on page 3-3.
Setting Simulation Options
Before simulating a model, you can set simulation options such as the start andstoptime,andthetypeofsolverthat Simulink software uses to solve the model at each time step. You specify these options using the Configuration Parameters dialog box.
3-14
To specify simulation options for the sample model:
1 Select Simulation > Configuration Parameters in the model window.
The software displays the Configuration Param eters dialog box.
Simulating the Model
0
2 Enter 2
3 Click OK.
in the Stop time field.
Thesoftwareappliesyourchangestotheparametersandclosesthe Configuration Parameters dialog box.
Note For more information o n Simulink configuration parameters, see “Configuration Parameters Dialog Box” in the Simulink online documentation.
3-15
3 Creating a Simulink
®
Model
Running the Simu
Now you are ready simulation resu
To run the simul
1 Select Simula
Thesoftwarerunsthemodel,stopping when it reaches the stop time specified in the Configuration Parameters dialog box.
Tip On computers running the Microsoft®Windows®operating system, you
can click the Start simulation button
in the model w indow toolbar to start and stop a simulation.
2 Double-click the Scope block in the model window.
The Scope window displays the simulation results.
lts.
ation:
tion > Start in the model window.
lation and Observing Results
to simulate your example model and observe the
and Stop simulation button
3-16
Simulating the Model
3 Select Fi
le > Save in the model window.
Thesoftwaresavesthemodel.
4 Select File > Close in the model window.
The soft
ware closes the model.
3-17
3 Creating a Simulink
®
Model
3-18
Modeling a Dynamic Control System
“Overview” on page 4-2
“Understanding the Demo Model” on page 4-3
“Simulating the Model” on page 4-11
4
4 Modeling a Dynamic Control System
Overview
This chapter illustrates how Simulink software can model a dynamic control system, using an example that simulates the thermodynamics of a house. The system models the outdoor environment, the thermal characteristics of the house, and the house heating system.
This chapter allows you to explore common Simulink modeling tasks, including:
Grouping multiple blocks in a model into a single subsystem, simplifying
the block diagram
Customizing the appearance of blocks using the masking feature
Simulating a model and observing the results using a Scope block
Changing the input parameters of the model to investigate how the system
responds
Importing data from the MATLAB workspace into a model before
simulation
4-2
Exporting simulation data from the model back to the MATLAB workspace
Understanding the Demo Model
In this section...
“Opening the Demo Model” on page 4-3
“Anatomy of the Demo Model” on page 4-5
“Using Subsystems” on page 4-6
“Masking Subsystems” on page 4-9
Opening the Demo Model
The demo model described in this chapter is called sldemo_househeat.You can open it from the MATLAB Command Window.
To open the demo model:
1 Ensure that MATLAB is open.
Understanding the Demo Model
2 Enter sldemo_househeat in the MATLAB Command Window.
The sof
tware starts and opens the
sldemo_househeat model.
4-3
4 Modeling a Dynamic Control System
4-4
Understanding the Demo Model
Anatomy of the Demo Model
The demo system models the outdoor environment, the thermal characteristics ofthehouse,andthehouseheatingsystem.Itallowsyoutosimulatehowthe thermostat setting and outdoor environment affect the indoor temperature and cumulative heating costs.
The demo model includes many of the same blocks you used to create the simple model in Chapter 3, “Creating a Simulink Model”. These include:
A Scope block (labeled
PlotResults) on the far right displays the
simulation results.
A Mux block at the bottom right combines the indoor and outdoor
temperature signals for the Scope.
A Sine Wave block (labeled
Daily Temp Variation) at the bottom left
provides one of three data sources for the model.
In the demo, the thermostat is set to 70 degrees Fahrenheit. The system models fluctuations in outdoor temperature by applying a sine wave with amplitude of 15 degrees to a base temperature of 50 degrees.
The three data inputs (sources) are provided by two Constant blocks (labeled
Set Point and Avg Outdoor Temp), and the Sine Wave block (labeled Daily Temp Variation
). The Scope block labeled PlotResults is the one output
(sink).
4-5
4 Modeling a Dynamic Control System
Using Subsystem
The sldemo_hous appearance of th the appearance encapsulated b
The demo model
Thermostat
Heater
House
Fahrenheit
Celsius to
eheat
e block diagram, create reusable compon ents, a nd customize
of blocks. A subsystem is a hierarchical grouping of blocks
y a single Subsystem block.
uses the following subsystems:
to Celsius
Fahrenheit
s
demo model uses subsystems to simplify the
4-6
Understanding the Demo Model
Subsystems can be complex and contain many blocks that might otherwise clutter a diagram. For e xample, double-click the
House subsystem to open it.
Contents of House subsystem
You can see that the subsystem receives heat flow and external temperature as inputs, which it uses to compute the current room temperature. You could leave each of these blocks in the main model window, but combining them as a subsystem helps simplify the block diagram.
4-7
4 Modeling a Dynamic Control System
Subsystems can also be simple and contain only a few blocks. For example, double-click the
Contents of Thermostat subsystem
This subsys te m models the operation of a thermostat, determining when the heating system is on or off. It contains only one Relay block, but logically represents the thermostat in t h e block diagram.
Thermostat subsystem to open it.
4-8
Subsystems are also reusable, enabling you to implement an algorithm once and use it multiple tim es. F or example, the model contains two instances of identical subsystems named
Fahrenheit to Celsius. These subsystems
convert the inside and outside temperatures from degrees Fahrenheit to degrees Celsius.
Creating a Subsystem
Creating a subsystem allows you to group multiple related blocks into one subsystem block.
To create a subsystem:
1 Select the Thermostat block in the demo model.
2 Shift-click the Heater block in the demo model to select it.
3 Select Edit > Create Subsystem in the model window.
Understanding the Demo Model
The software creates a Subsystem block containing the Thermostat and Heater blocks.
4 Select Edit > Undo Create Subsystem to return the model to its original
configuration.
For more information about working with subsystems, see “Creating Subsystems” in the Simulink User’s Guide.
Masking Subsystems
You can customize the appearance of a subsystem by using a process known as masking. Masking a subsystem allows you to specify a unique icon and dialog box for the Subsystem block. For example, the subsystems display custom icons that depict physical objects, while the conversion subsystems display custom dialog bo xe s when you double-click them.
House and Thermostat
w the underlying blocks in the conversion subsystem, right-click the
To vie
ystem block, then select Look Under Mask.
subs
4-9
4 Modeling a Dynamic Control System
Contents of Fahrenheit to Celsius subsystem
Creating a Subsystem Mask
To mask a subsystem:
1 Select the Heater block in the demo model.
4-10
2 Select Edit > Mask Subsystem in the model window.
The Mask Editor dia log box a ppears.
3 Select disp (show text in center of block) in the Command
drop-down menu.
4 Enter disp('HEATER') in the Drawing commands field.
5 Click OK.
The software masks the subsystem block with the text you entered.
For more information about masking subsystems, see “Working with Block Masks” in the Simulink User’s Guide.
Simulating the Model
In this section...
“Running the Simulation” on page 4-11
“Modifying Simulation Parameters” on page 4-13
“Importing Data from the MATLAB Workspace” on page 4-20
“Exporting Simulation Data to the MATLAB Workspace” on page 4-25
Running the Simulation
Simulating the model allows you to observe how the thermostat setting and outdoor environment affect the indoor temperature and the cumulative heating cost.
To run the simulation:
1 In the demo model window, double-click the Scope block named
PlotResults.
Simulating the Model
ThesoftwareopensaScopewindowthat contains two axes with the labels “HeatCost” and “Temperatures.”
2 Selec
t Simulation > Start in the model w indow.
The software simulates the model. As the simulation runs, the cumulative heating cost appears on the “HeatCost” graph at the top of the Scope window. The indoor and outdoor temperatures appear on the “Temperatures” graph as yellow (top) and magenta (bottom) signals, respectively.
4-11
4 Modeling a Dynamic Control System
4-12
Simulating the Model
Modifying Simulation Parameters
One of the most powerful benefits of modeling a system with S imulink is the ability to interactively define the system inputs and observe changes in the behavior of your model. This allows you to quickly evaluate your model and validate the simulation results. This section describes:
“Changing the Thermostat Setting” on page 4-13
“Changing the Average Outdoor Temperature” on page 4-16
“Changing the Daily Temperature Variation” on page 4-18
Changing the Thermostat Setting
Change the thermostat setting to 68 degrees Fahrenheit and observe how the model responds.
To change the thermostat setting:
1 Double-click the Set Point block in the model window.
4-13
4 Modeling a Dynamic Control System
The Source Block Parameters dialog box appears.
4-14
2 Enter 68 in the Constant value field.
3 Click OK.
The software applies your changes.
4 Select Simulation > Start to rerun the simulation.
The software simulates the model.
Simulating the Model
Notice that a lower thermostat setting reduces the cumulative heating cost.
4-15
4 Modeling a Dynamic Control System
Changing the Average Outdoor Temperature
Change the average outdoor temperature to 45 degrees Fahrenheit and observe how the model responds.
To change the average outdoor temperature:
1 Double-click the Avg Outdoor Temp block.
The Source Block Parameters dialog box appears.
4-16
2 Enter 45 in the Constant value field.
3 Click OK.
Thesoftwareappliesyourchangesandclosesthedialogbox.
4 Select Simulation > Start to rerun the simulation.
Simulating the Model
The software simulates the model.
Notice that a colder outdoor temperature increases the cumulative heating cost.
4-17
4 Modeling a Dynamic Control System
Changing the Daily Temperature Variation
Decreasethetemperaturevariationtoseehowthemodelresponds.
1 Double-click the Daily Temp Variation block.
The Source Block Parameters dialog box appears.
4-18
2 Enter 5 in the Amplitude field.
Simulating the Model
3 Click OK.
Thesoftwareappliesyourchangesandclosesthedialogbox.
4 Select Simulation > Start to rerun the simulation.
The software simulates the model.
IntheScopewindow,noticethatamorestable outdoor temperature alters the frequency with which the heater operates.
4-19
4 Modeling a Dynamic Control System
Importing Data from the MATLAB Workspace
Simulink also allows you to import data from the MATLAB workspace to the model’s input ports. This allows you to import actual physical data into your model. (For information about other data import capabilities, see “Importing Data from a Workspace” in the Simulink User’s Guide.)
Note In this example, you will create a vector of temperature data in MATLAB, and use that data as an input to the Simulink m od el.
To import data from the MATLAB workspace:
1 IntheMATLABCommandWindow,createtimeandtemperaturedataby
entering the following commands:
x = (0:0.01:4*pi)'; y = 32 + (5*sin(x)); z = linspace(0,48,1257)';
4-20
2 In the Simulink model window, select the Avg Outdoor Temp block, then
press the Delete key to delete it.
3 Delete the following items from the model in the same way:
Daily Temp Variation block
Two input signal lines to the
Sum block
Sum block
The model should now look similar to the following figure. Notice that the output signal from the Sum block changes to a red, dotted line, indicating that it is not connected to a block.
Simulating the Model
4 If the Simulink Library Browser is not ope n, select View > Library
Browser in the model w indow to open it.
5 Selec
6 Select the In1 block in the Simulink Library Browser, then drag it to the
ttheSources library in the Simulink Library Browser.
model window.
An
In1 block appears in the model window.
nect the dotted line (originally connected to the
7 Con
ck.
blo
Sum block) to the In1
4-21
4 Modeling a Dynamic Control System
4-22
8 Select Simulation > Configuration Parameters in the model window.
The Co
9 Select Data Import/Export in the menu on the left sid e of the dialog box.
nfiguration Parameters dialog box appears.
The Data Import/Export pane appears.
Simulating the Model
10 Select the Input check box in the Load from workspace section.
11 Enter [z,y] in the Input field.
12 Click OK.
Thesoftwareappliesyourchangesandclosesthedialogbox.
13 Select Simulation > Start to rerun the simulation.
The software simulates the model.
4-23
4 Modeling a Dynamic Control System
In the Scope window, notice that the model ran using the imported data, showing colder temperatures and higher heat use.
4-24
Simulating the Model
Exporting Simul
Once you have com results to MATLA Data to the MATL export capabil
To export the
1 Select the Si
2 Select the Out1 block in the Simulink Library Browser, then drag it to
ities.)
eatCost
H
nks library in the Simulink Library Browser.
ation Data to the MATLAB Workspace
pleted a model, you may want to export your simulation
Bforfurtherdataanalysisorvisualization. (See“Exporting
AB Base Workspace” fo r information about additional data
data from the model to the MATLAB workspace:
the top right of the model window.
An
Out1 block appears in the model window.
3 Draw a bran
more infor
mation, see “Drawing a Branch Line” on page 3-11.
ch line from the
HeatCost signal line to the Out1 block. For
4-25
4 Modeling a Dynamic Control System
4 Select Simulation > Configuration Parameters in the model window.
The Configuration Parameters dialog box appears.
5 Select Data Import/Export in the men u on the left side of the dialog box.
The Data Import/Export pane appears.
4-26
6 Select the Time checkboxintheSavetoworkspacesection.
ct the Output check box in the Save to workspace section.
7 Sele
8 Click OK.
Thesoftwareappliesyourchangesandclosesthedialogbox.
9 Select Simulation > Start to rerun the simulation.
Simulating the Model
The software simulates the model and saves the time and to the M ATLA B workspace.
Notice that the
tout and yout va ri ables now appear in the MATLAB
workspace.
HeatCost data
4-27
4 Modeling a Dynamic Control System
4-28
Index
IndexA
adding blocks to a model 3-5
B
basics
Simulink 2-1
block libraries
descriptions 2-7
blocks
connecting 3-9 copying 3-5 masking 4-9 moving 3-8 ports 3-9 subsystems 4-6
browser
library 2-6
C
closing
model 3-17 Configuration Parameters dialog box 3-14 connecting
blocks 3-9
lines to input ports 3-9 control system
model overview 4-5
modeling 4-2 copying blocks to a model 3-5 creating
new model 2-4 3-3
subsystem 4-8
subsystem mask 4-10
D
data
exporting to MATLAB 4-25
importing from MATLAB 4-20
demo model
opening 4-3 overview 4-5 running 4-11
demos
accessing 2-11
E
example model 3-2 exporting
data from Simulink to MATLAB 4-25
H
help
Simulink 2-10
house model
overview 4-5
I
importing
MATLAB data to Simulink 4-20
input data
importing from MATLAB 4-20
input port 3-9
L
library
descriptions 2-7 searching 2-7 selecting 2-7 viewing 2-7
Library Browser
opening 2-2 overview 2-6 using 3-5
lines
Index-1
Index
branching a signal 3-11
carrying the same signal 3-9
connecting to input ports 3-9
M
masking
creating a mask 4-10
overview 4-9 MATLAB
exporting data from Simulink 4-25
importing data to Simulink 4-20
Simulink interaction 1-4 model window
moving blocks 3-8
overview 2-9 Model-Based Design
overview 1-5
process 1-6 modeling
control system 4-2
process 1-6 models
closing 3-17
control system example 4-5
creating new 2-4
creating simple 3-3
empty 3-3
opening 2-4
opening existing 2-5
saving 3-13
simple example 3-2
simulating 3-14 modifying
simulation parameters 4-13 moving
blocks in the model window 3-8
O
online help
accessing 2-10 Simulink 2-10
opening
demo model 4-3 existing model 2-5 model 2-4 Simulink 2-2
output data
exporting to MATLAB 4-25 output port 3-9 overview
demo model 4-5
Simulink 1-2
P
parameters
modifying 4-13 product overview 1-2 products
related 1-9
R
related products 1-9 running
demo model 4-11
simulation 3-14
Simulink 2-2
S
sample
model 3-2 saving
models 3-13 simulating models
exercise 3-14
Index-2
Index
simulation
modifying parameters 4-13 running 4-11 specifying options 3-14 starting 3-16 stopping 3-16
Simulink
basics 2-1 demos 2-11 getting help 2-10 Library Browser 2-6 MATLAB interaction 1-4 model window 2-9 online help 2-10 opening 2-2 overview 1-2 related products 1-9 starting 2-2 user interface 2-6 web resources 2-14
starting
MATLAB 2-2 simulation 3-16
Simulink 2-2 stopping
simulation 3-16 subsystems
creating 4-8
masking 4-9
overview 4-6
T
thermo model
overview 4-5
U
user interface
Simulink 2-6
W
web resources
Simulink 2-14
Index-3
Loading...