0% found this document useful (0 votes)
65 views26 pages

Fabrication Mécanique

Simulink is a MATLAB toolbox that allows modeling and simulating dynamical systems using a graphical block diagram interface. It uses numerical integration methods to compute the evolution of state variables over time. Key blocks include sources to define input signals, sinks to visualize outputs, and transfer function blocks to define linear systems. Models are constructed by dragging blocks from libraries into the workspace and connecting them. Simulation parameters like the integration method and step size must be set appropriately. Simulink facilitates analyzing and testing control systems.

Uploaded by

Achraf Moutahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views26 pages

Fabrication Mécanique

Simulink is a MATLAB toolbox that allows modeling and simulating dynamical systems using a graphical block diagram interface. It uses numerical integration methods to compute the evolution of state variables over time. Key blocks include sources to define input signals, sinks to visualize outputs, and transfer function blocks to define linear systems. Models are constructed by dragging blocks from libraries into the workspace and connecting them. Simulation parameters like the integration method and step size must be set appropriately. Simulink facilitates analyzing and testing control systems.

Uploaded by

Achraf Moutahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Systems and Control Theory

Master Degree Course in ELECTRONICS ENGINEERING


http://www.dii.unimore.it/~lbiagiotti/SystemsControlTheory.html

Introduction to SIMULINK

Luigi Biagiotti
e-mail: luigi.biagiotti@unimore.it
http://www.dii.unimore.it/~lbiagiotti
Simulink introduction
• Simulink (Simulation and Link) is an extension of MATLAB
that offers modeling, simulation, and analysis of dynamical
systems under a graphical user interface (GUI) environment.

• Simulink is based on block diagrams of Dynamic Systems

• The construction of a model is simplified with click-and-drag


mouse operations. Simulink includes a comprehensive block
library of toolboxes for both linear and nonlinear analyses.

• As Simulink is an integral part of MATLAB, it is easy to switch


back and forth during the analysis process and thus, the user
may take full advantage of features offered in both
environments.

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 2


Starting Simulink
• From Matlab command window enter simulink, or alternately,
click on the Simulink icon located on the toolbar

Simulink's library browser

Library Block set

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 3


Simulink library
• The block library is organized into
functional groups. For instance

• Sources: Blocks for the


generation of input signals
(steps, sinusoids etc.)
• Sinks: Blocks for the graphical
visualization of signals
• Math: Blocks for the
mathematical elaboration of
signals
• Continuous: Blocks for the
definition of (continuous)
transfer functions

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 4


Simulink – Sources Library
• I The most used blocks are:
• Constant: for generating a constant
value

• Step: for generating a step function

• Ramp: for generating a ramp


function

• Sine wave: for generating a


sinusoidal function

• From workspace: the reference


signal, previously generated in the
MATLAB workspace, is passed as
[time, value], where time
and value are two column
vectors with the same length

• Clock: it outputs the current


simulation time at each simulation
step

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 5


Simulink – Sinks Library
• Set of tools for displaying the output of the
simulations

• The most used blocks are:

• Scope: it displays the input signal as a


function of time (take care to the option
limit data points to…)

• XYGraph: it produce a graphics of the


signal y (on the second input) as a
function of the signal x (on the first input).

• To Workspace: it saves the samples of


the input signal in a MATLAB variable
(N.B.: save format array).

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 6


Simulink – Transfer functions
• In order to insert a transfer function in a Simulink scheme the blocks of
the library Continuous can be used:

• Transfer Fcn: it allows to define a transfer function by specifying


the vectors containing the coefficient of numerator and
denominator.

• Zero-Pole: it defines a transfer function by specifying the vectors


containing polse and zeros of the transfer function.

• The library Discrete contains the corresponding blocks for the


definition of discrete-time transfer functions.

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 7


Simulink and the Control System Toolbox
• The Control system Toolbox
provides a Simulink block for
directly using a transfer
function defined in the
MATLAB workspace (see
command tf) or a state space
model

Double click

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 8


Simulink – Simulation parameters
• Simulink solves ordinary differential equations (e.g. defined by
means of transfer functions) by using techniques for
numerical integration

• Simulating a dynamic system means computing the evolution


of the state and output variables for a given time period
• The state and the output values are computed at given time-
instants (called time steps) which are separeted by integration
intervals (called step sizes)
Computation of x(t), y(t)
Step size
X(0)

0=t0 t1 t2 t3 t4
Time step
Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 9
Simulink – Methods for numerical integration
Several methods (the so-called solvers) for the numerical
integration of differential equations exist:
• Integration methods with fixed step size (useful for the
simulation of discrete-time systems)
• The smaller the step size is, the more accurate the
simulation results. On the other hand, the duration of the
simulation grows.
• Integration methods with variable step size
• the solver determines the optimal step size during the
simulation (for instance if the system is characterized by fast
dynamics, the step size must be reduced accordingly)

• ODE45 is the default solver

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 10


Simulation parameters
• Initial and final simulation time-instants
• Solver type (e.g. variable step, ODE45)
• Max step size (maximum size of the
interval beetwen two successive
time-steps)
Must be chosen:
• Smaller than the fastest time-constant
of the system
• Smaller than the period of the fastest
periodic signal acting on the system
(e.g. 1/10 smaller)

