Upload
eng-mohammed-kayed
View
240
Download
0
Embed Size (px)
Citation preview
8/13/2019 Chapter 11-2.doc
1/18
Chapter 11-2
Modeling and Simulating Dynamic Systems with Matlab
The Physical Model
The physical model treated in this example is described as follows.
Consider a simple mass-spring-dashpot mechanical system that can
be described by
wherey(t) is the instantaneous displacement of mass mfromequilibrium, and kand care proportionality constants that describe
the spring and dashpot properties.
This system can be put into state matrix form by letting x1 y and
x! dy"dt, gi#ing
where the matrices associated with the standard state
space format for $T% systems are gi#en by direct comparison with
the general equations,
Time Domain Simulation
Time domain simulations are possible using three state-space
&atlab functions, impulse, step, and lsim. 'or example, the
sequence for an arbitrary input function u(t) could be written as
sys = ss(!"!C!D#
!
8/13/2019 Chapter 11-2.doc
2/18
$%!T!&' = lsim(sys!!t!)o#
These commands can also be used with the frequency domain form
of a system where the $T% ob*ect is defined #ia sys = t*(num!den#.
+s a typical example, the impulseand stepfunctions are used in
&atlab file &$&.&to show the time domain beha#ior of
the mass-spring-dashpot system (see 'igs. /.! and /. below).
'ig. /.!. %mpulse response of typical second order system.
!/
http://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/modldemo.mhttp://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/modldemo.m8/13/2019 Chapter 11-2.doc
3/18
'ig. /.. 0tep response of typical second order system.
Model Con+ersion
The frequency domain representation of $T% systems is gi#en by
where the system transfer function matrix is
erforming the indicated matrix operations for the 0%0
mechanical system described abo#e gi#es a single scalar transfer
function,
!2
8/13/2019 Chapter 11-2.doc
4/18
This could also be easily deri#ed from the original !nd
orderdifferential equation.
3owe#er, multiple-input multiple-output (&%&) systems are
quite tedious to wor4 with algebraically, and the model con#ersion
functions in &atlab become quite useful. %n particular, the
con#ersions from state-space form to transfer function form (and
#ice #ersa) and from the transfer function form to 5ero-pole-gain
form are #ery useful. 6ith the new $T% ob*ect representation in
&atlab 7ersion / and higher, these con#ersions are quitestraightforward. The ss, t*, and ,pcommands easily con#ert
among the #arious forms. The &atlab functions to do the
con#ersions suggested abo#e are
sys1 = ss(!"!C!D#
sys2 = t*(sys1#
sys. = ,p(sys2#
ne can also extract the information stored within the data
structure associated with a particular $T% ob*ect with the ssdata,
t*data, and ,pdatacommands, or by direct structure-li4e
referencing. 'or example, the command,
$num!den' = t*data(sys2#
returns the numerators and denominators of the $T% ob*ect sys2.numand denare cell arrays with as many rows as outputs and as
many columns as inputs, and their i,* entries specify the transfer
function from input * to output i. ach cell array is a #ector that
contains the coefficients of the numerator or denominator
polynomial in s, in order of decreasing powers of s.
!8
8/13/2019 Chapter 11-2.doc
5/18
+n alternate approach would be to extract the indi#idual cell arrays
from the data structure and then display it using &atlab9s celldisp
command and"or perform other manipulations as desired. The
sequence for simply displaying the data could be accomplished
with the following commands:
*ieldnames(sys2#
num1 = sys2/num! den1 = sys2/den
celldisp(num1#! celldisp(den1#
0imilar manipulations can be performed with the 5ero-pole-gain
representation. %n particular, the command,
$0!P!' = ,pdata(sys.#
returns the 5eros, poles, and gain for each % channel of the $T%
system sys.. The 0and Pcell arrays and the matrix ha#e as
many rows as outputs and as many columns as inputs, and their i,*
entries specify the 5eros, poles, and gain of the transfer function
from input * to output i.
%n the case of the single-input single-output system (0%0) gi#en
here, the transfer function and 5ero-pole-gain form simplify to the
common representation gi#en by
The user is cautioned that model con#ersion for large systems is
tric4y because of potential numerical difficulties - so ma4e sure
that the results are reasonable;
!
8/13/2019 Chapter 11-2.doc
6/18
esidue or Partial 3raction 3orm
ne can also write the system in the partial fraction expansion
form. 'or example, =(s) for the 0%0 mechanical system can be
written as
where,
and r1and r!can be computed using a #ariety of methods >and 4(s)
?@. 'or problems of this type, &atlab has the residuefunction,
$r!p!' = residue("!#
where "and are row #ectors containing the polynomialcoefficients and rand pare column #ectors containing the residues
and poles, respecti#ely. (s#is only non-5ero if the order of "(s#is
greater than that of (s#/
3re4uency Domain Simulation
'requency domain simulations are conceptually straightforward,
but they can be computationally intensi#e. %n practice, one
e#aluates the expression,
for se#eral #alues of and then usually plots the data in one of
three ways - using Aode, Bichols, or Byquist plots.
!
8/13/2019 Chapter 11-2.doc
7/18
&atlab has se#eral functions for obtaining frequency domain
signatures. The first step is to generate a #ector of frequencies. The
points are usually logarithmically spaced between decades 1?d1and
1?d!with a total of n points,
w = logspace(d1!d2!n#
The bodeor ny4uistfunctions can then be used to e#aluate
at each ,
$M5!P6S7' = bode(sys!w#
or
$7!8M' = ny4uist(sys!w#
%f syshas BD inputs and BE outputs and $6 length(w), M5
and P6S7are BE-by-BD-by-$6 arrays and the response at the
frequency w(#is gi#en by M5(9!9!#and P6S7(9!9!#. +
similar description of the ny4uistoutput can be obtained from the
&atlab help files.
The frequency response for the 0%0 mass-spring-dashpot systemis computed as part of the &atlab sample session (see
&$&.&and 'igs. /. - /.
8/13/2019 Chapter 11-2.doc
8/18
'ig. /.. Aode magnitude plots for typical second order system.
!1
8/13/2019 Chapter 11-2.doc
9/18
'ig. /./. Aode phase plots for typical second order system.
!!
8/13/2019 Chapter 11-2.doc
10/18
'ig. /.2. Bichols plots for typical second order system.
!
8/13/2019 Chapter 11-2.doc
11/18
'ig. /.8. 3omemade Byquist plots for typical second order system.
!
8/13/2019 Chapter 11-2.doc
12/18
'ig. /.
8/13/2019 Chapter 11-2.doc
13/18
:/ Modeling and Simulating Dynamic Systems with Matlab
"loc Diagrams;Model "uilding
&any real systems that are comprised of se#eral components and
feedbac4 loops are gi#en in bloc4 diagram form. %t can be difficult
in some cases to find equi#alent system representations and the
corresponding state space matrices. 3owe#er, we can use &atlab
to help build the state space representation from the bloc4 diagram
form. ne can do this in &atlab using a #ariety of commands
within the Control Toolbox or by using the 0imulin4 graphical
interface for modeling dynamic systems.
To illustrate these processes, consider the simple mechanical
system example gi#en abo#e. $etFs first put this system in bloc4
diagram form, and then we can automatically recreate the original
state space and o#erall transfer function forms as a test of the
model building capabilities in &atlab and 0imulin4.
xpanding the state space equations and ta4ing the $aplace
transform of the indi#idual equations gi#es
The $aplace transform equations gi#e the indi#idual bloc4s, as
follows:
!2
8/13/2019 Chapter 11-2.doc
14/18
Bow connecting these bloc4s and specifying the desired output as
E(s) G1(s), gi#es
0ome minimal bloc4 diagram arithmetic gi#es the o#erall transfer
function between E(s) and D(s), where the resultant =(s) is the
same as before.
The
8/13/2019 Chapter 11-2.doc
15/18
1. efine the indi#idual 0%0 transfer functions for each bloc4
(numbered 1, !, , ..., nbloc4s). %n this example there are three
bloc4s where each transfer function is defined as the ratio
Bn(s)"n(s):
!. 6e then build an unconnected state-space model by repeated
calls to &atlabFs t*and appendcommands, as needed. 'or
example, we can append bloc4s 1, ! and to gi#e an
Hunconnected9 system with the following commands:
sys1 = t*(n1!d1#! sys2 = t*(n2!d2#! sys. = t*(n.!d.#
sysuct = append(sys1!sys2!sys.#! sysucs = ss(sysuct#
which gi#es the system
To simplify this process for the case of se#eral 0%0 bloc4s, the
appendcommand can ha#e as many systems in the input argument
list as needed.
. efine a matrix, >, that indicates how the indi#idual bloc4s are
interconnected. The matrix >has a row for each bloc4. The firstelement in each row is the bloc4 number and the subsequent
entries contain the bloc4 numbers where the current bloc4 gets its
summing inputs (a negati#e bloc4 number implies a negati#e
feedbac4 connection). 'or the abo#e example, the >matrix is
gi#en as
!
8/13/2019 Chapter 11-2.doc
16/18
> = $1 ? ?@ 2 1 -.@ . 2 ?'
. %dentify the system inputs and outputs in row #ectors iuand iy,
respecti#ely, where the entries are simply the appropriate bloc4
numbers. %n our example, the iuand iy#ectors are identified as
iu = $1@,iy = $2'
/. The final step is to simply connect the bloc4s as described in the
>matrix into a full state matrix representation. The appropriate
statement is
syscs = connect(sysucs!>!iu!iy#
erforming these steps gi#es a state matrix formulation equi#alent
to the system described #ia the original bloc4 diagram.
The abo#e process may not gi#e a minimal state space reali5ation
of the system. This implies that there are probably some poles and
5eros that can be canceled. =enerally, this is not a problem, but
minimal systems are usually more efficient during time and
frequency domain simulations. &atlab has commands to remo#e
the extra states and find a minimal reali5ation (see minreal). 'orexample, for this system the proper command is
syscsm = minreal(syscs#
+t this point the user has an o#erall state space formulation of the
original system that was in the form of se#eral connected 0%0
bloc4s. The bloc4 diagram arithmetic that can often be a tedious
underta4ing has been completed automatically, resulting in a set of
state space matrices that capture the full dynamics of the originalsystem. ne can now wor4 with this system as desired. %n
&$&.&and &$&.T(an edited #ersion of the
diary file) we simply show that con#ersion bac4 into the transfer
function form gi#es the original transfer function that we started
with, thus successfully completing this modeling demonstration.
!
http://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/modldemo.mhttp://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/modldemo.otphttp://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/modldemo.mhttp://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/modldemo.otp8/13/2019 Chapter 11-2.doc
17/18
The Aew ay
+s a final tas4 let9s build the same system as *ust described, but
this time we will use the 0imulin4 graphical interface. %n simple
terms, 0imulin4 represents a graphical interface whichautomatically performs the appendand connectoperations that we
illustrated abo#e. %n fact, howe#er, 0imulin4 has e#ol#ed into a
#ery powerful modeling capability that can perform sophisticated
analyses of coupled linear and nonlinear systems within a
relati#ely easy-to-use en#ironment.
6e will briefly explore some additional 0imulin4 capabilities at a
later time. 'or now the goal is to simply build the abo#e -bloc4
system within 0imulin4, extract the state space matrices from the
resultant model, and illustrate that it gi#es the expected dynamic
response for the simple mechanical spring-mass-dashpot system.
The process starts with the graphical representation of the system
in 0imulin4 (see class demo). ne simply drags the appropriate
bloc4s from the 0imulin4 bloc4 library to the wor4space area.
ragging the mouse between desired connections connects the
inputs and outputs of the bloc4s. 'inally, the indi#idual bloc4s arecustomi5ed to contain the desired parameters for the current
simulation. The resulting graphical representation is sa#ed as a
model file (with an mdl extension) for later use within &atlab or as
a standalone 0imulin4 model.
%n the current demo, the 0imulin4 model was sa#ed as
&&0$.&$. 0imply typing &&0$ at the &atlab
prompt displays the graphical representation of the system. +lso,
the last step in &$&.& gi#es an illustration of how to usethe graphical model embedded in &&0$.&$. %n this case
we simply extract the $T% state matrices using the linmod
command,
$!"!C!D' = linmod(Bmdemosl#
!/?
http://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/mdemosl.mdlhttp://gershwin.ens.fr/vdaniel/Doc-Locale/Cours-Mirrored/Methodes-Maths/white/sdyn/mdemo/mdemosl.mdl8/13/2019 Chapter 11-2.doc
18/18
and proceed to show that the system is identical to those generated
abo#e. Thus, this first 0imulin4 demo simply shows that the
0imulin4 graphical interface can be used for model construction as
an alternati#e to the append, connect, sequence from the
Control Toolbox library. 0imulin4 is often the preferred optionprimarily because of its flexibility and ease of use.
6e ha#e completed this brief demo illustrating some of &atlab9s
modeling capabilities. %n general, the reader is encouraged to
browse through the help files for many of &atlabFs interesting and
useful functions and to gi#e 0imulin4 a try. 6ith some experience,
you will find that the &atlab"0imulin4 combination is one of the
best tools a#ailable for the modeling and simulation of medium-si5ed dynamic systems. 'eel free to experiment with some of their
many features.
!/1