コード例 #1
0
 def testBalredMatchDC(self, matarrayin):
     # controlable canonical realization computed in matlab for the transfer
     # function:
     # num = [1 11 45 32], den = [1 15 60 200 60]
     A = matarrayin(
         [[-15., -7.5, -6.25, -1.875],
          [8., 0., 0., 0.],
          [0., 4., 0., 0.],
          [0., 0., 1., 0.]])
     B = matarrayin([[2.], [0.], [0.], [0.]])
     C = matarrayin([[0.5, 0.6875, 0.7031, 0.5]])
     D = matarrayin([[0.]])
     sys = StateSpace(A, B, C, D)
     orders = 2
     rsys = balred(sys,orders,method='matchdc')
     Artrue = np.array(
         [[-4.43094773, -4.55232904],
          [-4.55232904, -5.36195206]])
     Brtrue = np.array([[1.36235673], [1.03114388]])
     Crtrue = np.array([[1.36235673, 1.03114388]])
     Drtrue = np.array([[-0.08383902]])
     np.testing.assert_array_almost_equal(rsys.A, Artrue, decimal=2)
     np.testing.assert_array_almost_equal(rsys.B, Brtrue, decimal=4)
     np.testing.assert_array_almost_equal(rsys.C, Crtrue, decimal=4)
     np.testing.assert_array_almost_equal(rsys.D, Drtrue, decimal=4)
コード例 #2
0
 def testBalredTruncate(self, matarrayin):
     # controlable canonical realization computed in matlab for the transfer
     # function:
     # num = [1 11 45 32], den = [1 15 60 200 60]
     A = matarrayin([[-15., -7.5, -6.25, -1.875], [8., 0., 0., 0.],
                     [0., 4., 0., 0.], [0., 0., 1., 0.]])
     B = matarrayin([[2.], [0.], [0.], [0.]])
     C = matarrayin([[0.5, 0.6875, 0.7031, 0.5]])
     D = matarrayin([[0.]])
     sys = StateSpace(A, B, C, D)
     orders = 2
     rsys = balred(sys, orders, method='truncate')
     Artrue = np.array([[-1.958, -1.194], [-1.194, -0.8344]])
     Brtrue = np.array([[0.9057], [0.4068]])
     Crtrue = np.array([[0.9057, 0.4068]])
     Drtrue = np.array([[0.]])
     np.testing.assert_array_almost_equal(rsys.A, Artrue, decimal=2)
     np.testing.assert_array_almost_equal(rsys.B, Brtrue, decimal=4)
     np.testing.assert_array_almost_equal(rsys.C, Crtrue, decimal=4)
     np.testing.assert_array_almost_equal(rsys.D, Drtrue, decimal=4)
コード例 #3
0
plt.close('all')

# controllable canonical realization computed in MATLAB for the
# transfer function: num = [1 11 45 32], den = [1 15 60 200 60]
A = np.array([[-15., -7.5, -6.25, -1.875], [8., 0., 0., 0.], [0., 4., 0., 0.],
              [0., 0., 1., 0.]])
B = np.array([[2.], [0.], [0.], [0.]])
C = np.array([[0.5, 0.6875, 0.7031, 0.5]])
D = np.array([[0.]])

# The full system
fsys = StateSpace(A, B, C, D)

# The reduced system, truncating the order by 1
n = 3
rsys = msimp.balred(fsys, n, method='truncate')

# Comparison of the step responses of the full and reduced systems
plt.figure(1)
y, t = mt.step(fsys)
yr, tr = mt.step(rsys)
plt.plot(t.T, y.T)
plt.plot(tr.T, yr.T)

# Repeat balanced reduction, now with 100-dimensional random state space
sysrand = mt.rss(100, 1, 1)
rsysrand = msimp.balred(sysrand, 10, method='truncate')

# Comparison of the impulse responses of the full and reduced random systems
plt.figure(2)
yrand, trand = mt.impulse(sysrand)
コード例 #4
0
#controlable canonical realization computed in matlab for the transfer function:
# num = [1 11 45 32], den = [1 15 60 200 60]
A = np.matrix('-15., -7.5, -6.25, -1.875; \
8., 0., 0., 0.; \
0., 4., 0., 0.; \
0., 0., 1., 0.')
B = np.matrix('2.; 0.; 0.; 0.')
C = np.matrix('0.5, 0.6875, 0.7031, 0.5')
D = np.matrix('0.')

# The full system
fsys = StateSpace(A,B,C,D)
# The reduced system, truncating the order by 1
ord = 3
rsys = msimp.balred(fsys,ord, method = 'truncate')

# Comparison of the step responses of the full and reduced systems
plt.figure(1)
y, t = mt.step(fsys)
yr, tr = mt.step(rsys)
plt.plot(t.T, y.T)
plt.plot(tr.T, yr.T)

# Repeat balanced reduction, now with 100-dimensional random state space
sysrand = mt.rss(100, 1, 1)
rsysrand = msimp.balred(sysrand,10,method ='truncate')

# Comparison of the impulse responses of the full and reduced random systems
plt.figure(2)
yrand, trand = mt.impulse(sysrand)