Tutorials Matlab Simulink

Embed Size (px)

Citation preview

  • 8/4/2019 Tutorials Matlab Simulink

    1/7

    | Matlab | | Contro l Sys tems Appl ica t ions | | Symbolic Calculation | | Side Notes | | About this site |

    Introduction

    Simulink (Simulation and Link ) is an extension of MATLAB by Mathworks Inc. It works with MATLAB to o ffer modeling, sim ulation,and analysis o f dynamical systems under a graphical user interface (GUI) environm ent. The construction o f a model is simplifiedwith click-and-drag mouse operations. Simulink includes a comprehensive block library of toolboxes for both linear and nonlinearanalyses. Models are hierarchical, which allow using both top-down and bottom-up approaches. As Simulink is an integral part ofMATLAB, it is eas y to s witch back and forth during the analysis process and thus, the user may take full advantage of features o fferedin both environments. This tutorial presents the basic features o f Simulink and is focus ed on co ntrol systems as it has been writtenfor students in my control systems course.

    This tutorial has been written for Simulink v.5 and v.6.

    Getting Started

    To s tart a Simulink ses sio n, you'd need to bring up Matlab program first.

    From Matlab comm and window, enter:

    >> simulink

    Alternately, you may click on the Simulink icon lo cated on the too lbar as sho wn:

    Simulink's library browser window like o ne shown belo w will pop up presenting the block set for mo del construction.

    >

    M

    E

    N

    U

    >

    PDFmyURL.com

    http://edu.levitas.net/Tutorials/Matlab/filemgmt.htmlhttp://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://edu.levitas.net/Tutorials/Matlab/about.htmlhttp://edu.levitas.net/Tutorials/Matlab/sidenotes/index.htmhttp://edu.levitas.net/Tutorials/Matlab/symbolic.htmlhttp://edu.levitas.net/Tutorials/Matlab/controlsys.htmlhttp://edu.levitas.net/Tutorials/Matlab/index.htmlhttp://edu.levitas.net/Tutorials/Matlab/about.htmlhttp://edu.levitas.net/Tutorials/FEM/ProMhttp://edu.levitas.net/Tutorials/Matlab/Simulink/index.htmlhttp://edu.levitas.net/Tutorials/Matlab/bode.htmlhttp://edu.levitas.net/Tutorials/Matlab/gui.htmlhttp://edu.levitas.net/Tutorials/Matlab/controlsys.html#ss2tfhttp://edu.levitas.net/Tutorials/Matlab/controlsys.htmlhttp://edu.levitas.net/Tutorials/Matlab/filemgmt.htmlhttp://edu.levitas.net/Tutorials/Matlab/index.html#formathttp://edu.levitas.net/Tutorials/Matlab/index.html
  • 8/4/2019 Tutorials Matlab Simulink

    2/7

    To s ee the content of the blockset, click on the "+" sign at the beginning of each toolbo x.

    To s tart a mo del click on the NEW FILE ICON as s hown in the screenshot abo ve. Alternately, you may us e keystrokes CTRL+N.

    A new window will appear on the screen. You will be constructing your model in this window. Also in this window the constructedmo del is sim ulated. A screenshot o f a typical working (model) window is s hown belo w:

    PDFmyURL.com

    http://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://pdfmyurl.com/?otsrc=watermark&otclc=0.01
  • 8/4/2019 Tutorials Matlab Simulink

    3/7

    To become familiarized with the structure and the environment of Simulink, you are encouraged to explore the toolboxes and scantheir contents. You may no t know what they are all about at first, but perhaps you co uld catch on the organisatio n of these to olbo xesaccording to their categories. For instance, you may see that the Control System toolbox consists of the Linear Time Invariant (LTI)system l ibrary and the MATLAB functions can be found under Function and Tables o f the Simulink main too lbox. A goo d way to learnSimulink (or any co mputer program in general) is to practice and explore. Making mistakes is part of the learning curve. So, fear notyou should be!

    A simple model is used here to introduce some basic features of Simulink. Please follow the steps below to construct a simple

    model.

    STEP 1: CREATING BLOCKS.

    From BLOCK SET CATEGORIES section of the SIMULINK LIBRARY BROWSER window, click on the "+" sign next to the Simulinkgroup to expand the tree and select (click on) Sources.

    PDFmyURL.com

    http://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://pdfmyurl.com/?otsrc=watermark&otclc=0.01
  • 8/4/2019 Tutorials Matlab Simulink

    4/7

    A set of blocks will appear in the BLOCKSET group. Click on the Sine Wave block and drag it to the workspace window (also knownas mo del window).

    Now you have established a source of your model.

    NOTE: It is advisable that you save your model at some point early on so that if your PC crashes you wouldn't loose too much timereconstructing your mo del. This is among the reaso ns why I prefer Linux or Unix!

    I am going to save this mo del under the filename: "sim example1". To save a model, you may click on the floppy diskette icon . orfrom FILE menu, select Save or using keystrokes CTRL+S. All Simulink model file will have an extension ". mdl". Simulinkrecognises file with .mdl extension as a simulation model (similar to how MATLAB recognises files with the extension .m as anMFile).

    PDFmyURL.com

    http://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://pdfmyurl.com/?otsrc=watermark&otclc=0.01
  • 8/4/2019 Tutorials Matlab Simulink

    5/7

    Continue to build your model by adding more components (or blocks) to your model window. We'll continue to add a Scope fromSinks library, an Integratorblock from Continuous library, and a Mux block from Signal Routing library.

    NOTE:If you wish to locate a block knowing its name, you may enter the name in the SEARCH WINDOW (at Find prompt) andSimulink will bring up the s pecified block.

    To m ove the blocks aro und, simply click on it and drag it to a des ired location.

    Once you've dragged over all necessary blocks, the workspace window should consist of the following components:

    You may remove (delete) a block by simply clicking on it once to turn on the "select mode" (with four corner boxes ) and use the DELkey or keys combination CTRL-X.

    STEP 2: MAKING CONNECTIONS

    To establish connections between the blocks, move the cursor to the output port represented by ">" sign on the block. Once placedat a port, the cursor will turn into a cross "+" enabling you to make connection between blocks.

    To make a connection: left-click while holding down the control key (on your keyboard) and drag from source port to a destinationport.

    The connected model is shown below.

    PDFmyURL.com

    http://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://pdfmyurl.com/?otsrc=watermark&otclc=0.01
  • 8/4/2019 Tutorials Matlab Simulink

    6/7

    A sine signal is generated by the Sine Wave block (a source) and is displayed by the scope. The integrated sine signal is sent toscope for display along with the original signal from the source via the Mux, whose function is to mutiplex signals in form of scalar,vector, or m atrix into a bus.

    STEP 3: RUNNING SIMULATION

    You now may run the simulation of the simple sys tem above by clicking on the play button . Alternately, you may use keystrokesCTRL+T, or choo se Start submenu (under Simulation m enu).

    Double click on the Scope block to display of the scope.

    To view/edit the parameters, sim ply double click o n the block o f interest.

    Handling of Blo cks and Lines

    The table below describes the actions and the corresponding keystrokes or mouse operations (Windows versions).

    Actions Keystokes or Mouse Actions

    Copying a block from alibrary

    Drag the block to the mo del window with the left button on the mo use OR us e selectthe COPY and PASTE from EDIT menu.

    Duplicating blocks in a model Hold do wn the CTRL key and select the block with the left mo use drag the block to anew location.

    Display block's parameters Double click on the block

    Flip a block CTRL-F

    l l i

    PDFmyURL.com

    http://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://pdfmyurl.com/?otsrc=watermark&otclc=0.01
  • 8/4/2019 Tutorials Matlab Simulink

    7/7

    l l ideg @ each keystroke)

    CTRL-R

    Changing blocks' names Click on block's label and position the cursor to desired place.

    Disconnecting a block hold down the SHIFT key and drag the block to a new location

    Drawing a diagonal line hold down the SHIFT key while dragging the mouse with the left button

    Dividing a l ine move the cursor to the l ine to where you want to create the vertex and use the leftbutton o n the mous e to drag the line while holding do wn the SHIFT key

    Annotations

    To add an annotation to your model, place the cursor at an unoccupied area in your model window and double click (left button). Asmall rectangular area will appear with a cursor prom pting for your input.

    To delete an annotation, hold down the SHIFT key while selecting the annotation, then press the DELETE or BACKSPACE key. Youmay also change font type and colour from FORMAT menu. Make sure that the block is s elected before m aking the change.

    ______________________________________________________

    T. Nguyen MMIII, MMIV, MMV. All rights reserved. Users may not download and print extracts of content from this website without written

    pe rmission from the author. Republication or re distribution of the content in this site, including b y framing or similar means, is express ly

    prohib ited without the prio r written conse nt of the author.

    PDFmyURL.com

    http://pdfmyurl.com/?otsrc=watermark&otclc=0.01http://pdfmyurl.com/?otsrc=watermark&otclc=0.01