Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 24

Mathematical modeling of dynamic system

Definition: Mathematical modeling of dynamic system is defined as a set of equations that


represents the dynamics of the system accurately or at least fairly well. A system may be
represented in many different ways, and, therefore may have many mathematical models,
depending on one’s perspective.

How to describe the dynamic systems:


The dynamics of many systems, whether they are mechanical, electrical , thermal,
economic, biological, and so on, may be described in terms of differential equations. Such
differential equations may be obtained by using physical laws governing a particular system for
example, Newton laws for mechanical systems, Kirchhoff’s laws for electrical systems.

Different forms of mathematical models:


 State space representation: is suitable for optimal control problems
 Transfer function representation: is used for transient response or
frequency response analysis of single- input-single-output, linear-
invariant system

Selection of model depends on the particular system and the particular circumstances

Modeling using transfer function:


 Derive the differential equation for the system
 Take laplace transform of the differential equations
 Take the ratio of output to input. This ratio is the transfer function

1
Example:

Assume the equations of motion for the system are:

m1 x1  k1 x1  k 2 ( x1  x 2 )  b( x 1  x 2 )  u
m2 x2   k 3 x 2  k 2 ( x 2  x1 )  b( x 2  x 1 )

X 1 (s) X 2 ( s)
Obtain the transfer functions:- and
U (s) U ( s) ?

Solution:-

Rearrange the equation in following form:

m1 x1  bx 1  (k1  k 2 ) x1  bx 2  k 2 x 2  u


m2 x2  bx 2  (k 2  k 3 ) x 2  bx 1  k 2 x1

Taking the Laplace transform of these two equations:

m s
1
2

 bs  (k1  k 2 ) X 1 ( s )  (bs  k 2 ) X 2 ( s )  U ( s )  (1)
m s
2
2
 bs  (k 2  k ) X
3 2 ( s )  (bs  k 2 ) X 1 ( s )    (2)

Solving equation 2 for X 2 ( s ) and substituting it into equation 1 and rearrange it to get:

X 1 (s) m2 s 2  bs  k 2  k 3
  (3)
U ( s) (m1 s 2  bs  k1  k 2 )(m2 s 2  bs  k 2  k 3 )  (bs  k 2 ) 2

From equations 2 and 3 we get:

X 2 ( s) bs  k 2

U ( s ) (m1 s  bs  k1  k 2 )(m2 s 2  bs  k 2  k 3 )  (bs  k 2 ) 2
2

Transfer Function Representation

2
Commands covered: tf2zp zp2tf cloop feedback parallel series

Transfer functions are defined in MATLAB by storing the coefficients of the


numerator and the denominator in vectors. Given a continuous-time transfer function

Where :

and

Matlab representation:-

Store the coefficients of B(s) and A(s) in the vectors

In this text, the names of the vectors are generally chosen to be num
and den, but any other name could be used.

For example is defined by:


num = [2 3];
den = [1 4 0 5];

Note that all coefficients must be included


in the vector, even zero coefficients

3
zeros, poles and gain:
A transfer function may also be defined in terms of its zeros, poles and
gain:

To find the zeros, poles and gain of a transfer function from the vectors num and den
which contain the coefficients of the numerator and denominator polynomials, type

[z,p,k] = tf2zp(num,den)

The zeros are stored in z, the poles are stored in p, and the gain is stored in k.

To find the numerator and denominator polynomials from z, p, and k, type

[num,den] = zp2tf(z,p,k)

4
Overall transfer function of individual systems
The overall transfer function of individual systems in parallel, series or feedback can be
found using MATLAB.

G (s )

R (s ) C (s )
+
-

H (s )

Feedback System

For the above feedback system :

Store the transfer function G in numG and denG, and the transfer function H in
numH and denH. To reduce the general feedback system to a single transfer function,

T(s) = C(s)/R(s) = G(s)/(1+G(s)H(s))

