Sie sind auf Seite 1von 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

where y(t) is the instantaneous displacement of mass m from equilibrium, and k and c are proportionality constants that describe the spring and dashpot properties. This system can be put into state matrix form by letting x1 x! dy"dt, gi#ing y and

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#

!()

$%!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 impulse and step functions 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.

!(/

'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

1erforming the indicated matrix operations for the 0%0, mechanical system described abo#e gi#es a single scalar transfer function,

!(2

This could also be easily deri#ed from the original !nd order differential 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 quite straightforward. The ss, t*, and ,p- commands 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 ,p-data commands, 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. num and den are 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

+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!1' = ,p-data(sys.# returns the 5eros, poles, and gain for each %, channel of the $T% system sys.. The 0 and P cell arrays and the 1 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;

!(<

2esidue 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 r1 and r! can be computed using a #ariety of methods >and 4(s) ?@. 'or problems of this type, &atlab has the residue function, $r!p!-' = residue("! # where " and are row #ectors containing the polynomial coefficients and r and p are 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.
!(C

&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?d1 and 1?d! with a total of n points, w = logspace(d1!d2!n# The bode or ny4uist functions can then be used to e#aluate at each , $M 5!P6 S7' = bode(sys!w# or $27!8M' = ny4uist(sys!w# %f sys has BD inputs and BE outputs and $6 length(w), M 5 and P6 S7 are BE-by-BD-by-$6 arrays and the response at the frequency w(-# is gi#en by M 5(9!9!-# and P6 S7(9!9!-#. + similar description of the ny4uist output can be obtained from the &atlab help files. The frequency response for the 0%0, mass-spring-dashpot system is computed as part of the &atlab sample session (see &,-$-.&,.& and 'igs. /.) - /.<). + comparison of the time domain responses in 'igs. /.! and /.( and the #arious frequency domain signatures in 'igs. /.) to /.8 can help identify characteristic features that are common for typical second order systems. &atlab can also automatically generate the desired plots if there are no left hand side arguments in the function call. 0ometimes this gi#es a better plot with a lot less wor4 (compare 'igs. /.8 and /.< for example).

!)?

'ig. /.). Aode magnitude plots for typical second order system.

!)1

'ig. /./. Aode phase plots for typical second order system.

!)!

'ig. /.2. Bichols plots for typical second order system.

!)(

'ig. /.8. 3omemade Byquist plots for typical second order system.

!))

'ig. /.<. &atlab generated Byquist plots for typical second order system.

!)/

:/ 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

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 <ld =ay Bow the challenge is to get &atlab to ta4e this o#erall system bloc4 diagram and automatically generate the state space and global transfer function representations. The Control Toolbox has a number of functions that can be used to accomplish this tas4. There are fi#e basic steps in this procedure:
!)8

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 append commands, 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 append command 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 first element 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
!)<

> = $1 ? ?@ 2 1 -.@ . 2 ?' ). %dentify the system inputs and outputs in row #ectors iu and iy, respecti#ely, where the entries are simply the appropriate bloc4 numbers. %n our example, the iu and 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# 1erforming 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). 'or example, 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 original system. ,ne can now wor4 with this system as desired. %n &,-$-.&,.& and &,-$-.&,.,T1 (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.
!)C

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 which automatically performs the append and connect operations 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 are customi5ed 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 use the graphical model embedded in &-.&,0$.&-$. %n this case we simply extract the $T% state matrices using the linmod command, $ !"!C!D' = linmod(BmdemoslC#
!/?

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, D sequence from the Control Toolbox library. 0imulin4 is often the preferred option primarily 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 mediumsi5ed dynamic systems. 'eel free to experiment with some of their many features.

!/1

Das könnte Ihnen auch gefallen