Sei sulla pagina 1di 13

Breve introduzione alluso di matlab per lanalisi di sistemi dinamici

Corso di Laurea in Ingegneria dellInformazione (N.O.)


Corso di Laurea in Ingegneria Elettronica (V.O.)

Indice
1 Introduzione 2

2 Studio di sistemi dinamici in matlab 2


2.1 Costruzione di sistemi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1.1 Sistema nello spazio di stato, TC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1.2 Matrice di trasferimento, TC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1.3 Sistema nello spazio di stato, TD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1.4 Matrice di trasferimento, TD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.5 Poli, zeri e guadagno, TC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Conversione di sistemi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.1 Conversione in spazio di stato . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.2 Matrice di trasferimento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.3 Conversione da sistema TC a sistema TD . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.4 Conversione da sistema TD a sistema TC . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.5 Conversione da sistema TD a sistema TD . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Analisi di sistemi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3.1 Calcolo degli autovalori . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3.2 Calcolo dei poli . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3.3 Calcolo degli zeri . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Simulazione di sistemi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4.1 Simulazione di sistemi lineari . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4.2 Simulazione di sistemi non lineari . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Gli help di matlab 5


3.1 Costruzione e conversione di sistemi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.1 SS Create state-space model or convert LTI model to state space. . . . . . . . . . . . . . . 5
3.1.2 TF Creation of transfer functions or conversion to transfer function. . . . . . . . . . . . . . 6
3.1.3 ZPK Create zero-pole-gain models or convert to zero-pole-gain format. . . . . . . . . . . . 7
3.1.4 C2D Conversion of continuous-time models to discrete time. . . . . . . . . . . . . . . . . . 8
3.1.5 D2C Conversion of discrete LTI models to continuous time. . . . . . . . . . . . . . . . . . . 8
3.1.6 D2D Resample discrete LTI system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2 Analisi di sistemi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.1 POLE Compute the poles of LTI models. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.2 EIG Find the poles of an LTI system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.3 ZERO Transmission zeros of LTI systems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Simulazione di sistemi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.3.1 LSIM Simulate time response of LTI models to arbitrary inputs. . . . . . . . . . . . . . . . 10
3.3.2 ODE45 Solve non-stiff differential equations, medium order method. . . . . . . . . . . . . . 10
3.3.3 ODEFILE ODE file syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

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.

2 Studio di sistemi dinamici in matlab


I comandi brevemente ricordati nel seguito fanno riferimento alla versione 5.3.0 (R11) di matlab, disponibile
nei laboratori didattici della facolt`a e del corso di laurea. Per la compatibilit`a con altre versioni di matlab si
rimanda alla documentazione tecnica stessa.
La versione 5.3.0 di matlab `e, di fatto, un linguaggio object oriented. In tale contesto, un sistema lineare `e
descritto da un oggetto specifico, le cui propriet`a dipendono dal tipo di rappresentazione prescelto. Uno stesso
sistema fisico pu`o infatti essere descritto nello spazio di stato o come matrice di trasferimento a tempo continuo,
oppure con modelli equivalenti a tempo discreto.
Sono disponibili costruttori particolari per ciascuna possibile rappresentazione, e funzioni di conversione tra
rappresentazioni diverse.
Si consideri allora un sistema dinamico a tempo continuo descritto dalle equazioni:

x = F xGu, x Rn , u Rm (1)
y = Hx + Du, y Rp , (2)

cui corrisponde una matrice di trasferimento

W (s) = H(sI F )1 G + D (3)

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.

2.1 Costruzione di sistemi


