0% found this document useful (0 votes)
92 views

MATLAB - Modelling in Time Domain - Norman Nise

This document provides MATLAB examples for modeling systems in the time domain. It shows how to: 1) Plot signals over time using plot and specify the time range and signals. 2) Represent system matrices like A, B, C, and D that define state-space models. 3) Convert transfer functions between numerator/denominator and state-space representations using functions like tf2ss and ss.

Uploaded by

ichigo325
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

MATLAB - Modelling in Time Domain - Norman Nise

This document provides MATLAB examples for modeling systems in the time domain. It shows how to: 1) Plot signals over time using plot and specify the time range and signals. 2) Represent system matrices like A, B, C, and D that define state-space models. 3) Convert transfer functions between numerator/denominator and state-space representations using functions like tf2ss and ss.

Uploaded by

ichigo325
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

B.

2 MATLAB Examples 79

[e demon- the Command Window to see a list of choices for s. Multiple plots also can be
. 10(s f 2) obtained using plot (X1, Y1,51 ,X2tY2,52,X3,Y3,S3, ). In the
following example we plot on the same graph sin(s/) in red and cos(5r) in green
for /: 0 to 10 seconds in 0.01 second increments. Time is specified as t:start:
incremenl, : flnal.

' (ch2pL2)t % Display label.


Z+5s t:0:0.01:10; % Specify time range and increment.
f1:cos (5*t); % Specify f1 to be cos (5t) .
f2:sin (5*t) ; % Specify f2 to be sin (5t) .
2*5s pJ oc (r ,'1 ,'-' , t , f 2,'q' t % Pfot f1 in red and f2 in green.
pause

Chapter 3: Modeling iri the Time Domain


- 3)
t 0 1 0l
ch3p1 The square system matrix, A I o o t liswrittenwith a space or
-3) (s-5)- - L-e -8 -7.l
comma separating the elements of each row. The next row is indicated with a
al icrr.- semicolon or carriage return. The entire matrix is then enclosed in a pair of square
brackets.

:tored forms '(ch3p1)r % Display fabel.


between LTI A:[0 1 0; O 0 1; -9 -B -7] % Represent A.
rorr
merator and
Dn expressed
A:[0 1 0 % Represent A.
001
sfer function-
rinator. theu -9 -B -1)
pause
rctom in the
re concepts- ch3p2 A row vector, such as the output matrix C, can be represented with elements
separated by spaces or commas and enclosed in square brackets. A column vector,
such as input matrix B, can be written as elements separated by semicolons or
carriage returns, or as the transpose (') of a row vector.
-5)
'(ch3p2)' % Display Iabef.
c:t2 3 4l % Represent row vector C.
D t7. a. ol
D-tltett) % Represent cofumn vector B.
tort
D-t / % Represent column vector B.
B

el
'or'
B:[7 B 9]' % Represent column vector B.
pause

ch3p3 The state-space representation consists of specifying the A, B, C, and D


matrices followed by the creation of an LII state-space object using the MAILAB
command, ss (A, B, C, D) . flence, for the matrices in (ch3p1) and (ch3p2), the state-
space representation would be:
Itl Appendix B: MATLAB Tutorial

I (ch3p3)r % Display fabef. ch3p5 St


A:[0 10,'0 01;-9 -B -7] % Represent A. sented by
e:11 ; B; 9) ; % Represent column vector B. iu), wher
e-lt
L L-
1 At
J rl
.
.
% Represent row vector C. single-out1
D:O; % Represent D. be implem
E:ss (A, B, C, D) % Create an LTI obl ect and disPlaY. form or T
example, t
Ch3p4 (Example 3.4) Tiansfer functions represented either by numerator and
can be fou
denominator or an LII object can be converted to state space. For numeratol and
denominator fepresentation, the convelsion can be implemented using [A , B, C, D]
'(ch3p5)'
:tf2ss (num,den). The A matrix is returned in a form called the controller ,N,

