Nothing Special   »   [go: up one dir, main page]

Simulink

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

MEGSA presents:

Matlab in Mechanical Engineering, Simulink


Alireza Setayeshgar Setayesh@ualberta.ca

Simulink Overview
Simulink is the environment for the multi domain simulation of modelbased design for dynamic and embedded systems Helps you design, build and simulate models of Aerospace and Defense Control Automotive Communications Electronics and Signal Processing Medical Instrumentation

Introduction

Getting started with Simulink


Model-based design Introduction of Library browser Library Browser: Blocks of continuous Discrete in time Hybrid

Use keyword search to find required model block See the documentation on how to use it
Introduction 3

Example 1, Build a simple model


Build a sine wave and amplify it by a factor Drag a sine wave from source library Drag a gain block from math operations library Move the block and see the aligning guidelines To visualize, use scope from sinks library

To connect, you can simply drag a line between inputs and outputs
Or alternatively, select first block, hold CTRL, click on the second block

Save the model as simple_model.mdl

Brief Introduction of Toolbar

Example 1, Continue
Lets run it with default parameters value Now change the parameters Scope Parameters Gain parameter Change the sine wave form to a vector Making copies

Introduction

Problem 1: Solve a simple model


Build a Simulink model that solves the differential equation

x 3sin 2t

With Initial condition

x ( 0 ) 1.

Analytical Solution

x(t ) 1 3 cos2t 2 2

Modeling

Problem 1 Solution, Follow below


Input is the forcing function

3 sin 2t

Output is the solution of the differential equation

x(t )

x ( 0 ) 1

3sin(2t) (input)

1 s

x(t) (output)

integrator

Modeling

Problem 1 Solution, Continue


Apply in Simulink: Find sine wave, integrator and scope from Simulink library Browser Connect blocks with signals Set the parameters of sine wave and Integrator as required.
Sine wave: Amplitude: 3, Freq: 2 Integrator: initial condition: -1

Double click on scope to view simulation results Run the simulation by clicking on the RUN Button

x(t ) 1 3 cos2t 2 2

Modeling

Handling of Blocks and lines


Actions Copying a block from a library Duplicating blocks in a model Keystokes or Mouse Actions Drag the block to the model window with the left button on the mouse OR use select the COPY and PASTE from EDIT menu. Hold down the CTRL key and select the block with the left mouse drag the block to a new location.

Display block's parameters Double click on the block Flip a block Rotate a block (clockwise 90 deg @ each keystroke) Changing blocks' names Disconnecting a block Drawing a diagonal line CTRL-I CTRL-R Click on block's label and position the cursor to desired place. hold down the SHIFT key and drag the block to a new location hold down the SHIFT key while dragging the mouse with the left button

Dividing a line

move the cursor to the line to where you want to create the vertex and use the left button on the mouse to drag the line while holding down the SHIFT key

Some hints, try on problem 1

Saving Data
You can set the parameters to variables and set them in MATLAB workspace From Workspace, To workspace From File and To File Logging data, right click on signal and check the log signal data

Try these on problem 1

Saving Data

10

Using Subsystems
Used to hide details and simplify the appearance In view, Model Browser option To make subsystem select some graphs and right click create subsystem Masking also helps to create parameters to change the subsystems Right click on subsystem Mask subsystem Appearance, Ports, Parameters, can be set

Try these on problem 1

Subsystems

11

Incorporating Matlab algorithm to simulink


User-Defined function Embedded Matlab functions Writing your own code in Matlab Editor Embedded Matlab function library

Try these on problem 1

Coding in Simulink

12

Using Solvers
Using Play, pause, setting the simulation time Simulink Engine takes care of numerical caluclations Default solver is accurate and fast relatively Change the solver in configuration parameters Variable-step Vs. fix-step

Try these on problem 1

Using solvers

13

Problem 2:
2nd-order mass-spring-damper system

m cx kx f (t ) x
zero ICs input f(t) is a step with magnitude 3 parameters: m = 1, c = 2, k = 4

Modeling

14

Problem 2: Solution: Follow the instructions


First, solve for the term with highest-order derivative Make the left-hand side of this equation the output of a summing block

m f (t ) cx kx x
m x

Drag a sum block, and set its signs to +-- for f (t ) , cx and kx respectively.

Modeling

15

Problem 2 Solution, Continue


Add a gain (multiplier) block to eliminate the coefficient and produce the highest-derivative alone and set it to 1/4.

m x

1 m

summing block Add integrators to obtain the desired output variable

m x
summing block
Add a scope

1 m

1 s

1 s

Modeling

16

Problem 2 Solution, Continue


Drag new Gain Blocks, Flip them by CTRL +R, set their values for k and C and connect them like figure below:

f(t) input

+ -

m 1 x m

1 s
c

x x
k

1 s

x(t) output

c x
kx

Put the Step Function and Scope for Input and Output.

Modeling

17

Need more Problems?


Check out these cool Problems: Hydraulic Example: http://www.me.cmu.edu/ctms/modeling/hydraulic/simulinkmodeling/ mainframes.htm Thermal Example: http://www.me.cmu.edu/ctms/modeling/thermal/simulinkmodeling/ mainframes.htm A Foucault Pendulum Example: http://www.mathworks.com/products/simulink/demos.html?file=/prod ucts/demos/shipping/simulink/sldemo_foucault.html More? http://www.mathworks.com/products/simulink/demos.html

Modeling Problems

18

Other Libraries
Simscape modeling and simulating multidomain physical systems, such as those with mechanical, hydraulic, and electrical components Serve as platform for SimHydraulics, SimDriveline, SimMechanics, SimElectronics & SimPowerSystems. Simmechanics Based on Simscape, platform product for the Simulink Physical Modeling family Simulation of rigid body machines and their motions Some good examples Http://www.mathworks.com/help/toolbox/physmod/mech/exampl eindex.html

Other libraries

19

References
http://edu.levitas.net/Tutorials/Matlab/Simulink/ http://www.me.cmu.edu/ctms/modeling/tutorial/simulinkmodeling/ma inframes.htm http://www.mathworks.com/products/simulink/demos.html?show=de mo

References

20

You might also like