Repository navigation
Expand file tree
/
Copy pathtest_ab08n.py
More file actions
78 lines (65 loc) · 2.91 KB
/
Copy pathtest_ab08n.py
File metadata and controls
78 lines (65 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# ===================================================
# ab08n* tests
import numpy as np
from numpy.testing import assert_allclose, assert_equal
from scipy.linalg import eig
from slycot import analysis
class Test_ab08nX:
""" Test regular pencil construction ab08nX with input parameters
according to example in documentation """
A = np.diag([1., 1., 3., -4., -1., 3.])
B = np.array([[ 0., -1.],
[-1., 0.],
[ 1., -1.],
[ 0., 0.],
[ 0., 1.],
[-1., -1.]])
C = np.array([[1., 0., 0., 1., 0., 0.],
[0., 1., 0., 1., 0., 1.],
[0., 0., 1., 0., 0., 1.]])
D = np.zeros((3, 2))
def normalize(self, w):
wi = np.flip(np.argsort(np.abs(w)))
wn = w[wi]/w[wi[0]]
return wn
def ab08nX(self, ab08fun, A, B, C, D):
n = 6
m = 2
p = 3
# Check the observability and compute the ordered set of
# the observability indices (call the routine with M = 0).
out = ab08fun(n, 0, p, A, B, C, D)
nu, rank, dinfz, nkror, nkrol, infz, kronr, kronl, Af, Bf = out[:10]
assert_equal(kronl[:nkrol], np.array([1, 2, 2]))
assert_equal(n-nu, 5)
assert_allclose(Af[:nu, :nu], np.array([[-1.]]))
# Check the controllability and compute the ordered set of
# the controllability indices (call the routine with P = 0)
out = ab08fun(n, m, 0, A, B, C, D)
nu, rank, dinfz, nkror, nkrol, infz, kronr, kronl, Af, Bf = out[:10]
assert_equal(kronr[:nkror], np.array([2, 3]))
assert_equal(n-nu, 5)
assert_allclose(Af[:nu, :nu], np.array([[-4.]]))
# Compute the structural invariants of the given system.
out = ab08fun(n, m, p, A, B, C, D)
nu, rank, dinfz, nkror, nkrol, infz, kronr, kronl, Af, Bf = out[:10]
assert_equal(nu, 2)
# Compute the invariant zeros of the given system.
w = eig(Af[:nu, :nu], Bf[:nu, :nu], left=False, right=False)
w_ref = np.array([-2., 1.])
assert_allclose(self.normalize(w), self.normalize(w_ref))
# the examples value of infinite zeros does not match the code
# compare output formats to given strings
# assert_equal(sum(infz[:dinfz]), 2)
# assert_equal([[infz[i], i+1] for i in range(dinfz)], [[1, 1]])
assert_equal(nkror, 0)
assert_equal(nkrol, 1)
assert_equal(kronl[:nkrol], np.array([2]))
def test_ab08nd(self):
"Test Construct regular pencil for real matrices"
self.ab08nX(analysis.ab08nd, self.A, self.B, self.C, self.D)
def test_ab08nz(self):
"Test Construct regular pencil for (pseudo) complex matrices"
Ac, Bc, Cc, Dc = [M.astype(np.complex128) for M in [self.A, self.B,
self.C, self.D]]
self.ab08nX(analysis.ab08nz, Ac, Bc, Cc, Dc)