# [Numpy-discussion] Generating special polynomials (Chebyshev, Hermite etc.)

Kumar Appaiah a.kumar@alumni.iitm.ac...
Fri Jun 14 20:02:39 CDT 2013

```On Fri, Jun 14, 2013 at 08:59:03PM -0400, Kumar Appaiah wrote:
> Dear Numpy Users,
>
> I am trying to find out a way by which I can easily generate the n-th
> order "special" polynomial, where "special" could refer to Hermite,
> Chebyshev etc. Numpy 1.7 introduces several methods for such
> polynomials, but I couldn't find a convenience function that gives me
> a polynomial directly based on degree. For instance, I'd like:
>
> hermite(3) to result in array([  0., -12.,   0.,   8.])
> hermite(6) to result in array([-120.,    0.,  720.,    0., -480.,    0.,   64.])
> and so on.
>
> The quickest way I could come up with for this is:
>
> def hermite(n):
>     if n <= 0:
>         return numpy.array([1.0])

I should technically raise a ValueError here if n is below 0, but I'll
do the right thing in a patch if I am asked for one.

>     coeff_polynomial = [0.0] * n
>     coeff_polynomial.extend([1])
>     return numpy.polynomial.hermite.herm2poly(coeff_polynomial)
>
> Now, if I am missing something, please let me know. If you think this
> is a useful feature, I volunteer to patch all the polynomial modules
> to generate such polynomials, if you could tell me appropriate
> function names for such convenience functions.

Thanks!

Kumar

--
Kumar Appaiah
```