|
| 1 | +""" |
| 2 | +Test ab01 wrappers |
| 3 | +
|
| 4 | +@author: bnavigator |
| 5 | +""" |
| 6 | + |
| 7 | +from numpy import array |
| 8 | +from numpy.testing import assert_allclose, assert_equal |
| 9 | +from scipy.linalg.lapack import dorgqr |
| 10 | + |
| 11 | +from slycot.analysis import ab01nd |
| 12 | + |
| 13 | + |
| 14 | +class Test_ab01nd: |
| 15 | + |
| 16 | + def test_ab01nd(self): |
| 17 | + """SLICOT doc example |
| 18 | +
|
| 19 | + http://slicot.org/objects/software/shared/doc/AB01ND.html""" |
| 20 | + |
| 21 | + # Example program data |
| 22 | + n = 3 |
| 23 | + m = 2 |
| 24 | + tol = 0.0 |
| 25 | + |
| 26 | + A = array([[-1., 0., 0.], |
| 27 | + [-2., -2., -2.], |
| 28 | + [-1., 0., -3.]]) |
| 29 | + B = array([[1., 0.], |
| 30 | + [0, 2.], |
| 31 | + [0., 1.]]) |
| 32 | + |
| 33 | + for jobz in ['N', 'I', 'F']: |
| 34 | + Ac, Bc, ncont, indcon, nblk, Z, tau = ab01nd(n, m, A, B, |
| 35 | + jobz=jobz, tol=tol) |
| 36 | + |
| 37 | + # The transformed state dynamics matrix of a controllable realization |
| 38 | + assert_allclose(Ac[:ncont, :ncont], array([[-3.0000, 2.2361], |
| 39 | + [ 0.0000, -1.0000]]), |
| 40 | + atol=0.0001) |
| 41 | + |
| 42 | + # and the dimensions of its diagonal blocks are |
| 43 | + assert_equal(nblk[:indcon], array([2])) |
| 44 | + |
| 45 | + # The transformed input/state matrix B of a controllable realization |
| 46 | + assert_allclose(Bc[:ncont, :],array([[ 0.0000, -2.2361], |
| 47 | + [ 1.0000, 0.0000]]), |
| 48 | + atol=0.0001) |
| 49 | + |
| 50 | + # The controllability index of the transformed system representation |
| 51 | + assert indcon == 1 |
| 52 | + |
| 53 | + if jobz == 'N': |
| 54 | + assert Z is None |
| 55 | + continue |
| 56 | + elif jobz == 'I': |
| 57 | + Z_ = Z |
| 58 | + elif jobz == 'F': |
| 59 | + Z_, _, info = dorgqr(Z, tau) |
| 60 | + assert info == 0 |
| 61 | + |
| 62 | + # The similarity transformation matrix Z |
| 63 | + assert_allclose(Z_, array([[ 0.0000, 1.0000, 0.0000], |
| 64 | + [-0.8944, 0.0000, -0.4472], |
| 65 | + [-0.4472, 0.0000, 0.8944]]), |
| 66 | + atol=0.0001) |
| 67 | + |
0 commit comments