[Numpy-discussion] poly class question

josef.pktd@gmai... josef.pktd@gmai...
Fri Oct 2 13:30:57 CDT 2009

```On Fri, Oct 2, 2009 at 2:09 PM, Charles R Harris
<charlesr.harris@gmail.com> wrote:
>
>
> On Fri, Oct 2, 2009 at 11:35 AM, Charles R Harris
> <charlesr.harris@gmail.com> wrote:
>>
>>
>> On Fri, Oct 2, 2009 at 11:33 AM, Charles R Harris
>> <charlesr.harris@gmail.com> wrote:
>>>
>>>
>>> On Fri, Oct 2, 2009 at 11:30 AM, Charles R Harris
>>> <charlesr.harris@gmail.com> wrote:
>>>>
>>>>
>>>> On Fri, Oct 2, 2009 at 11:08 AM, <josef.pktd@gmail.com> wrote:
>>>>>
>>>>> Is there a way in numpy (or scipy) to get an infinite expansion for
>>>>> the inverse of a polynomial (for a finite number of terms)
>>>>>
>>>>> np.poly1d([ -0.8, 1])**(-1)
>>>>>
>>>>> application for example the MA representation of an AR(1)
>>>>>
>>>>
>>>> Hmm, I've been working on a chebyshev class and division of a scalar by
>>>> a chebyshev series is
>>>> expressly forbidden, but it could be included if a good interface is
>>>> proposed. Same would go for polynomials.
>>>
>>> In fact is isn't hard to get, for poly1d you should be able to multiply
>>> the series by a power of x to shift it left, then divide.
>>>
>>
>> That is, divide a power of x by the polynomial.
>>
>
> You will also need to reverse the denominator coefficients...Chuck

That's the hint I needed. However the polynomial coefficients are then
reversed and not consistent with other polynomial operations, aren't
they?

>>> from scipy.signal import lfilter

>>> (np.poly1d([1, 0])**10)/np.poly1d([1, -0.8])
(poly1d([ 1.        ,  0.8       ,  0.64      ,  0.512     ,  0.4096    ,
0.32768   ,  0.262144  ,  0.2097152 ,  0.16777216,
0.13421773]), poly1d([ 0.10737418]))

>>> lfilter([1], [1,-0.8], [1] + [0]*9)
array([ 1.        ,  0.8       ,  0.64      ,  0.512     ,  0.4096    ,
0.32768   ,  0.262144  ,  0.2097152 ,  0.16777216,  0.13421773])

>>> (np.poly1d([1, 0])**10)/np.poly1d([1, -0.8, 0.2])
(poly1d([ 1.        ,  0.8       ,  0.44      ,  0.192     ,  0.0656    ,
0.01408   , -0.001856  , -0.0043008 , -0.00306944]),
poly1d([-0.00159539,  0.00061389]))
>>> lfilter([1], [1,-0.8, 0.2], [1] + [0]*9)
array([ 1.        ,  0.8       ,  0.44      ,  0.192     ,  0.0656    ,
0.01408   , -0.001856  , -0.0043008 , -0.00306944, -0.00159539])

What I meant initally doesn't necessarily mean division of a scalar.

>>> np.poly1d([1])/np.poly1d([-0.8, 1])
(poly1d([ 0.]), poly1d([ 1.]))

I didn't find any polynomial division that does the expansion of the
remainder. The same problem, I think is inherited, by the
scipy.signal.lti, and it took me a while to find the usefulness of
lfilter in this case.

If it were possible to extend the methods for the polynomial class to
do a longer expansions, it would make them more useful for arma and
lti.

(in some areas, I'm still trying to figure out whether some
functionality is just hidden to me, or actually a limitation of the
implementation or a missing feature.)

Thanks,

Josef

>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
```