Type:

>> [numT,denT] = feedback(numG,denG,numH,denH);

For a unity feedback system: let numH = 1 and denH = 1 before applying the
above algorithm. Alternately, use the command

[numT,denT] = cloop(numG,denG,-1);

5
R(s) C(s)
G (s) H (s)

Cascaded system

To reduce the series system to a single transfer function:

T(s) =C(s)/R(s)= G(s)H(s)

Type:

>> [numT,denT] = series(numG,denG,numH,denH);

G (s)
R(s) C(s)

H (s)
Parallel system

To reduce the parallel system to a single transfer function, T(s) = C(s)/R(s)=G(s) + H(s)

Type:

>>[numT,denT] = parallel(numG,denG,numH,denH);

6
Example

R(s) C(s) G1(s)


G1 ( s) G2 ( s) R(s) C(s)

Cascaded system
G2 (s)
Parallel system

Assume :
10 5
G1 ( s)  G2 ( s) 
G1 (s) s  2s  10
2
s5

R (s ) C (s ) find C(s)/R(s) for each arrangement


+
- of G1 ( s ) and G 2 ( s ) shown in above
figure?
G2 (s)

Solution

MATLAB program:

num1=[0 0 10];
den1=[1 2 10];
num2=[0 5];
den2=[1 5];

% for cascaded arrangement


[nums,dens]=series(num1,den1,num2,den2);
Printsys(nums,dens)

% for parallel arrangement


[nump,denp]=parallel(num1,den1,num2,den2);
Printsys(nump,denp)

% for feedback arrangement


[numf,denf]=feedback(num1,den1,num2,den2);
Printsys(numf,denf)

7
Continuous Time System Analysis
Time Simulations

Commands covered: residue step impulse lsim

1- residue

The analytical method to find the time response of a system requires


taking the inverse Laplace Transform of the output Y(s). MATLAB aides
in this process by computing the partial fraction expansion of Y(s)
using the command residue. Store the numerator and denominator coefficients of
Y(s) in num and den, then type

[r,p,k] = residue(num,den)

The residues are stored in r, the corresponding poles are stored in p, and the gain is stored
in k.

Once the partial fraction expansion is known, an analytical expression for y(t) can be
computed by hand.

2- step

A numerical method to find the response of a system to a particular input is


available in MATLAB. First store the numerator and denominator of the transfer function
in num and den, respectively. To plot the step response, type

step(nums,dens)

hold on

step(nums,dens)

holdof

3- impulse

To plot the impulse response, type

impulse(num,den)

8
4- lsim

For the response to an arbitrary input , use the


command lsim. Create a vector t which contains the time values in seconds at
which you want MATLAB to calculate the response. Typically, this is done by entering

t = a:b:c;

where a is the starting time, b is the time step and c is the end time. For
smooth plots, choose b so that there are at least 300 elements in t (increase as
necessary).

Define the input x as a function of time, for example, a ramp is


defined as x = t. Then plot the response by typing

t = 0:0.01:5;

x=t

lsim(nums,dens,x,t);

To customize the commands, the time vector can be defined


explicitly and the step response can be saved to a vector. Simulating
the response for five to six time constants generally is sufficient to
show the behavior of the system. For a stable system, a time constant
is calculated as 1/Re(-p) where p is the pole that has the largest real
part (i.e., is closest to the origin).

Example:-

consider a transfer function defined by

The step response y is calculated and plotted from the following


commands:

num = 2;

den = [1 2];

9
step(num,den);

For the impulse response, simply replace the word step with impulse.

Note:-

For the response to an arbitrary input stored in x, type

y = lsim(num,den,x,t);

plot(t,y)

10
State Space Representation

Commands Covered: ss step lsim ss2tf tf2ss ss2ss

The standard state space representation is used in MATLAB, i.e.,

Where:-

x is nx1 vector, u is mx1, y is px1, A is nxn, B is nxm,


