We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent cc23b83 commit ccebddcCopy full SHA for ccebddc
scratch/minreal.py
@@ -0,0 +1,34 @@
1
+from control import TransferFunction
2
+from sys import float_info
3
+import numpy as np
4
+
5
+s = TransferFunction([1, 0], [1])
6
7
+h = (s+1)*(s+2)/(s+2)/(s**2+s+1)
8
+tol = None
9
10
+sqrt_eps = np.sqrt(float_info.epsilon)
11
12
+for i in range(h.inputs):
13
+ for j in range(h.outputs):
14
+ newzeros = []
15
+ zeros = np.roots(h.num[i][j])
16
+ poles = np.roots(h.den[i][j])
17
+ # check all zeros
18
+ for z in zeros:
19
+ t = tol or \
20
+ 1000 * max(float_info.epsilon, abs(z) * sqrt_eps)
21
+ idx = np.where(abs(z - poles) < t)[0]
22
+ print idx
23
+ if len(idx):
24
+ print "found match %s" % (abs(z - poles) < t)
25
+ poles = np.delete(poles, idx[0])
26
+ else:
27
+ newzeros.append(z)
28
+ print newzeros
29
+ print poles
30
31
32
33
34
0 commit comments