2.1.1 Sistema nello spazio di stato, TC
Un oggetto sistema, di tipo ss e con nome sys, nello spazio di stato e a tempo continuo, viene creato con il
comando: sys=ss(F,G,H,D);.
La matrice di legame diretto D, se non presente, pu`o essere sostituita dallo scalare 0, indipendentemente dalle
dimensioni del sistema.

2.1.2 Matrice di trasferimento, TC


Un oggetto sistema, di tipo tf e con nome sys, rappresentato come funzione di trasferimento e a tempo continuo,
viene creato con il comando: sys=tf(NUM,DEN);.
I parametri NUM e DEN sono matrici di dimensioni opportune con i coefficienti del numeratore e del denominatore
della matrice di trasferimento. Nel caso di sistemi scalari (singolo ingresso e singola uscita), NUM e DEN sono
due vettori riga, contenenti, ordinatamente, i coefficienti del numeratore e denominatore della funzione di
trasferimento.

2.1.3 Sistema nello spazio di stato, TD


Un oggetto sistema, di tipo ss e con nome sys, nello spazio di stato e a tempo discreto, con periodo di
campionamento pari a T s unit`a di tempo, viene creato con il comando: sys=ss(F,G,H,D,Ts);.
La matrice di legame diretto D, se non presente, pu`o essere sostituita dallo scalare 0, indipendentemente dalle
dimensioni del sistema.
TdS [MatLab; 01/02; N.O.; UniPG] - 3

2.1.4 Matrice di trasferimento, TD


Un oggetto sistema, di tipo tf e con nome sys, rappresentato come funzione di trasferimento e a tempo discreto,
con periodo di campionamento T s unit`a di tempo, viene creato con il comando: sys=tf(NUM,DEN,Ts);.
I parametri NUM e DEN sono matrici di dimensioni opportune con i coefficienti del numeratore e del denominatore
della matrice di trasferimento. Nel caso di sistemi scalari (singolo ingresso e singola uscita), NUM e DEN sono
due vettori riga, contenenti, ordinatamente, i coefficienti del numeratore e denominatore della funzione di
trasferimento.

2.1.5 Poli, zeri e guadagno, TC


Un oggetto sistema, di tipo zpk e con nome sys, rappresentato tramite linsieme dei poli, degli zeri e del
guadagno, a tempo continuo, viene creato con il comando: sys=zpk(Z,P,K);.
I parametri Z, P e K sono matrici di dimensioni opportune contenenti, rispettivamente, gli zeri, i poli ed il
vettore dei guadagni del sistema. Per modelli scalari, Z, P sono i vettori degli zeri e dei poli della funzione di
tasferimento, mentre K `e un guadagno scalare.

2.2 Conversione di sistemi


Le varie rappresentazioni di un dato sistema dinamico possono essere facilmente convertite tra loro con comandi
di conversione. Tali comandi prendono la stessa forma dei comandi di creazione, ma vengono applicati ad un
oggetto sistema gi`a definito anziche ad insiemi di parametri di descrizione del sistema stesso.

2.2.1 Conversione in spazio di stato


Il comando SYS2 = SS(SYS1) converte un sistema SYS1, con rappresentazione arbitraria, in un modello nello
spazio di stato. In particolare, se SYS1 `e una matrice di trasferimento, il comando calcola una realizzazione di
tale funzione di trasferimento.

2.2.2 Matrice di trasferimento


Il comando SYS2 = TF(SYS1) converte un sistema SYS1, con rappresentazione arbitraria, in una matrice di
trasferimento.

2.2.3 Conversione da sistema TC a sistema TD


Il comando SYSD = C2D(SYSC,TS,METHOD) converte il modello a tempo continuo SYSC nel corrispondente mo-
dello a tempo discreto SYSD, con periodo di campionamento pari a T S unit`a di tempo. Il parametro METHOD
indica il metodo di conversione da utilizzare. Il metodo di default `e zoh , cio`e basato su una tenuta di ordine
` il metodo utilizzato se il parametro viene omesso.
zero degli ingressi. E

2.2.4 Conversione da sistema TD a sistema TC


Il comando SYSC = D2C(SYSD,METHOD) converte il modello a tempo discreto SYSD nel corrispondente modello
a tempo continuo SYSC. Il parametro METHOD indica il metodo di conversione da utilizzare. Il metodo di default
`e zoh , e viene utilizzato se il parametro viene omesso.

2.2.5 Conversione da sistema TD a sistema TD


