Introduction to Simulink Dr. Mohammed F. Alsayed

  • View

  • Download

Embed Size (px)

Text of Introduction to Simulink Dr. Mohammed F. Alsayed

Introduction to Simulink

Introduction to SimulinkDr. Mohammed F. AlsayedIntroductionIn the last few years, Simulink has become the most widely used software package in academia and industry for modeling and simulating dynamical systems.Simulink environment encourages you to pose a question, model it, and see what happens.You can move beyond idealized linear models to explore more realistic nonlinear models. Thus, describing real-world phenomena. It turns your computer into a lab for modeling and analyzing systems.It 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.What is Simulink?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.You can also customize and create your own blocks (S-Functions).Models are hierarchical, so you can build models using both top-down and bottom-up approaches.What is Simulink?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.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 visualizationWhat is Simulink?Running a Demo modelAn interesting demo program provided with Simulink models the thermodynamics of a house. To run this demo, type thermo in the MATLAB command window. This command starts up Simulink and creates a model window that contains this model.or>> demo simulinkQuick Start

Quick StartWhen you open the model, Simulink opens a Scope block containing two plots labeled Indoor vs. Outdoor Temp and Heat Cost ($), respectively.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 temperatures appear in the Indoor vs. Outdoor Temp plot and the cumulative heating cost appears in the Heat Cost ($) plot.Quick StartQuick Start

To stop the simulation, choose the Stop command from the Simulation menu (or press the Pause button on the toolbar). When youre finished running the simulation, close the model by choosing Close from the File menu.Quick StartDescription 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.Quick StartThe 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: Thermostat, House, and three Temp Convert subsystems (two convert Fahrenheit to Celsius, one converts Celsius to Fahrenheit).Quick StartThe 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.Quick Start

The Thermostat subsystem models the operation of a thermostat, determining when the heating system is turned on and off.Quick Start

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.Quick Start

Some Things to TryThe 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 while the simulation is running. 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.Quick StartAdjust the daily temperature variation by opening the Sine Wave block labeled Daily Temp Variation and changing the Amplitude parameter.

Quick StartRunning the simulation involves specifying parameters and starting the simulation with the Start command.You can encapsulate complex groups of related blocks in a single block, called a subsystem. You can create a customized icon and design a dialog box for a block by using the masking feature.Scope blocks display graphic output much as an actual oscilloscope does.What this Demo Illustrates?Other demos illustrate useful modeling concepts.Type simulink3 in the MATLAB command window.The Simulink block library window appears.

Double-click on the Demos icon.Other Useful Demos

The model integrates a sine wave and displays the result, along with the sine wave. To create the model, first type simulink in the MATLAB command window. Note: The window might differ based on the operating system you are using.Building a Simple Model

Building a Simple ModelTo create a new model, select the New Model button on the Library Browsers toolbar.Building a Simple Model

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)Building a Simple ModelTo 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 first on the Simulink node to display the Sources node, then 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 ModelNow drag the Sine Wave node from the browser and drop it in the model window.

Copy the rest of the blocks in a similar manner from their respective libraries into the model window.Building a Simple Model

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.

Building a Simple Model

Building a Simple ModelDrawing a branch line is slightly different. To weld a connection to an existing line, follow these steps:First, position the pointer on the line between the Sine Wave and the Mux block.Second, Press and hold down the Ctrl key. Press the mouse button, then drag the pointer to the Integrator blocks input port or over the Integrator block itself.Building a Simple ModelFinish making block connections. When youre done, your model should look something like this.Building a Simple Model

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 Parameters from the Simulation menu. On the dialog box that appears, notice that the Stop time is set to 10.0 (its default value).Building a Simple ModelClose 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.Building a Simple ModelCreating a ModelYou can start Simulink in two ways:Click on the Simulink icon on the MATLAB toolbar.Enter the simulink command at the MATLAB prompt.Starting SimulinkTo create a new model, click the New button on the Library Browsers toolbar (Windows only) or choose New from the library windows File menu and select Model. Creating a New ModelTo edit an existing model diagram, either:Choose the Open button on the Library Browsers toolbar (Windows only) or the Open command from the Simulink library windows File menu and then choose or enter the model filename for the model you want to edit.Enter the name of the model (without the .mdl extension) in the MATLAB command window. The model must be in the current directory or on the path.Editing an Existing ModelSummary of Mouse and Keyboard Actions

Summary of Mouse and Keyboard Actions

Summary of Mouse and Keyboard Actions

Summary of Mouse and Keyboard Actions

As your model increases in size and complexity, you can simplify it by grouping blocks into subsystems. Using subsystems has these advantages:It helps reduce the number of blocks displayed in your model window.It allows you to keep functionally related blocks together.It enables you to establish a hierarchical block diagram, where a Subsystem block is on one layer and the blocks that make up the subsystem are on another.Creating SubsystemsYou can create a subsystem in two ways:Add a Subsystem block to your model, then open that block and add the blocks it contains to the subsystem window.Add the blocks that make up the subsystem, then group those blocks into a subsystem.Creating SubsystemsHere are some model-building hints you might find useful:Memory issues: In general, the more memory, the better Simulink performs.Using hierarchy: More complex models often benefit from adding the hierarchy of subsystems to the model. Grouping blocks simplifies the top level of the model and can make it easier to read and understand the model. Tips for Building ModelsCleaning up models: Well organized and documented models are easier to read and understand.Modeling strategies: If several of your models tend to use the same blocks, you might find it easier to save these blocks in a model. Then, when you build new models, just ope