MATLAB Tutorials

35
Department of Mechanical Engineering, LSU Session VII MATLAB Tutorials Session VII Introduction to SIMULINK Rajeev Madazhy Email: [email protected] Dept of Mechanical Engineering LSU

description

MATLAB Tutorials. Session VII Introduction to SIMULINK. Rajeev Madazhy Email: [email protected] Dept of Mechanical Engineering LSU. Last Session…. Engineering Applications using MATLAB…. Solving non linear differential equations Algorithm analysis for four bar linkage problem - PowerPoint PPT Presentation

Transcript of MATLAB Tutorials

Page 1: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

MATLAB Tutorials

Session VIIIntroduction to SIMULINK

Rajeev MadazhyEmail: [email protected]

Dept of Mechanical Engineering

LSU

Page 2: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Last Session….

Engineering Applications using MATLAB….

Solving non linear differential equations

Algorithm analysis for four bar linkage problem

Other mechanical problems

Page 3: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Session VII Outline….

Introduction to Simulink

Solving simple problems using Simulink

Page 4: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Simulink…..

Simulink is a program that runs as a companion to MATLAB

Simulink provides a graphical user interface (GUI) that is used

in building block diagrams, performing simulations, as well as

analyzing results of dynamic systems.

In Simulink, models are hierarchical so that you can view a

system at a high level, then double click on blocks by using

the mouse to go down through the design levels.

Page 5: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Getting started…..

Lets get started with a simple example of simulating a sin wave.

To open Simulink open the MATLAB command window first.

Click on the icon which is present in the toolbar in the command window of MATLAB.

Alternatively you can also enter the command Simulink to open the graphics library of simulink

Page 6: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Opening Simulink….

Page 7: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Simulink block library….

Page 8: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

General list of libraries….

Source type blocks produce input signals.The Sine Wave block is a source type block

Sink type blocks provide a place for output. The scope block is a sink type block.

Linear type blocks perform a linear transformation.The Integrator is a linear type block.

Connection type blocks are involved with formingvector signals, the Mux block is an example.

Page 9: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Adding a block from the library…..

To open a block library, double click on the associated library icon in the Simulink block library window. After opening the Sources library, the Sources library window opens, as shown

Page 10: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Simulink Library Browser….

Page 11: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Adding a block from the library…..

To add the first block to the diagram, point the mouse at the Sine

Wave block in the Sources library window and press the left button.

Create a new model window by clicking on to the new icon at the

toolbar.

Without releasing the left mouse button, drag the mouse to the

new model window and release the mouse button.

Page 12: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Simulink model window….

Page 13: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Pulling the selected blocks….

Pull in the following blocks for our simulation from the following libraries.

Block From Library

Sine wave sources

integrator Linear

Mux connections

Scope sinks

Page 14: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Inputs and outputs….

In general the inputs to a block are on the left a > symbol points into the block. In addition, outputs are generally on to the right, a > symbol out of the block.

To add a connection, use the mouse to position the pointer over the output port of the block. During this time the pointer changes to cross hairs .

Page 15: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Cont…

The completed connection should look like this….

Adding a branch line….This is required when you have an output which needs to be connected to two separate blocks

Page 16: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

To complete the connections, add a line from the output of the integrator block to the input port of the mux block. When you are done it should look similar to the following.

Cont…

Labels can be added to lines to further annotate your model. To create a signal label, double click on a line segment and type the label at the insertion point.

Page 17: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Save the model as

example1.mdl

Final model….

Page 18: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Giving model parameters…..

The sine wave block

Double click on the sine wave block and examine the data fields.

Sine wave block parameters:

Amplitude = 1

Frequency (rad/sec) = 0.25*2*pi

Phase(rad) = 0

Sample time = 0

Page 19: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Block Parameters of Sine Wave….

Page 20: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Integrator Block….

Integrator block parameters:

External reset = None

Initial Conditions = 0

Limit Output = Not checked

Show saturation point = Not checked

Show state port = Not checked

Absolute tolerance = auto

Page 21: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Block parameters: Integrator

Page 22: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Simulation parameters….

Go to simulation => parameters in the model window toolbar

Enter the following

values

Page 23: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Run the simulation….

To view the results of the simulation, double click on the scope block.

Page 24: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Cont….

To better fit the display in the scope window, click on the ‘Fit View’ button . The scope window should similar to the following.

Page 25: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Example 2….

The next example would be to simulate the dynamics of second order system.

)()()(2)(22

2

2

tuKtytydt

dty

dt

dnnn

Given that:

4;5.0;1

nK

Obtain the velocity and displacement response

Page 26: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Building the model….

The same procedure is applied as being shown in the first example. Pull all the necessary blocks from the library browser.

The blocks required is as follows:

Blocks Number

Integrator 2

Sum 1

Scope 3

Step I/P 1

Gain 3

Page 27: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Final Model….

Page 28: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Gain parameters- 1st Gain block

Similarly give the gains for the second and the third one as shown in the model window.

Page 29: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Block parameters - Step

Page 30: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Simulation parameters….

Page 31: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Output from Scope1 and Scope2…

Page 32: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Output from Scope3….

Scope3 shows the displacement response for the second order system.

Page 33: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

References….

MATLAB website (http://www.mathworks.com) has a comprehensive list of examples and references to SIMULINK.

There are several books which cater to this area. One of the good references is listed below:

Mastering Simulink 4James B. Dabney & Thomas L. Harman

ISBN 0-13-017085-2

Page 34: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

This completes the MATLAB Tutorial.

Sessions 1 to 7 covered almost all areas of applications of MATLAB.

Specialized areas of MATLAB are using the toolboxes. These are a collection of m-files that are specific to the area of application.

Looking back….

Page 35: MATLAB Tutorials

Department of Mechanical Engineering, LSU Session VII

Thank You