Il comando SYS2 = D2d(SYS1,TS,METHOD) converte il modello a tempo discreto SYSD nellulteriore modello a
tempo discreto SYS2, caratterizzato da un diverso periodo di campionamento T S. Il parametro METHOD indica
il metodo di conversione da utilizzare. Il metodo di default `e zoh , e viene utilizzato se il parametro viene
omesso.

2.3 Analisi di sistemi


Sono disponibili comandi per determinare in modo diretto autovalori, poli e zeri di sistemi.

2.3.1 Calcolo degli autovalori


Gli autovalori del sistema dinamico SYS possono essere calcolati con il comando EIG(SYS). Il comando `e efficace
se il sistema SYS `e una rappresentazione nello spazio di stato. In caso contrario il comando restituisce i poli.
TdS [MatLab; 01/02; N.O.; UniPG] - 4

2.3.2 Calcolo dei poli


I poli del sistema dinamico SYS possono essere calcolati con il comando POLE(SYS).

2.3.3 Calcolo degli zeri


Gli zeri (di trasmissione) del sistema dinamico SYS possono essere calcolati con il comando ZERO(SYS).

2.4 Simulazione di sistemi


La simulazione di sistemi dinamici consiste, sostanzialmente, nella soluzione per via numerica delle equazioni
differenziali o alle differenze finite che descrivono il sistema stesso. Nel caso di sistemi lineari la procedura `e
assai semplice, e si basa sulluso del comando lsim. Nel caso di sistemi non lineari si deve invece ricorrere a
procedure pi` u articolate di integrazione numerica.

2.4.1 Simulazione di sistemi lineari


Il comando per simulare il comportamento di un sistema dinamico `e lsim(SYS,U,T,X0), dove SYS `e un oggetto
di tipo sistema, con rappresentazione arbitraria, U `e un vettore contenente i campioni del segnale di ingresso,
calcolati in corrispondenza degli istanti di tempo contenuti nel vettore T. Infine X0 `e il vettore delle condizioni
iniziali, e pu`o essere specificato solo se il sistema SYS `e una rappresentazione nello spazio di stato. Un esempio
di utilizzo del comando per il calcolo della risposta di un sistema dinamico `e contenuto nel file massamolla.m,
disponibile in formato elettronico sulle pagine web del corso.

2.4.2 Simulazione di sistemi non lineari


La simulazione di sistemi non lineari richiede procedure di integrazione numerica diverse rispetto a quello
possibili per i sistemi lineari. In matlab `e disponibile un ricco ventaglio di possibilit`a, complessivamente indicate
con il termine ODE Suite (ODE: Ordinary Differential Equation). Nel seguito verr`a illustrato, a titolo di esempio,
luso di una delle possibili procedure di integrazione: ODE45.
Il comando [T,Y] = ODE45(odefile,TSPAN,Y0) integra le equazioni differenziali contenute nel file con
nome dato dalla stringa odefile, per un intervallo TSPAN=[T0 TFinale], a partire dalle condizioni iniziali
contenute nel vettore Y0.
Il sistema dinamico da simulare viene descritto in un file separato. Il formato tipico di tale file (detto
ODEFILE in ambiente matlab) `e illustrato il seguente:

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);

% Definizione dei parametri del sistema


g=9.8; l=0.5; m=0.5; c1=-g/l; c2=1/(m*l*l);

% Calcolo della legge di controllo


u=0 % sistema in evoluzione libera

% Modello dinamico del sistema


xp1=x(2); xp2=c1*sin(x(1)) + c2*u;

% 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

% Simulazione dinamica di un pendolo.


% Traccia per la simulazione di un sistema non lineare in matlab.
% Parte della tesina di Teoria dei Sistemi
% Modulo congiunto Nuovo e Vecchio Ordinamento
% Anno Accademico 2001/02 - Universit di Perugia
%

% Intervallo temporale da simulare


tspan=[0 20*pi];

% Vettore delle condizioni iniziali del sistema da simulare


x0=[1; 0];

% Opzioni per la routine di integrazione


% options = odeset(RelTol,1e-7,AbsTol,[1e-7 1e-7]);

% Inizialmente le opzioni pssono essere omesse.


% Se le opzioni vengono utilizzate, il comando per eseguire la simulazione :
% [tempo,x] = ODE45(pendolo,tspan,x0,options);
% In alternativa, se NON vengono utilizzate, il comando :
% [tempo,x] = ODE45(pendolo,tspan,x0);

% Comando per lintegrazione numerica delle equazione contenute nel file (ODEFILE) "pendolo.m"
[tempo,x] = ODE45(pendolo,tspan,x0);

% Esempio di visualizzazione dei risultati. Andamento della posizione del pendolo.


plot(tempo,x(:,1)) title(Simulazione di un pendolo in evoluzione libera);
xlabel(Tempo);
ylabel(Posizione del pendolo (rad));

3 Gli help di matlab


