I think I have found a small bug in signal.residue and may have found a simple solution. The problem seems to come from polydiv requiring that the numerator polynomial be of degree at most 1 less than the denominator. If I have a denominator of s^2+3*s+2, the numerator must have an s coefficient (even if that coefficient is 0) for signal.residue to work: In [75]: a Out[75]: array([1, 3, 2]) In [76]: signal.residue([1],a) --------------------------------------------------------------------------- exceptions.ValueError Traceback (most recent cal last) C:\Python24\<ipython console> C:\Python24\Lib\site-packages\scipy\signal\signaltools.py in residue(b, a, tol, rtype) 1054 1055 b,a = map(asarray,(b,a)) -> 1056 k,b = polydiv(b,a) 1057 p = roots(a) 1058 r = p*0.0 C:\Python24\Lib\site-packages\numpy\lib\polynomial.py in polydiv(u, v) 399 n = len(v) - 1 400 scale = 1. / v[0] --> 401 q = NX.zeros((m-n+1,), float) 402 r = u.copy() 403 for k in range(0, m-n+1): ValueError: negative dimensions are not allowed In [77]: signal.residue([0,1],a) Out[77]: (array([ 1.+0.j, -1.+0.j]), array([-1.+0.j, -2.+0.j]), array([], dtype=float64)) I think the simple solution is to replace line 1056 with these four lines: if len(b)<len(a): k=[] else: k,b = polydiv(b,a) where the last line above is the old line 1056. Basically, specify that there is no k term if the len of b is less than the len of a. Is this too simple? What do I do to actually submit this if it is the right solution? Ryan
On Tue, Feb 13, 2007 at 01:57:46PM -0600, Ryan Krauss wrote:
I think I have found a small bug in signal.residue and may have found a simple solution. The problem seems to come from polydiv requiring that the numerator polynomial be of degree at most 1 less than the denominator. If I have a denominator of s^2+3*s+2, the numerator must have an s coefficient (even if that coefficient is 0) for signal.residue to work:
In [75]: a Out[75]: array([1, 3, 2])
In [76]: signal.residue([1],a) --------------------------------------------------------------------------- exceptions.ValueError Traceback (most recent cal last) [snip] In [77]: signal.residue([0,1],a) Out[77]: (array([ 1.+0.j, -1.+0.j]), array([-1.+0.j, -2.+0.j]), array([], dtype=float64))
I think the simple solution is to replace line 1056 with these four lines: if len(b)<len(a): k=[] else: k,b = polydiv(b,a)
where the last line above is the old line 1056. Basically, specify that there is no k term if the len of b is less than the len of a.
Is this too simple? What do I do to actually submit this if it is the right solution?
I think you are right. This seems to be a bug. Please register and open a ticket at http://projects.scipy.org/scipy/scipy and state the problem and the specified solution. Thanks. Kumar -- Kumar Appaiah, 462, Jamuna Hostel, Indian Institute of Technology Madras, Chennai - 600 036
I will add this to my ticket, but there is also a problem with signal.residue when the first denominator coefficent isn't zero. I think I fixed it and I tested my fix against Maxima's partfrac command and it looks right. Bascially, I added the line rscale = a[0] near the beginning of the function and then change the last line to return return r/rscale, p, k This is (nearly) identical to the approach in residuez, so that and the agreement with Maxima give me a good feeling about it. The .wxm file I am attaching is a wxMaxima script for the test, but it requires a fairly recent version of wxMaxima (I am using 0.7.1). Ryan On 2/13/07, Kumar Appaiah <akumar@iitm.ac.in> wrote:
On Tue, Feb 13, 2007 at 01:57:46PM -0600, Ryan Krauss wrote:
I think I have found a small bug in signal.residue and may have found a simple solution. The problem seems to come from polydiv requiring that the numerator polynomial be of degree at most 1 less than the denominator. If I have a denominator of s^2+3*s+2, the numerator must have an s coefficient (even if that coefficient is 0) for signal.residue to work:
In [75]: a Out[75]: array([1, 3, 2])
In [76]: signal.residue([1],a) --------------------------------------------------------------------------- exceptions.ValueError Traceback (most recent cal last) [snip] In [77]: signal.residue([0,1],a) Out[77]: (array([ 1.+0.j, -1.+0.j]), array([-1.+0.j, -2.+0.j]), array([], dtype=float64))
I think the simple solution is to replace line 1056 with these four lines: if len(b)<len(a): k=[] else: k,b = polydiv(b,a)
where the last line above is the old line 1056. Basically, specify that there is no k term if the len of b is less than the len of a.
Is this too simple? What do I do to actually submit this if it is the right solution?
I think you are right. This seems to be a bug. Please register and open a ticket at http://projects.scipy.org/scipy/scipy and state the problem and the specified solution.
Thanks.
Kumar -- Kumar Appaiah, 462, Jamuna Hostel, Indian Institute of Technology Madras, Chennai - 600 036
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
participants (2)
-
Kumar Appaiah -
Ryan Krauss