Intro2MatlabCh2 - Hadi Saadat PDF
Intro2MatlabCh2 - Hadi Saadat PDF
Go to Chapter 1
CHAPTER
2
MATHEMATICAL
MODELS OF
SYSTEMS
Fehlberg second and third order pair of formulas for medium accuracy and fourth and
fifth order pair for high accuracy. The nth-order differential equation must be trans-
formed into n first order differential equations and must be placed in an M-file that
returns the state derivatives of the equations. The following examples demonstrate the
use of these functions.
Example 2.1
Consider the simple mechanical system of Figure 2.1. Three forces influence the mo-
tion of the mass, namely, the applied force, the frictional force, and the spring force.
... ... ... ... ... ... ... ... ... ... ... ...
.... .... .... .... .... .... .... .... .... .... .... ....
........
...
..
.
.... ..
........... ..............
.... .. .......... .........
.. .. ..
K B
... . .
. . .. .. ...
.......................... ..
.. ...
... ............................
.
... .
........... ................
.... ..
. ..
..
........
...
.
........
...
M
()
.
...
.
x t
..........
...
()
.
f t
FIGURE 2.1
Mechanical translational system.
d2 x
M
dt2
+ B dx
dt
+ Kx = f (t)
Let x1 = x and x2 = dxdt , then
dx1
dt
= x2
dx2
dt
= M1 [f (t) Bx2 Kx1 ]
With the system initially at rest, a force of 25 Newton is applied at time t = 0. Assume
that the mass M Kg, frictional coefficient B N/m/sec., and the spring =1 =5
constant K = 25
N/m. The above equations are defined in an M-file mechsys.m as
follows:
The following M-file, ch2ex01.m uses ode23 to simulate the system over an
interval of 0 to 3 sec., with zero initial conditions.
2.2. Numerical Solution 53
displacement
1
velocity
0
1
0 0.5 1 1.5 2 2.5 3
Time sec.
velocity versus displacement
3
2
velocity
1
0 0.2 0.4 0.6 0.8 1 1.2 1.4
displacement
FIGURE 2.2
Response of the mechanical system of Example 2.1.
d= x(:,1); v = x(:,2);
subplot(2,1,2), plot(d, v)
title('velocity versus displacement ')
xlabel('displacement')
ylabel('velocity')
subplot(111)
Example 2.2
The circuit elements in Figure 2.3 are R : ,L H, and C : F, the initial = 1 4
= 2 = 0 32
inductor current is zero, and the initial capacitor voltage is .5 volts. A step voltage of
1 volt is applied at time t =0
. Determine i t and v t over the range < t < () () 0 15
sec. Also, obtain a plot of current versus capacitor voltage.
.... ...
........ 1:4
2H
+
.... .....
.... ....... ... ... ... ... ....................................
... ...................................................... ... ... ... ..
.. .. .. ..
Vs =1V + 0:32 F vc t ()
FIGURE 2.3
RLC circuit for time-domain solution example.
Applying KVL
Ri + L dt
di
+ vc = Vs
and
i = C dvdtc
Let
x1 = vc
and
x2 =i
then
_ = C1 x2
x1
_ = L1 (Vs
and
x2 x1 Rx2 )
The above equations are defined in an M-file electsys.m as follows:
function xdot = electsys(t,x);
% returns the state derivatives
V = 1; % Step input
R =1.4; L = 2; C = 0.32;
xdot = [x(2)/C ; 1/L*( V - x(1) - R*x(2) ) ];
2.2. Numerical Solution 55
0.5
Current
0
0.5
0 5 10 15
Time sec.
Current versus capacitor voltage
0.15
0.1
Current
0.05
0.05
0.1
0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3
Capacitor voltage
FIGURE 2.4
Response of the series RLC circuit of Example 2.2.
The following M-file, ch2ex02.m, uses ode23 to simulate the system over an interval
of 0 to 15 sec.
Example 2.3
Consider the simple pendulum illustrated in Figure 2.5 where a weight of W mg kg =
is hung from a support by a weightless rod of length L meters. While usually approx-
imated by a linear differential equation, the system really is nonlinear and includes
viscous damping with a damping coefficient of B kg/m/sec.
.
..........
....
....
....
.
...
......
....
......
....
....
.... ....
....
.... ..... .
.... ............. .
L . ....
....
.... .
.
.....
..
{
... ..
.
... ... .
.... .... ....
..
..... .
......
.. ..
.... .... ...
.....
. .....
.
. .. .. ..
.......... ...
....
..... .... .
..
. ....
..
.....
.
...
..
...
.... .
....
...
..
......... ....
... ..
mg
.
FIGURE 2.5
Pendulum oscillator.
If in radians is the angle of deflection of the rod, the velocity of the weight
at the end will be L and the tangential force acting to increase the angle can be _
written:
FT = W sin BL _
From Newtons law
FT = mL
Combining the two equations for the force, we get:
_=
x2
B
m
x2
W
mL
sin x1
The above equations are defined in an M-file pendulum.m as follows:
2.3. Nonlinear Systems 57
4
0 1 2 3 4 5
Time sec.
Phase plane plot of pendulum
4
Angular velocity
4
1 0.5 0 0.5 1
Position Rad.
FIGURE 2.6
Response of the pendulum described in Example 2.3.
2.4 Linearization
Nonlinear systems are often linearized assuming small signal conditions. The nonlin-
ear differential equation describing the motion of the pendulum in Example 2.3 can be
= +
linearized if the initial angle of deflection is small. When 0 , the pendulum
equation can be written as
For small assuming sin ' 0 , cos ' 1 and expanding the sine term
yields the following linear differential equation.
mL + BL_ + W = 0 (2.2)
It is left as an exercise to show that the above linearized equation will yield
approximately the same response as long as is small.
Transfer function:
s + 4
--------------
s^2 + 2 s + 10
Example 2.3
Find the roots of the following polynomial.
Example 2.5
Determine the roots of the characteristic equation of the following matrix.
2
0 1 13
A=4 6 11 65
6 11 5
The characteristic equation of the matrix is found by poly, and the roots of this
equation are found by roots.
A = [ 0 1 -1; -6 -11 6; -6 -11 5];
p = poly(A)
r = roots(p)
The result is as follows:
p =
1.0000 6.0000 11.0000 6.0000
r = -3.0000
-2.0000
-1.0000
Example 2.6
Find the poles and zeros of the following transfer function:
num = [ 1 11 30 0];
den = [ 1 9 45 87 50];
[z,p,k] = tf2zp(num,den)
The zeros, poles and gains are:
z =
-6.0000
-5.0000
0.0000
inf
p =
-3.0000 +4.0000i
-3.0000 -4.0000i
-2.0000
-1.0000
k =
1
2.5. Transfer Function 61
Therefore
(s + 5)(s + 6)
( ) = (s + 1)(s + s2)(
H s
s + 3 + j 4)(s + 3 j 4)
zp2tf forms transfer function polynomials from the zeros, poles and gains of
systems.
Example 2.7
6 50
A system has zeros at , , , poles at 3j 4 , 2, 1, and a gain of 1. Determine
the system transfer function.
num =
1 11 30 0
den =
1 9 45 87 50
( ) = bm sm + bm 1 sm 1 + + b1 s + b0
P s
( ) ansn + an 1sn 1 + + a1 s + a0
Q s
(2.3)
Example 2.8
Determine the partial fraction expansion for
num = [ 2 0 9 1];
den = [ 1 1 4 4];
[res, poles ,k] = residue(num, den)
res =
0.0000 -0.2500i
0.0000 +0.2500i
-2.0000
poles =
0.0000 +2.0000i
0.0000 -2.0000i
-1.0000
K =
2.0000