3.1 Costruzione e conversione di sistemi
3.1.1 SS Create state-space model or convert LTI model to state space.
Creation:
SYS = SS(A,B,C,D) creates a continuous-time state-space (SS) model
SYS with matrices A,B,C,D. The output SYS is a SS object. You
can set D=0 to mean the zero matrix of appropriate dimensions.

SYS = SS(A,B,C,D,Ts) creates a discrete-time SS model with sample


time Ts (set Ts=-1 if the sample time is undetermined).

SYS = SS creates an empty SS object.


SYS = SS(D) specifies a static gain matrix D.

In all syntax above, the input list can be followed by pairs


PropertyName1, PropertyValue1, ...
that set the various properties of SS models (type LTIPROPS for
details). To make SYS inherit all its LTI properties from an
existing LTI model REFSYS, use the syntax SYS = SS(A,B,C,D,REFSYS).

Arrays of state-space models:


You can create arrays of state-space models by using ND arrays for
A,B,C,D above. The first two dimensions of A,B,C,D determine the
number of states, inputs, and outputs, while the remaining
TdS [MatLab; 01/02; N.O.; UniPG] - 6

dimensions specify the array sizes. For example, if A,B,C,D are


4D arrays and their last two dimensions have lengths 2 and 5, then
SYS = SS(A,B,C,D)
creates the 2-by-5 array of SS models
SYS(:,:,k,m) = SS(A(:,:,k,m),...,D(:,:,k,m)), k=1:2, m=1:5.
All models in the resulting SS array share the same number of
outputs, inputs, and states.

SYS = SS(ZEROS([NY NU S1...Sk])) pre-allocates space for an SS array


with NY outputs, NU inputs, and array sizes [S1...Sk].

Conversion:
SYS = SS(SYS) converts an arbitrary LTI model SYS to state space,
i.e., computes a state-space realization of SYS.

SYS = SS(SYS,min) computes a minimal realization of SYS.

See also LTIMODELS, DSS, RSS, DRSS, SSDATA, LTIPROPS, TF, ZPK, FRD.

3.1.2 TF Creation of transfer functions or conversion to transfer function.


Creation:
SYS = TF(NUM,DEN) creates a continuous-time transfer function SYS with
numerator(s) NUM and denominator(s) DEN. The output SYS is a TF object.

SYS = TF(NUM,DEN,TS) creates a discrete-time transfer function with


sample time TS (set TS=-1 if the sample time is undetermined).

S = TF(s) specifies the transfer function H(s) = s (Laplace variable).


Z = TF(z,TS) specifies H(z) = z with sample time TS.
You can then specify transfer functions directly as rational expressions
in S or Z, e.g.,
s = tf(s); H = (s+1)/(s^2+3*s+1)

SYS = TF creates an empty TF object.


SYS = TF(M) specifies a static gain matrix M.

In all syntax above, the input list can be followed by pairs


PropertyName1, PropertyValue1, ...
that set the various properties of TF models (type LTIPROPS for details).
To make SYS inherit all its LTI properties from an existing LTI model
REFSYS, use the syntax SYS = TF(NUM,DEN,REFSYS).

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) ]

By default, transfer functions are displayed as functions of s or z.


TdS [MatLab; 01/02; N.O.; UniPG] - 7

Alternatively, you can set the variable name to p (continuous time)


and z^-1 or q (discrete time) by modifying the Variable property.

Arrays of transfer functions:


You can create arrays of transfer functions by using ND cell arrays for
NUM and DEN above. For example, if NUM and DEN are cell arrays of size
[NY NU 3 4], then
SYS = TF(NUM,DEN)
creates the 3-by-4 array of transfer functions
SYS(:,:,k,m) = TF(NUM(:,:,k,m),DEN(:,:,k,m)), k=1:3, m=1:4.
Each of these transfer functions has NY outputs and NU inputs.

To pre-allocate an array of zero transfer functions with NY outputs


and NU inputs, use the syntax
SYS = TF(ZEROS([NY NU k1 k2...])) .

Conversion:
SYS = TF(SYS) converts an arbitrary LTI model SYS to the transfer
function representation. The result is a TF object.

SYS = TF(SYS,inv) uses a fast algorithm for conversion from state


space to TF, but is typically less accurate for high-order systems.

See also LTIMODELS, FILT, SET, GET, TFDATA, SUBSREF, LTIPROPS, ZPK, SS.

