Sunteți pe pagina 1din 24

Simulink Basics

SIMULINK Basics

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

Simulink Basics Content Whats SIMULINK? SIMULINKLibraries Sources, Sinks und Math Simulation parameters Algorithms for numerical integration SIMULINKLibraries Signals&Systems, Subsystems

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics Whats Simulink? Graphical modelling of dynamic systems by signal ow graphs Addition to MATLAB (Toolbox) SimulinkAdditions: Blocksets (SimPower-Systems, SimMechanics)
Sine Wave

Clock Product1 80 Constant

1 Gain

eu Math Function Product2

Product3

1 Gain1

Mux

gedaempfte Sinusschwingung

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics Starting SIMULINK Blocks are basic elements

Blocks characterized by input, output, name, icon

Double click opens Block P arameters dialog

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics SIMULINK block libraries Sources and Sinks Block library Sources:
Generation of signals Import data from MATLAB workspace Import of data from les
untitled.mat

1 Constant

Step

Signal Sine Wave Generator

From File

1 In1
simin From Workspace

Ramp

Repeating Pulse Generator Sequence

Block library Sinks:


Graphical display of signals Write data to MATLAB workspace Write data to les
untitled.mat To File Scope XY Graph simout To Workspace 1 Out1

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics Example for Sources and Sinks

Signal 1

Signal 2

1 s Integrator

Scope

Signal Builder

Signal Builder : bsp sigbuild.mdl Signal Builder Dialog box for group of three signals

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics SIMULINK block library Math Opertions Block library Math: Arithmetic, logical and relational operators Mathematical and trigonometric functions
etc.
1 eu Product Sum sin Dot Product Trigonometric Function K*u Matrix Gain Relational Operator Math Function Gain 1 Slider Gain AND Logical Operator <=

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics Examples for Math Operations

Simulink model bspmath.mdl of equation 1 t f (t) = 80 e 80 sin (0.25t + )


3

Sine Wave

Clock Product1 80 Constant

1 Gain

eu Math Function Product2

Product3

1 Gain1

Mux

gedaempfte Sinusschwingung

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics Simulation: parameters and solvers Conguration Parameters dialog box

Solver pane: Specify start and stop time of simulation Solvers for numerical integration Output options
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics Numerical integration of ODE Inhomogeneous linear ordinary dierential equation:
u(t) DGL y(t)

y (t) = f (u(t), y (t))


tn+1

Integration: Numerous methods:


yn+1 = yn +
tn

f (u(t), y (t))dt

Euler method Heuns method Other RungeKuttamethods AdamsBashforth methods

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

SIMULINK Basics Numerical integration of ODE Euler method (explicit)


y y1 dy y(t1) y0 y0 h t0 t1 t y(t) hy0

y1 = y0 + h y 0
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

10

SIMULINK Basics Numerical integration of ODE RungeKutta method


y y1 y0 y0 h t0 t1 t2 t y1 P3(t2) = y2 P3(t)
P

2h P )] y2 = y0 + [y 0 + 4y 1 + f (u2, y2 6
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

11

SIMULINK Basics Numerical integration of ODE AdamsBashforth method


y yn yn-1 yn-2 h tn-2 tn-1 tn tn+1 t P2(t) P2(tn+1)

h yn+1 = yn + [23y n 16y n1 + 5y n2] 12


Matlab/Simulink Dipl.-Ing. U. Wohlfarth

12

SIMULINK Basics Solver: integration algorithms in MATLAB Variablestep solver: use variable step size allow error control & detection of zero crossings for continuous-time, non-sti systems: ode45 (rst try), ode23, ode113 for continuous-time, sti systems: ode15s, ode23s, ode23t,ode23tb for discrete-time systems: discrete (Variablestep)
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

13

SIMULINK Basics Solver: integration algorithms in MATLAB Fixedstep solver: use xed step size no error control no detection of zero crossings for continuous-time systems: ode5, ode4, ode3, ode2, ode1 for discrete-time systems: discrete (Fixedstep)
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

17

SIMULINK Basics Simulation: parameters and solver methods Conguration Parameters dialog box

Data Import/Export pane: Initialization Load data from Workspace Write data to Workspace
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

18

SIMULINK Basics Simulation: parameters and solver methods Conguration Parameters dialog box

Diagnostics pane: Control of warning and error messages Set simulation options
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

19

SIMULINK Basics Simulation Start and stop of simulation from SIMULINK window from MATLAB Command Window
set_param(sys, SimulationCommand, cmd) get_param(sys, SimulationStatus) [t,x,y] = sim(model, timespan, options, ut) options = simset(property, value, ...) newopts = simset(oldopts, property, value, ...) struct = simget(model)

Example:
[t,x,y] = sim(m1,[],simset(simget(m1),Solver,ode23,MaxStep,0.01))
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

20

SIMULINK Basics Error handling

Simulation Diagnostics Viewer

upper part: error information lower part: complete text of error message

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

23

SIMULINK Basics SIMULINK block library Signal Routing Block library Signal Routing:
Date saving
A Data Store Memory A Data Store Read A Data Store Write

Connect and selection of signals


etc.
[A] [1] Mux Demux Demux Bus Selector Selector Hit Crossing IC From [A] Goto

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

24

SIMULINK Basics Subsystems Subsystems: Structural order of complex models Combining blocks of similar function hierarchic structuring Creation by 1. menue item Edit/Create Subsystem 2. block library Subsystems

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

25

SIMULINK Basics SIMULINK block library Subsystems Block library Subsystems:

In1

Out1

In1

Out1

In1

Out1

Action In1 Out1

Subsystem

Atomic Subsystem
function() In1 Out1 In1

Triggered Subsystem

In1

while { ... } Out1


IC Out1

If Action Subsystem
if(u1 > 0)

While Iterator Subsystem

u1 else

FunctionCall Subsystem

If Enabled Subsystem

etc.
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

26

SIMULINK Basics Conditionally executed subsystems / Masking Conditionally Executed Subsystems Execution controlled by control signal comprise Enable or Trigger Masking of subsystems building a new block from a subsystem easier parametrization of complex subsystems Setting up of user dened libraries
Matlab/Simulink Dipl.-Ing. U. Wohlfarth

27

SIMULINK Basics Masking of subsystems Example bspmask.mdl


x y

m Steigung

b yAchsenabschnitt

y=mx+b

Matlab/Simulink Dipl.-Ing. U. Wohlfarth

28

S-ar putea să vă placă și