# [SciPy-user] problem with signal.residue

Ryan Krauss ryanlists@gmail....
Tue Feb 13 13:57:46 CST 2007

```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
```