|
5 | 5 |
|
6 | 6 | import unittest
|
7 | 7 | import numpy as np
|
8 |
| -from scipy.linalg import eigvals |
| 8 | +from numpy.linalg import solve |
| 9 | +from scipy.linalg import eigvals, block_diag |
9 | 10 | from control import matlab
|
10 |
| -from control.statesp import StateSpace, _convertToStateSpace |
| 11 | +from control.statesp import StateSpace, _convertToStateSpace,tf2ss |
11 | 12 | from control.xferfcn import TransferFunction
|
12 | 13 |
|
13 | 14 | class TestStateSpace(unittest.TestCase):
|
@@ -235,6 +236,51 @@ def test_dcgain(self):
|
235 | 236 | sys3 = StateSpace(0., 1., 1., 0.)
|
236 | 237 | np.testing.assert_equal(sys3.dcgain(), np.nan)
|
237 | 238 |
|
| 239 | + |
| 240 | + def test_scalarStaticGain(self): |
| 241 | + """Regression: can we create a scalar static gain?""" |
| 242 | + g1=StateSpace([],[],[],[2]) |
| 243 | + g2=StateSpace([],[],[],[3]) |
| 244 | + |
| 245 | + # make sure StateSpace internals, specifically ABC matrix |
| 246 | + # sizes, are OK for LTI operations |
| 247 | + g3 = g1*g2 |
| 248 | + self.assertEqual(6, g3.D[0,0]) |
| 249 | + g4 = g1+g2 |
| 250 | + self.assertEqual(5, g4.D[0,0]) |
| 251 | + g5 = g1.feedback(g2) |
| 252 | + self.assertAlmostEqual(2./7, g5.D[0,0]) |
| 253 | + g6 = g1.append(g2) |
| 254 | + np.testing.assert_array_equal(np.diag([2,3]),g6.D) |
| 255 | + |
| 256 | + def test_matrixStaticGain(self): |
| 257 | + """Regression: can we create a scalar static gain?""" |
| 258 | + d1 = np.matrix([[1,2,3],[4,5,6]]) |
| 259 | + d2 = np.matrix([[7,8],[9,10],[11,12]]) |
| 260 | + g1=StateSpace([],[],[],d1) |
| 261 | + g2=StateSpace([],[],[],d2) |
| 262 | + g3=StateSpace([],[],[],d2.T) |
| 263 | + |
| 264 | + h1 = g1*g2 |
| 265 | + np.testing.assert_array_equal(d1*d2, h1.D) |
| 266 | + h2 = g1+g3 |
| 267 | + np.testing.assert_array_equal(d1+d2.T, h2.D) |
| 268 | + h3 = g1.feedback(g2) |
| 269 | + np.testing.assert_array_almost_equal(solve(np.eye(2)+d1*d2,d1), h3.D) |
| 270 | + h4 = g1.append(g2) |
| 271 | + np.testing.assert_array_equal(block_diag(d1,d2),h4.D) |
| 272 | + |
| 273 | + |
| 274 | + def test_BadEmptyMatrices(self): |
| 275 | + """Mismatched ABCD matrices when some are empty""" |
| 276 | + self.assertRaises(ValueError,StateSpace, [1], [], [], [1]) |
| 277 | + self.assertRaises(ValueError,StateSpace, [1], [1], [], [1]) |
| <
6A4F
td data-grid-cell-id="diff-4c76080acbdea36493458693d93ec10e4e10b2e04ce01c56e8a81567cc1ea0d6-237-278-1" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">278
+ self.assertRaises(ValueError,StateSpace, [1], [], [1], [1]) |
| 279 | + self.assertRaises(ValueError,StateSpace, [], [1], [], [1]) |
| 280 | + self.assertRaises(ValueError,StateSpace, [], [1], [1], [1]) |
| 281 | + self.assertRaises(ValueError,StateSpace, [], [], [1], [1]) |
| 282 | + self.assertRaises(ValueError,StateSpace, [1], [1], [1], []) |
| 283 | + |
238 | 284 | class TestRss(unittest.TestCase):
|
239 | 285 | """These are tests for the proper functionality of statesp.rss."""
|
240 | 286 |
|
|
0 commit comments