3.1.3 ZPK Create zero-pole-gain models or convert to zero-pole-gain format.


Creation:
SYS = ZPK(Z,P,K) creates a continuous-time zero-pole-gain (ZPK)
model SYS with zeros Z, poles P, and gains K. The output SYS is
a ZPK object.

SYS = ZPK(Z,P,K,Ts) creates a discrete-time ZPK model with sample


time Ts (set Ts=-1 if the sample time is undetermined).

S = ZPK(s) specifies H(s) = s (Laplace variable).


Z = ZPK(z,TS) specifies H(z) = z with sample time TS.
You can then specify ZPK models directly as rational expressions in
S or Z, e.g.,
z = zpk(z,0.1); H = (z+.1)*(z+.2)/(z^2+.6*z+.09)

SYS = ZPK creates an empty zero-pole-gain model.


SYS = ZPK(D) specifies a static gain matrix D.

In all syntax above, the input list can be followed by pairs


PropertyName1, PropertyValue1, ...
that set the various properties of ZPK models (type LTIPROPS for
details). To make SYS inherit all its LTI properties from an
existing LTI model REFSYS, use the syntax SYS = ZPK(Z,P,K,REFSYS).

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 MIMO systems with NY outputs and NU inputs,


* Z and P are NY-by-NU cell arrays where Z{i,j} and P{i,j}
specify the zeros and poles of the transfer function from
input j to output i
* K is the 2D matrix of gains for each I/O channel.
TdS [MatLab; 01/02; N.O.; UniPG] - 8

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) ]

Arrays of zero-pole-gain models:


You can create arrays of ZPK models by using ND cell arrays for Z,P
above, and an ND array for K. For example, if Z,P,K are 3D arrays
of size [NY NU 5], then
SYS = ZPK(Z,P,K)
creates the 5-by-1 array of ZPK models
SYS(:,:,m) = ZPK(Z(:,:,m),P(:,:,m),K(:,:,m)), m=1:5.
Each of these models has NY outputs and NU inputs.

To pre-allocate an array of zero ZPK models with NY outputs and NU


inputs, use the syntax
SYS = ZPK(ZEROS([NY NU k1 k2...])) .

Conversion:
SYS = ZPK(SYS) converts an arbitrary LTI model SYS to the ZPK
representation. The result is a ZPK object.

SYS = ZPK(SYS,inv) uses a fast algorithm for conversion from state


space to ZPK, but is typically less accurate for high-order systems.

See also LTIMODELS, SET, GET, ZPKDATA, SUBSREF, SUBSASGN, LTIPROPS, TF, SS.

3.1.4 C2D Conversion of continuous-time models to discrete time.


SYSD = C2D(SYSC,TS,METHOD) converts the continuous-time LTI
model SYSC to a discrete-time model SYSD with sample time TS.
The string METHOD selects the discretization method among the
following:
zoh Zero-order hold on the inputs.
foh Linear interpolation of inputs (triangle appx.)
tustin Bilinear (Tustin) approximation.
prewarp Tustin approximation with frequency prewarping.
The critical frequency Wc is specified as fourth
input by C2D(SYSC,TS,prewarp,Wc).
matched Matched pole-zero method (for SISO systems only).
The default is zoh when METHOD is omitted.

For state-space models SYS and the zoh or foh methods,


[SYSD,G] = C2D(SYSC,TS,METHOD)
also returns a matrix G that maps continuous initial conditions
into discrete initial conditions. Specifically, if x0,u0 are
initial states and inputs for SYSC, then equivalent initial
conditions for SYSD are given by
xd0 = G * [x0;u0], ud0 = u0 .

See also D2C, D2D, LTIMODELS.

3.1.5 D2C Conversion of discrete LTI models to continuous time.


SYSC = D2C(SYSD,METHOD) produces a continuous-time model SYSC
that is equivalent to the discrete-time LTI model SYSD.
The string METHOD selects the conversion method among the
following:
zoh Assumes zero-order hold on the inputs.
TdS [MatLab; 01/02; N.O.; UniPG] - 9

tustin Bilinear (Tustin) approximation.


prewarp Tustin approximation with frequency prewarping.
The critical frequency Wc is specified last as in
D2C(SysD,prewarp,Wc)
matched Matched pole-zero method (for SISO systems only).
The default is zoh when METHOD is omitted.

See also C2D, D2D, LTIMODELS.

