Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Indice
1 Introduzione 2
1
TdS [MatLab; 01/02; N.O.; UniPG] - 2
1 Introduzione
Matlab `e un linguaggio di programmazione orientato ai problemi tipici dellingegneria dellinformazione. Nel
seguito vengono brevemente presentati i comandi matlab pi` u rilevanti rispetto allanalisi di sistemi ed alla sintesi
di leggi di controllo stabilizzanti, nel dominio del tempo.
Per una trattazione pi` u approfondita di tali temi, e per una trattazione di tutte le altre potenzialit`a di
matlab, si rimanda alla documentazione specifica e ad altri testi.
Nella successiva sezione vengono brevemente presentati i comandi pi` u importanti, mentre nella sezione 3
viene riportata la descrizione di tali comandi basata sul comando help di matlab stesso.
x = F xGu, x Rn , u Rm (1)
y = Hx + Du, y Rp , (2)
La costruzione di un oggetto matlab di tipo sistema pu`o essere fatta con uno o pi`
u tra i seguenti comandi.
Nel seguito, la sigla TC indica un modello o sistema a tempo continuo, la sigla TD un modello o sistema
a tempo discreto.
function F = odefile(t,y)
F = < Insert a function of t and/or y here. >;
Per semplicit`a, di seguito si riporta il file pendolo.m, che descrive il modello dinamico di un pendolo, nel
formato richiesto per la simulazione in matlab, ed il file integra.m, che contiene tutte le istruzione necessarie
alla simulazione della risposta libera del pendolo. Una versione leggermente pi` u estesa del file pendolo.m,
contenente anche una semplice legge di controllo, `e disponibile in formato elettronico sul sito web del corso.
Sullo stesso sito `e disponibile anche una versione elettronica del file integra.m.
Il file pendolo.m
function F = pendolo(t,x);
% Calcolo del vettore delle derivate per la funzione di integrazione (e.g., ode45)
F=[xp1;xp2];
Il file integra.m
TdS [MatLab; 01/02; N.O.; UniPG] - 5
% Comando per lintegrazione numerica delle equazione contenute nel file (ODEFILE) "pendolo.m"
[tempo,x] = ODE45(pendolo,tspan,x0);
Conversion:
SYS = SS(SYS) converts an arbitrary LTI model SYS to state space,
i.e., computes a state-space realization of SYS.
See also LTIMODELS, DSS, RSS, DRSS, SSDATA, LTIPROPS, TF, ZPK, FRD.
Data format:
For SISO models, NUM and DEN are row vectors listing the numerator and
denominator coefficients in
* descending powers of s or z by default
* ascending powers of q = z^-1 if the Variable property is set to
z^-1 or q (DSP convention).
For MIMO models with NY outputs and NU inputs, NUM and DEN are NY-by-NU
cell arrays of row vectors where NUM{i,j} and DEN{i,j} specify the
transfer function from input j to output i. For example,
H = TF( {-5 ; [1 -5 6]} , {[1 -1] ; [1 1 0]})
specifies the two-output, one-input transfer function
[ -5 /(s-1) ]
[ (s^2-5s+6)/(s^2+s) ]
Conversion:
SYS = TF(SYS) converts an arbitrary LTI model SYS to the transfer
function representation. The result is a TF object.
See also LTIMODELS, FILT, SET, GET, TFDATA, SUBSREF, LTIPROPS, ZPK, SS.
Data format:
For SISO models, Z and P are the vectors of zeros and poles (set
Z=[] if no zeros) and K is the scalar gain.
For example,
H = ZPK( {[];[2 3]} , {1;[0 -1]} , [-5;1] )
specifies the two-output, one-input ZPK model
[ -5 /(s-1) ]
[ (s-2)(s-3)/s(s+1) ]
Conversion:
SYS = ZPK(SYS) converts an arbitrary LTI model SYS to the ZPK
representation. The result is a ZPK object.
See also LTIMODELS, SET, GET, ZPKDATA, SUBSREF, SUBSASGN, LTIPROPS, TF, SS.
ODE45 can solve problems M(t,y)*y = F(t,y) with a mass matrix M that is
nonsingular. Use ODESET to set Mass to M, M(t), or M(t,y) if the
ODE file is coded so that F(T,Y,mass) returns a constant,
time-dependent, or time- and state-dependent mass matrix, respectively.
The default value of Mass is none. See FEM1ODE, FEM2ODE, or BATONODE.
ODE15S and ODE23T can solve problems with singular mass matrices.
By default, the ODE Suite solvers solve initial value problems of the form
dy/dt = F(t,y) where t is an independent variable and y is a vector of
dependent variables. To do this, the solvers repeatedly call F =
ODEFILE(T,Y) where argument T is a scalar, Y is a column vector, and
output F is expected to be a column vector of the same length. Note that
the ODE file must accept the arguments T and Y, although it does not have
to use them. In its simplest form, an ODE file can be coded as
function F = odefile(t,y)
F = < Insert a function of t and/or y here. >;
As described in the Users Guide, the ODE Suite solvers are capable of
using additional information coded in the ODE file. In this more general
usage, an ODE file is expected to respond to the arguments
ODEFILE(T,Y,FLAG,P1,P2,...) where T and Y are the integration variables,
FLAG is a lower case string indicating the type of information that the
ODE file should return, and P1,P2,... are any additional parameters that
the problem requires. The currently supported flags are
See also RIGIDODE, VDPODE, BRUSSODE, FEM1ODE, and BALLODE M-files for
examples of FLAG usage. The VDPODE, BRUSSODE and FEM1ODE examples
illustrate the use of additional ODE file parameters, and are also
examples of vectorized ODE files (an option described in ODESET).
Below is a template that illustrates how you might code an extended ODE
file that uses two additional input parameters. This template uses
subfunctions. Note that it is not typical to include all of the cases
shown below. For example, jacobian information is used for evaluating
Jacobians analytically, and jpattern information is used for generating
Jacobians numerically.
switch flag
case % Return dy/dt = f(t,y).
varargout{1} = f(t,y,p1,p2);
case init % Return default [tspan,y0,options].
[varargout{1:3}] = init(p1,p2);
case jacobian % Return Jacobian matrix df/dy.
varargout{1} = jacobian(t,y,p1,p2);
case jpattern % Return sparsity pattern matrix S.
varargout{1} = jpattern(t,y,p1,p2);
case mass % Return mass matrix.
varargout{1} = mass(t,y,p1,p2);
case events % Return [value,isterminal,direction].
[varargout{1:3}] = events(t,y,p1,p2);
otherwise
error([Unknown flag flag .]);
end
% --------------------------------------------------------------------------
TdS [MatLab; 01/02; N.O.; UniPG] - 13
% --------------------------------------------------------------------------
% --------------------------------------------------------------------------
% --------------------------------------------------------------------------
function S = jpattern(t,y,p1,p2)
S = < Insert Jacobian matrix sparsity pattern here. >;
% --------------------------------------------------------------------------
function M = mass(t,y,p1,p2)
M = < Insert mass matrix here. >;
% --------------------------------------------------------------------------