matlab training - simulating dynamic systems

9
Simulating Dynamic Systems 1 of 9 MA TLAB TRAINING SESSION IV SIMULATING DYNAMIC SYSTEMS MATLAB provides a variety of techniques for solving dynamics problems numerically. On-line help for each of the commands shown below is available by typing help ‘command_name’ or doc ‘command_name’ at the MATLAB prompt. Sampling the Solution Equation: Suppose you already have the solution to a dynamics problem and you want to obtain a plot of the response. The task would reduce to implementing the equation in MATLAB and sampling the function over some domain of interest. For a high fidelity reproduction of the function, the func- tion must be sampled with a spacial or time increment that captures many samples for each fre- quency that comprises the Fourier series for the function. In simpler terms, we can tell if we have used a small enough increment if the resulting plot appears smooth. The example shows how the same function can look jagged or smooth in the plot depending on the sampling increment.

Upload: hamed

Post on 12-Nov-2014

837 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

ne

of thehenc-

h fre-haveow the.

MATLAB TRAINING SESSION IV

SIMULATING DYNAMIC SYSTEMS

MATLAB provides a variety of techniques for solving dynamics problems numerically. On-lihelp for each of the commands shown below is available by typinghelp ‘command_name’ ordoc ‘command_name’ at the MATLAB prompt.

Sampling the Solution Equation:Suppose you already have the solution to a dynamics problem and you want to obtain a plotresponse. The task would reduce to implementing the equation in MATLAB and sampling tfunction over some domain of interest. For a high fidelity reproduction of the function, the fution must be sampled with a spacial or time increment that captures many samples for eacquency that comprises the Fourier series for the function. In simpler terms, we can tell if weused a small enough increment if the resulting plot appears smooth. The example shows hsame function can look jagged or smooth in the plot depending on the sampling increment

1 of 9

Page 2: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

d byren-deter-form

Suppose we find:

Linear Systems:There are three general purpose methods for solving dynamics problems; transfer functionmethod, state space integration method, and the MATLAB functionlsim .

Transfer Function Method:The transfer function method uses partial fraction expansion of the transfer function multipliethe Laplace transform of the forcing function to obtain the solution. The solution of the diffetial equation is expressed in terms of a linear combonation of complex exponentials that aremined by the poles and the corresponding residues in the partial fraction expansion. Thus theof the solution is:

Suppose we have

Then we can write

y t( ) 8 5e2t–

2πt( )sin 0.5 2πt( )cos+( )–=

y t( ) r i( ) p i( ) t⋅( )expi 1=

n

∑=

y 2y 5y+ + 5u t( ) u t( )+= and u t( ) input=

2 of 9

Page 3: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

Let the inputu(t) be the step function and to solve fory(t) do

With then

Let u(t) besin(2t) and to solve fory(t) do

s2Y s( ) sy 0( )– y 0( )– 2sY s( ) 2y 0( )– 5Y s( )+ + 5U s( ) sU s( ) u 0( )+ +=

Let y 0( ) 0= y 0( ) 0= u 0( ) 0=

Then Y s( ) s 5+

s2

2s 5+ +--------------------------U s( )=

U s( ) 1s---= Y s( ) s 5+

s s2

2s 5+ +( )---------------------------------=

U s( ) 2

s2

4+--------------=

3 of 9

Page 4: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

ABcor-ets

Integration Method:The integration method utilizes the state space representation of the system and the MATLode23 or theode45 integrator. One advantage of this method is that it is much easier to inporate the initial conditions in the solution without having to find the new transfer function. Llook at the last example given above.

The state space representation is

To implement the model create the M-file eqn1.m as shown

x t( ) 0 1

5– 2–x t( ) 0

1u t( )+= x Ax Bu+=

y 5 1 x t( )= y Cx Du+=

4 of 9

Page 5: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

lu-eble aret con-

,D)

r

s

Then at the MATLAB prompt, enter:

Special Purpose MATLAB Commands:The MATLAB control systems toolbox provides several built in functions for solving for the sotion to linear dynamic equations. All functions except either the transfer function or the statspace representations. When the functions are invoked with left hand arguments, the variafilled and a no plot is made. Each function has a variable number of possible valid argumenfigurations. Most function support both transfer function (num/den) and state space (A,B,Cforms. More information about each function can be found by typinghelp ‘function_name’ . Alist is provided below.

• initial(A,B,C,D,x0) Initial condition response of cont-time LTI systems• impulse(num,den,t) Impulse response of continuous time LTI systems

impulse(A,B,C,D,IU,t) IU = input channel number; t = sample time vecto• step(num,den,t) Step response of continuous time LTI systems

step(A,B,C,D,IU,t)• lsim(num,den,U,t) Simulation of c-time LTI systems to arbitrary input

lsim(A,B,C,D,U,t,x0) U = input time history (# of columns = # of inputs)

5 of 9

Page 6: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

ove .

For example lets work with the series resonant circuit:

With Matlab:

There is a corresponding function for discrete time dynamics for the functions mentioned abThe function would start with a ‘d’ likedstep for example.

Suppose we find the z-transform to be

Then

Ri Ltd

di 1C---- i τd

0

t

∫+ + Vs=

THEN LCt

2

dd i

RCtd

dii+ + C

tddV

=

RCs2

LCs 1+ +( )I s( ) CsV s( )= I s( )V s( )----------- Cs

LCs2

RCs 1+ +( )--------------------------------------------=

OR x1 i= x2 x1=x1

x2

0 1

1LC-------– R

L---–

x1

x2

0

1u+= y 0

1L---

x1

x2

=

~ L

R

C

Vs

G z( ) 0.4673z 0.3393–

z2

1.5327z– 0.6607+----------------------------------------------------=

6 of 9

Page 7: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

sed ina-

Nonlinear Systems:Nonlinear dynamics are solved by the integration method. The system equations are expresstate form described in a M-file function and theode integrators are used to solve for the state trjectories.

Consider the Wien-Bridge Oscillator:

Create the M-file wien.m as shown (Let R1 = R2 = C1 = C2 = 1.0)

Then with MATLAB

x11

C1R1------------- x1– x2 g x2( )–+[ ]=

x21

C2R1------------- x1– x2 g x2( )–+[ ] 1

C2R2-------------x2–=

g v( ) 3.234v 2.195v3

– 0.666v5

+=

7 of 9

Page 8: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

Consider the Cart and Pendulum Problem

Use a change of variables to y then we can write

Write the M-file cart.m

Then with MATLAB

M m+( ) x mlθ θ mlθ2

θsin–cos+ 0=

ml2θ mlx θ mlxθ θ mgl θsin+sin–cos+ 0=

x t( )x t( )θ t( )

θ t( )

y1

y2

y3

y4

=

1 0 0 0

0 M m+( ) 0 ml y3cos

0 0 1 0

0 ml y3cos 0 ml2

y1

y2

y3

y4

y2

mly42

y3sin

y4

ml y2y4 g–( ) y3sin

=

m

M

l

θ

x

8 of 9

Page 9: Matlab Training - Simulating Dynamic Systems

Simulating Dynamic Systems

9 of 9