# [SciPy-user] Interpolation polynomials

Matthieu Brucher matthieu.brucher@gmail....
Wed Aug 22 08:04:52 CDT 2007

```>
> def gen_lagrange_polys(points):
>     def make_poly(int_pt, zero_pts):
>         return N.poly1d(N.poly(zero_pts)/N.multiply.reduce(
>             [int_pt - p for p in zero_pts]))
>     return [make_poly(pi, [pz for pz in points if pz != pi]) for pi in
> points]

I suppose you can do better this way (not sure though) :
def make_poly(int_pt, zero_pts):
p = N.poly(zero_pts)
return N.poly1d(N.polydiv(p, N.polyval(int_pt)))

This gives the correct scaling, which means N.poly is exactly equivalent to
> the product of (x - Zi) where Zi are the desired zeros. The problem I have
> is that because the polynomials are represented i.t.o. monomial
> coefficients, they don't evaluate to exactly zero at Zi which is quite
> important for what I want to do.
>
> Does scipy/numpy have an alternate
> polynomial representation based on the product of zeros rather than
> monomial coefficients? If not, is there a better way to do this than
> generating code to do this?

The poly1d returns a new object with the roots, but the value is computed
with polyval :( I don't know if there is another fnction to evaluate a
polynomial.

Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070822/98d7a4ad/attachment.html
```

More information about the SciPy-user mailing list