3.1.6 D2D Resample discrete LTI system.


SYS = D2D(SYS,TS) resamples the discrete-time LTI model SYS
to produce an equivalent discrete system with sample time TS.

See also D2C, C2D, LTIMODELS.

3.2 Analisi di sistemi


3.2.1 POLE Compute the poles of LTI models.
P = POLE(SYS) computes the poles P of the LTI model SYS (P is
a column vector).

For state-space models, the poles are the eigenvalues of the A


matrix or the generalized eigenvalues of the (A,E) pair in the
descriptor case.

If SYS is an array of LTI models with sizes [NY NU S1 ... Sp],


the array P has as many dimensions as SYS and P(:,1,j1,...,jp)
contains the poles of the LTI model SYS(:,:,j1,...,jp). The
vectors of poles are padded with NaN values for models with
relatively fewer poles.

See also DAMP, ESORT, DSORT, PZMAP, ZERO, LTIMODELS.

There is more than one pole available. See also


help tf/pole.m
help ss/pole.m
help frd/pole.m

3.2.2 EIG Find the poles of an LTI system.


P = EIG(SYS) returns the poles of SYS (P is a column vector).

For state-space models, the poles are the eigenvalues of the A


matrix or the generalized eigenvalues of the (A,E) pair in the
descriptor case.

See also DAMP, ESORT, DSORT, PZMAP, TZERO.

3.2.3 ZERO Transmission zeros of LTI systems.


Z = ZERO(SYS) returns the transmission zeros of the LTI
model SYS.

[Z,GAIN] = ZERO(SYS) also returns the transfer function gain


(in the zero-pole-gain sense) for SISO models SYS.

If SYS is an array of LTI models with sizes [NY NU S1 ... Sp],


Z and K are arrays with as many dimensions as SYS such that
Z(:,1,j1,...,jp) and K(1,1,j1,...,jp) give the zeros and gain
TdS [MatLab; 01/02; N.O.; UniPG] - 10

of the LTI model SYS(:,:,j1,...,jp). The vectors of zeros are


padded with NaN values for models with relatively fewer zeros.

See also POLE, PZMAP, ZPK, LTIMODELS.

There is more than one zero available. See also


help tf/zero.m
help ss/zero.m
help frd/zero.m

3.3 Simulazione di sistemi


3.3.1 LSIM Simulate time response of LTI models to arbitrary inputs.
LSIM(SYS,U,T) plots the time response of the LTI model SYS to the
input signal described by U and T. The time vector T consists of
regularly spaced time samples and U is a matrix with as many columns
as inputs and whose i-th row specifies the input value at time T(i).
For example,
t = 0:0.01:5; u = sin(t); lsim(sys,u,t)
simulates the response of a single-input model SYS to the input
u(t)=sin(t) during 5 seconds.

For discrete-time models, U should be sampled at the same rate as SYS


(T is then redundant and can be omitted or set to the empty matrix).
For continuous-time models, choose the sampling period T(2)-T(1) small
enough to accurately describe the input U. LSIM checks for intersample
oscillations and resamples U if necessary.

LSIM(SYS,U,T,X0) specifies an additional nonzero initial state X0


(for state-space models only).

LSIM(SYS1,SYS2,...,U,T,X0) simulates the response of multiple LTI


models SYS1,SYS2,... on a single plot. The initial condition X0
is optional. You can also specify a color, line style, and marker
for each system, as in
lsim(sys1,r,sys2,y--,sys3,gx,u,t).

When invoked with left-hand arguments,


[YS,TS] = LSIM(SYS,U,T)
returns the output history YS and time vector TS used for simulation.
No plot is drawn on the screen. The matrix YS has LENGTH(TS) rows
and as many columns as outputs in SYS.
WARNING: TS contains more points than T when U is resampled to reveal
intersample oscillations. To get the response at the samples T only,
extract YS(1:d:end,:) where d=round(length(TS)/length(T)).

For state-space models,


[YS,TS,XS] = LSIM(SYS,U,T,X0)
also returns the state trajectory XS, a matrix with LENGTH(TS) rows
and as many columns as states.

See also GENSIG, STEP, IMPULSE, INITIAL, LTIMODELS.

3.3.2 ODE45 Solve non-stiff differential equations, medium order method.