• Min step size (minimum size of the interval beetwen two successive
time-steps)
Can be used to reduce the simulation time (at the expense of the accuracy)

• Relative/absolute tollerance Accuracy of the simulation output (set


“auto” or values smaller enough, e.g. 1e-4)

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 11


Steps for constructing a Simulink model
• Open a new model from the Matlab menu file

or from the icon in the Simulink Library browser

Simulink workspace

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 12


Steps for constructing a Simulink model
• Import blocks in the Simulink workspace

Drag block to workspace window

• Connect blocks

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 13


Steps for constructing a Simulink model
• Action on blocks

Actions Keystrokes or Mouse Actions


Drag the block to the model window with the left 
Copying a block from a library button on the mouse OR use select the COPY and 
PASTE from EDIT menu.
Hold down the CTRL key, select the block with the 
Duplicating blocks in a model left mouse button and drag the block to a new 
location.
Display block's parameters Double click on the block

Flip a block CTRL‐I

Rotate a block (clockwise 90 deg @ each keystroke) CTRL‐R

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

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 14


Steps for constructing a Simulink model
• Save and run the simulation from the workspace window

or directly from MATLAB


>> sim(‘SimulinkModel’,EndTime)

• Display the results

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 15


Guidelines for a good simulation
• Matlab-Simulink models are usually structured in two main files:
M-file Simulink Model

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 16


Simulation of a feedback system - problem
With reference to the scheme of figure

1. Simulate the step response of the system with the continuous-


time transfer functions

In a unique figure plot the system's response


superimposed to the reference signal and the control
variable (two distinct subplots)

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 17


Simulation of a feedback system - problem
2. Simulate the step response of the feedback system with the
discrete-time transfer functions

and obtained from by discretization with sampling


time Ts = 0.1 s. Make the same plots of point 1.

3. Simulate the step response of the feedback system with the


discrete-time transfer functions R(z) and the continuous-time
plant G(s). Make the same plots of point 1.

4. Simulate the response of the system considered in the


previous point, by considering a reference signal computed
with the MATLAB function [q_t] = TrjPoly3(q0,q1,T,dt),
with q0=0, q1=1, T=2, dt = Ts.

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 18


Simulation of a differential equation
• A Simulink scheme allows the simulation of any differential
equation, even nonlinear or time-varying, if it is possible to
rewrite it an explicit form, i.e.

• The correpsonding block-scheme (to be designed in Simulink) is

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 19


Simulation of the simple pendulum
• The dynamics of the system is described by
the nonlinear differential equation

• In order to represent the equation with block-


schemes, it is convenient to rewrite it as

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 20


Simple pendulum – Simulink scheme
• From the equation

the Simulink scheme descends


w

To Workspace3
Cm

Constant

1 1
1/(M*l^2) q
s s
Manual Switch Integrator Integrator1 To Workspace
0
Gain
Constant1

Scope

Ci

To Workspace1 t
M*g*l sin Clock To Workspace2
Trigonometric
Gain1
Function

Parameters and initial conditions on and must be defined in


a separate m-file

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 21


Simple pendulum – Simulink scheme
• From the equation

the Simulink scheme descends


w

To Workspace3
Cm

Constant

1 1
1/(M*l^2) q
s s
Manual Switch Integrator Integrator1 To Workspace
0
Gain
Constant1

Scope

Ci

To Workspace1 t
M*g*l sin Clock To Workspace2
Trigonometric
Gain1
Function

In order to define the function it is possible to use other Simulink


blocks, in particular the blocks that allow the insertion of user-defined
functions
Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 22
Blocks for inserting user-defined functions

Function directly
defined in the Simulink
block

External function
defined as m-function
Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 23
Simple pendulum – alternatives schemes
w

To Workspace3
Cm

Constant
1 1
1/(M*l^2) q
s s
Manual Switch Integrator Integrator1 To Workspace
0
Gain
Constant1

Scope

Ci
Fcn1
To Workspace1 t
M*g*l*sin(u) Clock
To Workspace2

To Workspace3
Cm

Constant

1 1
1/(M*l^2) q
s s
Manual Switch Integrator Integrator1 To Workspace
0
Gain
Constant1

Scope

Ci

To Workspace1 MATLAB Fcn t


MATLAB
Clock
Function To Workspace2

function [Out] = PendFun(q) Global parameters in order to make them visible to


global M g l; the function (the same statement is present in the
Out = M*g*l*sin(q); m-file where the parameters are assigned)

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 24


Simple pendulum - problem
• Design a Simulink system for solving the equation of a simple
pendulum with friction, i.e.

• By assuming the parameters' values

simulate
• the free response from initial conditions
• the forced response to a constant input
• the complete response of the system
Plot in a unique figure (3 distinct subplots) the evolution of
in the three cases.

Luigi Biagiotti Systems and Control Theory Introduction to Simulink-- 25


Systems and Control Theory
Master Degree Course in ELECTRONICS ENGINEERING
http://www.dii.unimore.it/~lbiagiotti/SystemsControlTheory.html

Introduction to SIMULINK

Luigi Biagiotti
e-mail: luigi.biagiotti@unimore.it
http://www.dii.unimore.it/~lbiagiotti

You might also like