@@ -14,7 +14,7 @@ class TestTf2SS(unittest.TestCase):
14
14
15
15
def test_td04ad_c (self ):
16
16
"""td04ad: Convert with 'C' option"""
17
-
17
+
18
18
# for octave:
19
19
"""
20
20
num = { [0.0, 0.0, 1.0 ], [ 1.0, 0.0 ];
@@ -24,36 +24,36 @@ def test_td04ad_c(self):
24
24
[1.0, 0.4, 3.0], [ 1.0, 1.0 ];
25
25
[1.0, 0.4, 3.0], [ 1.0, 1.0 ]};
26
26
"""
27
-
27
+
28
28
m = 2
29
29
p = 3
30
- d = 3
30
+ d = 3
31
31
num = np .array ([
32
32
[ [0.0 , 0.0 , 1.0 ], [1.0 , 0.0 , 0.0 ] ],
33
33
[ [3.0 , - 1.0 , 1.0 ], [0.0 , 1.0 , 0.0 ] ],
34
34
[ [0.0 , 0.0 , 1.0 ], [0.0 , 2.0 , 0.0 ] ] ])
35
-
35
+
36
36
numc = np .zeros ((max (1 , m , p ), max (1 , m , p ), d ), dtype = float )
37
37
numc [:p ,:m ,:] = num
38
38
denc = np .array (
39
39
[ [1.0 , 0.4 , 3.0 ], [ 1.0 , 1.0 , 0.0 ] ])
40
40
indc = np .array (
41
41
[ 2 , 1 ], dtype = int )
42
-
42
+
43
43
nref = 3
44
44
Aref = np .array ([ [- 1 , 0 , 0 ],
45
45
[ 0 , - 0.4 , - 0.3 ],
46
46
[ 0 , 10 , 0 ] ])
47
47
Bref = np .array ([ [0 , - 1 ],
48
- [1 , 0 ],
48
+ [1 , 0 ],
49
49
[0 , 0 ] ])
50
50
Cref = np .array ([ [1 , 0 , 0.1 ],
51
51
[- 1 , - 2.2 , - 0.8 ],
52
52
[- 2 , 0 , 0.1 ] ])
53
53
Dref = np .array ([ [0 , 1 ],
54
54
[3 , 0 ],
55
55
[0 , 0 ] ])
56
-
56
+
57
57
nr , A , B , C , D = transform .td04ad ('C' , m , p , indc , denc , numc )
58
58
#print('A=\n', A, '\nB=\n', B, '\nC=\n', C, '\nD=\n', D)
59
59
np .testing .assert_equal (nref , nr )
@@ -70,78 +70,78 @@ def test_td04ad_c(self):
70
70
71
71
def test_td04ad_r (self ):
72
72
"""td04ad: Convert with 'R' option"""
73
-
73
+
74
74
""" example program from
75
75
http://slicot.org/objects/software/shared/doc/TD04AD.html"""
76
-
76
+
77
77
m = 2
78
78
p = 2
79
79
rowcol = 'R'
80
80
index = [3 , 3 ]
81
81
dcoeff = np .array ([ [1.0 , 6.0 , 11.0 , 6.0 ], [1.0 , 6.0 , 11.0 , 6.0 ] ])
82
-
82
+
83
83
ucoeff = np .array ([ [[1.0 , 6.0 , 12.0 , 7.0 ], [0.0 , 1.0 , 4.0 , 3.0 ]],
84
- [[0.0 , 0.0 , 1.0 , 1.0 ], [1.0 , 8.0 , 20.0 , 15.0 ]] ])
85
-
84
+ [[0.0 , 0.0 , 1.0 , 1.0 ], [1.0 , 8.0 , 20.0 , 15.0 ]] ])
85
+
86
86
nref = 3
87
87
88
88
Aref = np .array ([ [ 0.5000 , - 0.8028 , 0.9387 ],
89
89
[ 4.4047 , - 2.3380 , 2.5076 ],
90
90
[- 5.5541 , 1.6872 , - 4.1620 ] ])
91
91
Bref = np .array ([ [- 0.2000 , - 1.2500 ],
92
92
[ 0.0000 , - 0.6097 ],
93
- [ 0.0000 , 2.2217 ] ])
93
+ [ 0.0000 , 2.2217 ] ])
94
94
Cref = np .array ([ [0.0000 , - 0.8679 , 0.2119 ],
95
95
[0.0000 , 0.0000 , 0.9002 ] ])
96
96
Dref = np .array ([ [1.0000 , 0.0000 ],
97
97
[0.0000 , 1.0000 ] ])
98
-
98
+
99
99
nr , A , B , C , D = transform .td04ad (rowcol , m , p , index , dcoeff , ucoeff )
100
100
#print('A=\n', A, '\nB=\n', B, '\nC=\n', C, '\nD=\n', D)
101
101
np .testing .assert_equal (nref , nr )
102
102
# order of states is not guaranteed, so we reorder the reference
103
103
rindex = np .flip (np .argsort (np .diag (A )))
104
104
Arref = Aref [rindex , :][:, rindex ]
105
- Brref = Bref [rindex , :]
106
- Crref = Cref [:, rindex ]
105
+ Brref = Bref [rindex , :]
106
+ Crref = Cref [:, rindex ]
107
107
Drref = Dref
108
108
np .testing .assert_array_almost_equal (A , Arref ,decimal = 4 )
109
109
np .testing .assert_array_almost_equal (B , Brref ,decimal = 4 )
110
110
np .testing .assert_array_almost_equal (C , Crref ,decimal = 4 )
111
- np .testing .assert_array_almost_equal (D , Drref ,decimal = 4 )
111
+ np .testing .assert_array_almost_equal (D , Drref ,decimal = 4 )
112
112
113
113
114
114
def test_staticgain (self ):
115
115
"""td04ad: Convert a transferfunction to SS with only static gain"""
116
-
116
+
117
117
# 2 inputs, 3 outputs? columns share a denominator
118
118
num = np .array ([ [ [1.0 ], [2.0 ] ],
119
119
[ [0.2 ], [4.3 ] ],
120
120
[ [1.2 ], [3.2 ] ] ])
121
121
p , m , d = num .shape
122
122
numc = np .zeros ((max (1 , m , p ), max (1 , m , p ), d ), dtype = float )
123
123
numc [:p ,:m ,:] = num
124
-
124
+
125
125
# denc, columns share a common denominator
126
126
denc = np .array ([ [ 1.0 ], [0.5 ] ])
127
127
Dc = (num / denc ).reshape ((3 ,2 ))
128
128
idxc = np .zeros ((2 ,), dtype = int )
129
-
129
+
130
130
# denr, rows share a common denominator
131
131
denr = np .array ([ [1.0 ], [0.5 ], [3.0 ] ])
132
132
idxr = np .zeros ((3 ,), dtype = int )
133
133
Dr = (num / denr [:, np .newaxis ]).reshape ((3 ,2 ))
134
134
135
135
# fails with:
136
136
# On entry to TB01XD parameter number 5 had an illegal value
137
-
137
+
138
138
n , A , B , C , D = transform .td04ad ('C' , 2 , 3 , idxc , denc , numc )
139
139
#print('A=\n', A, '\nB=\n', B, '\nC=\n', C, '\nD=\n', D)
140
140
self .assertEqual (A .shape , (0 ,0 ))
141
141
self .assertEqual (B .shape , (0 ,2 ))
142
142
self .assertEqual (C .shape , (3 ,0 ))
143
143
np .testing .assert_array_almost_equal (D , Dc )
144
-
144
+
145
145
n , A , B , C , D = transform .td04ad ('R' , 2 , 3 , idxr , denr , num )
146
146
#print('A=\n', A, '\nB=\n', B, '\nC=\n', C, '\nD=\n', D)
147
147
self .assertEqual (A .shape , (0 ,0 ))
@@ -187,7 +187,7 @@ def test_mixfeedthrough(self):
187
187
idxc = np .array ([ 1 , 0 ])
188
188
n , A , B , C , D = transform .td04ad ('C' , 2 , 2 , idxc , denc , numc )
189
189
np .testing .assert_array_almost_equal (D , np .array ([[0 , 0 ],[- 0.1 , 0 ]]))
190
-
190
+
191
191
def test_toandfrom (self ):
192
192
193
193
A = np .array ([[- 3.0 ]])
@@ -205,7 +205,7 @@ def test_toandfrom(self):
205
205
np .testing .assert_array_almost_equal (A , At )
206
206
207
207
def test_tfm2ss_6 (self ):
208
- """Python version of Fortran test program from
208
+ """Python version of Fortran test program from
209
209
-- Bug in TD04AD when ROWCOL='C' #6
210
210
This bug was fixed in PR #27"""
211
211
m = 1
@@ -219,6 +219,6 @@ def test_tfm2ss_6(self):
219
219
n , A , B , C , D = transform .td04ad ('C' , m , p , index , dcoeff , ucoeff )
220
220
self .assertEqual (n , 0 )
221
221
np .testing .assert_array_almost_equal (D , np .array ([[64 ]]))
222
-
222
+
223
223
if __name__ == "__main__" :
224
224
unittest .main ()
0 commit comments