and C is pxn.

The response of a system to various inputs can be found using the same commands
that are used for transfer function representations: step, impulse, and lsim. The argument
list contains the A, B, C, and D matrices instead of the numerator and denominator
vectors.

Alternately, the system can be combined into one model using the command(ss)

sys = ss(A,B,C,D);

Then, sys can be used as an input argument for the other commands. For example, the
step response is obtained by typing either of the following commands:

[y,t,x] = step(A,B,C,D);

[y,t,x] = step(sys);

The states are stored in x, the outputs in y and the time vector, which
is automatically generated, is stored in t. The rows of x and y contain the
states and outputs for the time points in t. Each column of x represents a
state.

For example, to plot the second state versus time, type

11
plot(t,x(:,2))

To plot the impulse response, type

impulse(A,B,C,D)

Example:

Consider the following system:

 x 1    1  1  x1  1 1  u1   y1  1 0  x1  0 0  u1 
 x   6.5 0   x   1 0 u   y   0 1  x   0 0 u 
 2   2    2   2   2    2 

Obtain the unit-step response curves?

MATLAB program Result:

% Enter Matrices A,B, C and D


step-response plots: input = u1 (u2=0 )
0.5
A=[-1 -1;6.5 0];
)

0
T:O
o t(1
u

-0.5
B=[1 1; 1 0];
d
litue

2
m
A p

1
t
u(2

C=[1 0;0 1];


T:O
o

0
0 2 4 6 8 10 12
Time (sec)
D=[0 0;0 0];
step-response plots: input = u1 (u2=0 )
0.5
Subplot(2,1,1)
)

0
T:O
o t(1
u

-0.5
Step(A,B,C,D,1)
d
litue

2
m
A p

1
t
u(2

Grid
T:O
o

0
0 2 4 6 8 10 12
Time (sec)
Subplot(2,1,2)

Step(A,B,C,D,2)

Grid

Example:

Obtain the unit-impulse response of the following system:

12
 x 1   0 1   x1  0 x 
 x    1  1  x   1u y  1 0  1    0u
 2   2     x2 

A1=[0 1;-1 -1]; Result

B1=[0;1];
unit-impulse response
0.6

C1=[1 0]; 0.5

D1=[0]; 0.4

0.3

Amplitude
impulse(A1,B1,C1,D1)
0.2

hold on 0.1

0
step(A1,B1,C1,D)
-0.1
0 2 4 6 8 10 12

hold off Time (sec)

grid

title(‘unit-impulse response’)

Example

Obtain the unit-impulse response of the following system:

C ( s) 1
 2
R ( s ) s  0.2 s  1

num=[0 0 1]; Result

den=[1 0.2 1]; unit-impulse response


1

impulse(num,den) 0.8

0.6

0.4
Grid
Amplitude

0.2

title(‘unit-impulse response’) -0.2

-0.4

-0.6

-0.8
0 10 20 30 40 50 60
Time (sec)

13
Response of arbitrary input:

To find the response of an arbitrary input or to find the response to initial


conditions, use lsim

Define a time vector t and an input matrix u with the same number of
rows as in t and the number of columns equaling the number of inputs. An
optional argument is the initial condition vector x0. The command is then
given as

[y,x] = lsim(A,B,C,D,u,t,x0)

or [y,x] = lsim(sys,u,t,x0)

You can find the transfer function for a single-input/single-output (SISO)


system using the command:

[num,den] = ss2tf(A,B,C,D);

The numerator coefficients are stored in num and the denominator coefficients are stored
in den.

Given a transformation matrix P, the ss2ss function will perform the


similarity transform. Store the state space model in A, B, C and D and the
transformation matrix in P.

[Abar,Bbar,Cbar,Dbar]=ss2ss(A,B,C,D,P)

Or [Abar,Bbar,Cbar,Dbar] = ss2ss(sys,P)

performs the similarity transform z=Px resulting in a state space system that is defined as:

14
where

Example:
Y ( s) s
Given the following transfer function:-  find the state
U ( s ) ( s  10)( s  4 s  16)
2

space representation?

Y (s) s
Solution: put the transfer function in the following form:  3
U ( s ) s  14s  56 s  160
2

MATLAB Program Results

Num=[0 0 1 0]; A B
 14  56  160 1 C
Den=[1 14 56 160]; 1 0 0 0 0 1 0
0 1 0 0
[A,B,C,D]=tf2ss(num,den) D
0
The state space representation is:

 x 1   14  56  160  x1  1  x1 
 x    1 0 0   x2   0u y   0 1 0  x2    0u
 2 
 x 3   0 1 0   x3  0  x3 

15
Example
Obtain the transfer function of the system defined by the following state space equations:

 x 1   0 1 0   x1   0   x1 
 x    0 0 1   x 2    25 u y  1 0 0  x 2 
 2 
 x 3   5  25  5  x3   120  x3 

Solution:

MATLAB Program Result:

A=[0 1 0;0 0 1;-5 -25 -5]; Num= 0 0 25 5

B=[0;25;-120]; Den=1 5 25 5

C=[1 0 0]; The transfer function is:

D=[0]; Y (s) 25s  5


 3
U ( s ) s  5s 2  25s  5
[num,den]=ss2tf(A,B,C,D)

16
Example:
Consider the close loop system

C (s) 1
 2
R(s) s  s  1

Use Matlab to obtain unit ramp response of this system. For unit ramp input take,
R( s )  1 .
s2

Solution:

For this system we can write:

1 1 1 1
C ( s)   2
s  s 1 s
2 2
( s  s  1) s s

Solution
% the unit ramp response is obtained
% as the unit step response of G(s)/s
Result
num=[0 0 0 1];
unit ramp-response curve
7
den=[1 1 1 0];
6
% specify computing time
5

t=0:0.1:7;
input and output

c=step(num,den,t) 3

%plot ramp-response curve 2

1
u=t
0
0 1 2 3 4 5 6 7
plot(t,c,’o’,t,u,’-‘) t sec

17
grid

title(‘unit ramp-response curve’)

xlabel(‘t sec’)

ylabel(‘input and output’)

Example:
Using the lsim command, obtain the unit-ramp response of the following system:

C (s) 1
 2
R(s) s  s  1

num=[0 0 1]; Result

den=[1 1 1]; unit ramp-response curve


8

t=0:0.1:8; 7

r=t; 6

5
y=lsim(num,den,r,t)
input and output

plot(t,r,’-‘,t,y,’o’) 3

0
0 1 2 3 4 5 6 7 8
t sec

18
Example:

Consider the system:

 x 1   1 0.5  x1  0 x 
 x    1 0   x   1u y  1 0  1 
 2   2     x2 

Use MATLAB, obtain the response curve y(t) when the input u is given by:

1- u=unit-step input
2- u  e  t

MATLAB Program Result

t=0:0.1:12; A=[-1 0.5;-1 0];

B=[0;1]; C=[1 0]; D=[0]; unit step response


1.5
% for unit step input u=1(t)

y=step(A,B,C,D,1,t) 1
up
tut

% for the response to expontial input u=exp(-t)


o

0.5

u=exp(-t)
0
0 2 4 6 8 10 12
z=lsim(A,B,C,D,u,t) t sec
response to exponential input u=exp(-t)
plot(t,u,'-',t,z,'o',t,y,’x’); 1

0.5
u
op
tut

0
p
linu n
tady
sse
tm

-0.5
ia

0 2 4 6 8 10 12
pn
oet
n

t sec
x
E

19
Response to initial condition:

If the system is given in state space form then use the following command:

initial(A,B,C,D,[intial condition],t)

Example:

Consider the following system that is subjected to initial condition


  8 y  17 y
y   10 y  0.0
y (0)  2 y (0)  1
 y (0)  0.5

Obtain the response y(t) to the given initial conditions?

Solution:

By defining the state variables as


x1  y
x 2  y
x3  y

We obtain the following state-space representation for the system

 x 1   0 1 0   x1   x1 (0)   2   x1 
 x    0 0 1   x 2   x (0)   1  y  1 0 0  x 2 
 2   2   
 x 3  10  17  8  x3   x3 (0)  0.5  x3 

t=0:0.05:10; Result

A=[0 1 0;0 0 1;-10 -17 -8]; 2.5

B=[0;0;0]; 2

1.5

C=[1 0 0];
1

D=[0]; 0.5

y=initial(A,B,C,D,[2;1;0.5],t); 0
0 1 2 3 4 5 6 7 8 9 10

plot(t,y)

20
res=[t’ y]

Second order system

 n2
It is in the form: G ( s )  2 is called standard second order system. Given
s  2 n s   n2
 n and  we can use :-

[num,den]=ord2(  n ,  )

to get the transfer function of second order system

Example:

Consider  n  5 rad / sec and   0.4 use MATLAB to generate the standard second
order system, and to obtain unit step response?

MATLAB program Result

wn=5; num/den =
damping_ratio=0.4;
[num0,den]=ord2(wn,damping_ratio); 25
num=5^2*num0;
Printsys(num,den,’s’) --------------
% to obtain unit step response
step(num,den) s^2 + 4 s + 25
grid
title(‘Unit-step Response ‘)

21
Tutorial (5&6)

1-

Fig.1

For control system shown in fig-1 use MATLAB to find the overall transfer
function?

2- Find the equations of motion of the dynamic system shown in fig.2,then find
the transfer function X(s)/F(s) between displacement (x) and force (F).
assume M = 1000 kg (a Dodge Neon has a mass of about 1100 kg) b = 40 N*sec/m
µ=0.002 s/m g=9.81 m/s2. Create m-file to represent the transfer function
and to obtain matrices A, B, C, D of the state space form , hence write the
equations in state space form.

Fig-2

22
3- A unity-feedback system is characterized by the open loop transfer
function:

4500
G ( s) 
s ( s  361.2)

Plot step response of the system with a cascade controller D(s) with:

(a) D(s)=184.1
(b) D(s)=184.1 + 0.32s

(c) D(s)=14.728 + 147.28/s

Compare the responses for (a) and (b), and those for (a) and (c). comment
upon the effects of derivative and integral control action.

4- Consider the system described by:


y  3 y  2 y  u

Derive a state-space representation of the system.

5- Consider a system defined by the following state-space equation:

 x 1   4  1  x1  1 x 
 x    3  1  x   1u y  1 0  1 
 2   2     x2 

Obtain the transfer function of the system.

6- Consider the close loop system defined by :


C (s) a
 2
R ( s ) s  bs  a

Using a for loop write a MATLAB program to obtain unit step


response of this system for the following four cases:

Case1: a=1 b=0.6

Case2: a=4 b=2

Case3: a=16 b=5.6

23
Case4: a=36 b=9.6

7-

Consider the position control system shown in fig.3 write a MATLAB program
to obtain a unit-step response and a unit-ramp response of the system. Plots
curves x1(t) versus t, x2(t) versus t, x3(t) versus t, and e(t) versus t (where
e(t)=r(t)-x1(t)) for both the unit step response and the unit-ramp response.

8- Considered the close loop system defined by:

C (s) 2s  1
 2
R ( s ) s  2s  1

Where ζ=0.2, 0.4, 0.6, 0.8 and 1.0 using MATLAB plot a two-
dimensional diagram of unit-impulse response curves.

9- Consider differential equation system given by:


y  y  2 y  0 y (0)  0.1 y (0)  0.05

Obtain the response y(t) subject to the given initial condition

24

You might also like