canonical form, which will be explained in Chapter 5 in the text. To obtain the phase- A:[0 1 O;0
variable form, IAp, Bp, Cp , Dp], we perform the following operations: Ap:inv P ) B:11 ; B;9);
(

*A*p; Bp:inv (P)*B; Cp:C*P, Dp:D, whele P is a matrix with 1's along the anti- c:t2 3 4l
diagonal and 0's elsewhire. "These transformations will be explained in Chapter 5' rTtf
* ( s )'
The command inv (X) finds the inverse of a squale matrix. The symbol signifies
Inum, den]=
multiplication. For systems represented as LII objects, the command s s (F ) , where
f is an LII transfer-function object, can be used to convelt F to a state-space object'
Let us look at Example 3.4 in the text. For the numerator-denominator representa-
tion, notice that the MAILAB response associates the gain, 24, with the vector C
rather than the vector B as in the example in the text. Both representations are
equivalent. For the LTI transfer-function object, the conversion to state space does rLl
not yield the phase-variable form. The result is a balanced model that improves the Tss:ss (A,
acculacy of calculating eigenvalues, which are covered in Chapter 4. Since ss (E) 'Polynomi
does not yield familial forms of the state equations (nor is it possible to easily Trf:rf (rs
convert to familiar forms), we will have limited use for that transformation at this
time. rFactored
Tzpk=zpk
% Display fabel .
t

' (ch3p4 ) Example 4I


3.
t
Numerator-denominator representation conversion'
% Display fabel.
rController canonical forml pause
% Display 1abel.

num:24; % Define numerator of


%c(s):c(s)/R(s). Chaptel
% Deflne denominator of G (s) .
ch4p1 (Exa
den:[1 9 26 24);
% Convert G (s) to controfler order systei
[A, B, C, D]:tf 2ss (num, den)
% canonical form, store matrices (pos); settli
%A, B, C, D, anddisPlaY.
IPhase-variable form' % Display fabel. '(ch4p1) E
P:[0 0 1;O 1 0;1 0 0]; % Form trans f ormation matrix. p1:[1 3+7*
Ap=inv(P)*A*P % EormAmatrix, Phase-variable
% form. p2-ll 3-1*:
a^:i-.,/D\*P.
DY L!I
% Eorm B vector, Phase-variable
% form. deng:conr,
cP:c*P % Eorm C vector, Phase-variable
% form.

Dp:D % form D phase-variabfe form. omegan:sc


obj ect rePresentation' % Display label.
'LTI
T:tf (num, den) % Represent T (s):24/ (s^3+9s^2 + ,"13: (der
'" 26st24) as an LTf uransfer-
% function object.

Tss=ss (T) % Convert T (s) to state space. Ts:4/ (zet


pause
B.2 MATLAB Examples 795

dtfpS State-space representations can be converted to transfer functions repre-


sented by a numerator and a denominator using Inum, den]:ss2tf (A,Btc,D,
iu), where iu is the input number for multiple-input systems. For single-input,
single-output systems iu:1. For an LTI state-space system, Tss, the conversion can
be implemented using Ttf:tf (Tss ) to yield the transfer function in polynomial
form or Tzpk:zpk(Tss) to yield the transfer function in factored form. For
example, the transfer function represented by the matrices described in (ch3p3)
can be found as follows:

'(ch3p5)t % Display fabef.


rNon LT I I
% Display labef.
A:[0 10,'0 01;-9 -B -t); % Represent A.
B:11 ; B;9); % Represent B.
c:12 3 4) % Represent C.
D:0; . % Represent D.

'Ttf (s )r % Display fabef.


[num, den]:s s2Lf (A, B/ C/ D/ 1) % Convert state-space
% representation to a
% transfer function represented as
% a numerator and denominator in
c % polynomial form, G (s):num/den,
rIG % display num and den.
and
rLTf, % Display labef.
tu Tss:ss (A, B, C, D) % Eorm LTI state-space mode1.
(F) 'Polynomi al form, Ttf (s)' "o Display labeI.
Ttf:tf (Tss) % Transform from state space to
this % transfer function in polynomial
% form.
'Eactored form, Tzpk (s)r % Display labef.
Tzpk:zpk (Tss) % Transform from state space to

% transfer function in factored


% form.
pause

Chapter 4: Iime Response


ch4p1 (Example 4.6) We can use MAILAB to calculate characteristics of a second-
order system, such as damping ratio, (; natural fiequency, ou;percent overshoot,"/oos
(pos);settling time, 7"; and peak time, Tr.Let us look at Example 4.6 in the text.

'(ch4p1) Example4.6r % Display 1abef.


p1:[1 3+7*i]; ? Define polynomial containing
% first po1e.
p2:[7 3-7*7]; % Define polynomial containinqr
% second pole.
deng:conv (p7,p2) ; % Multiply the two polynomials to
? find the 2nd order polynomial,
% as^2+bs+c.
omeqlan:sqrt (deng (3) /denS (1) ) % Calcufate the naturaf frequency,
% sqrt (c/a).
^2+ zeta: (deng (2) /deng (1) ) / (2*omegan)
? Calcufate damping ratio,
%( (b/a) /2*wn) .
Is:4/ (zetatcmegan) e" CafcuIaLe settLind I i ma

% (4/z*wn).

You might also like