0
|
1 |
#!/usr/bin/python
|
|
2 |
|
|
3 |
import pylab as pl
|
|
4 |
from polyfuncs import polsize
|
|
5 |
|
|
6 |
def clcoef(Q, degQ):
|
|
7 |
"""Function to clear zero leading coefficient matrices
|
|
8 |
of a Polynomial Matrix"""
|
|
9 |
rQ, cQ = polsize(Q, degQ)
|
|
10 |
|
|
11 |
if pl.allclose(Q, pl.zeros_like(Q)):
|
|
12 |
P = pl.zeros((rQ,cQ))
|
|
13 |
degP = 0
|
|
14 |
else:
|
|
15 |
P, degP = Q, degQ
|
|
16 |
rP, cP = rQ, cQ
|
|
17 |
j = degP
|
|
18 |
while j>=0:
|
|
19 |
if pl.norm(P[:, -cP:], pl.inf) < 1e-8 *pl.norm(P, pl.inf):
|
|
20 |
P = P[:, :j*cP]
|
|
21 |
degP = degP-1
|
|
22 |
else:
|
|
23 |
j=0
|
|
24 |
j -= 1
|
|
25 |
return P, degP
|
|
26 |
|
|
27 |
if __name__== "__main__":
|
|
28 |
s = """P = pl.array([[1, 2, 3, 4, 0, 0, 0, 0],
|
|
29 |
[9, 10, 11, 12, 0, 0, 0, 0],
|
|
30 |
[5, 6, 7, 8, 0, 0, 0, 0]])"""
|
|
31 |
t = """degP = 3"""
|
|
32 |
print s, t
|
|
33 |
exec(s)
|
|
34 |
exec(t)
|
|
35 |
|
|
36 |
print clcoef(P, degP)
|