[T,Y] = ODE45(F,TSPAN,Y0) with TSPAN = [T0 TFINAL] integrates the
system of differential equations y = F(t,y) from time T0 to TFINAL with
initial conditions Y0. F is a string containing the name of an ODE
file. Function F(T,Y) must return a column vector. Each row in
TdS [MatLab; 01/02; N.O.; UniPG] - 11

solution array Y corresponds to a time returned in column vector T. To


obtain solutions at specific times T0, T1, ..., TFINAL (all increasing
or all decreasing), use TSPAN = [T0 T1 ... TFINAL].

[T,Y] = ODE45(F,TSPAN,Y0,OPTIONS) solves as above with default


integration parameters replaced by values in OPTIONS, an argument
created with the ODESET function. See ODESET for details. Commonly
used options are scalar relative error tolerance RelTol (1e-3 by
default) and vector of absolute error tolerances AbsTol (all
components 1e-6 by default).

[T,Y] = ODE45(F,TSPAN,Y0,OPTIONS,P1,P2,...) passes the additional


parameters P1,P2,... to the ODE file as F(T,Y,FLAG,P1,P2,...) (see
ODEFILE). Use OPTIONS = [] as a place holder if no options are set.

It is possible to specify TSPAN, Y0 and OPTIONS in the ODE file (see


ODEFILE). If TSPAN or Y0 is empty, then ODE45 calls the ODE file
[TSPAN,Y0,OPTIONS] = F([],[],init) to obtain any values not supplied
in the ODE45 argument list. Empty arguments at the end of the call list
may be omitted, e.g. ODE45(F).

As an example, the commands

options = odeset(RelTol,1e-4,AbsTol,[1e-4 1e-4 1e-5]);


ode45(rigidode,[0 12],[0 1 1],options);

solve the system y = rigidode(t,y) with relative error tolerance 1e-4


and absolute tolerances of 1e-4 for the first two components and 1e-5
for the third. When called with no output arguments, as in this
example, ODE45 calls the default output function ODEPLOT to plot the
solution as it is computed.

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.

[T,Y,TE,YE,IE] = ODE45(F,TSPAN,Y0,OPTIONS) with the Events property in


OPTIONS set to on, solves as above while also locating zero crossings
of an event function defined in the ODE file. The ODE file must be
coded so that F(T,Y,events) returns appropriate information. See
ODEFILE for details. Output TE is a column vector of times at which
events occur, rows of YE are the corresponding solutions, and indices in
vector IE specify which event occurred.

See also ODEFILE and


other ODE solvers: ODE23, ODE113, ODE15S, ODE23S, ODE23T, ODE23TB
options handling: ODESET, ODEGET
output functions: ODEPLOT, ODEPHAS2, ODEPHAS3, ODEPRINT
odefile examples: ORBITODE, ORBT2ODE, RIGIDODE, VDPODE

3.3.3 ODEFILE ODE file syntax.


An ODE file is an M-file function you write to define a differential
equation problem for the ODE Suite solvers. This M-file is referred to as
ODEFILE here, although you can give your M-file any name you like.
TdS [MatLab; 01/02; N.O.; UniPG] - 12

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

FLAGS RETURN VALUES


(empty) - F(t,y)
init - default TSPAN, Y0 and OPTIONS for this problem
jacobian - Jacobian matrix J(t,y) = dF/dy
jpattern - matrix showing the Jacobian sparsity pattern
mass - mass matrix M, M(t), or M(t,y), for solving M*y = F(t,y)
events - information for zero-crossing location

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.

function varargout = odefile(t,y,flag,p1,p2)

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 dydt = f(t,y,p1,p2)


dydt = < Insert a function of t and/or y, p1, and p2 here. >

% --------------------------------------------------------------------------

function [tspan,y0,options] = init(p1,p2)


tspan = < Insert tspan here. >;
y0 = < Insert y0 here. >;
options = < Insert options = odeset(...) or [] here. >;

% --------------------------------------------------------------------------

function dfdy = jacobian(t,y,p1,p2)


dfdy = < Insert Jacobian matrix here. >;

% --------------------------------------------------------------------------

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. >;

% --------------------------------------------------------------------------

function [value,isterminal,direction] = events(t,y,p1,p2)


value = < Insert event function vector here. >
isterminal = < Insert logical ISTERMINAL vector here.>;
direction = < Insert DIRECTION vector here.>;

Potrebbero piacerti anche