<br><br><div class="gmail_quote">On Tue, May 17, 2011 at 8:03 AM, Wolfgang Kerzendorf <span dir="ltr"><<a href="mailto:wkerzendorf@googlemail.com">wkerzendorf@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<br>
<br>
The science package I'm using fits legendre polynomials to data. I heard<br>
it is more stable than the normal polynomials for a fit. Is there a<br>
polyfit for legendre polynomials? How do I do that with the new legendre<br>
polynomials module?<br>
<br></blockquote><div><br>In [1]: from numpy.polynomial import Legendre as L<br><br>In [2]: x = np.linspace(0,10)<br><br>In [3]: y = x*(x - 5)*(x - 8)<br><br>In [4]: p = L.fit(x, y, 3)<br><br>In [5]: plot(*p.linspace())<br>
Out[5]: [<matplotlib.lines.Line2D object at 0x2ea5590>]<br><br>In [6]: p.coef<br>Out[6]: <br>array([  1.66666667e+01,  -1.36479923e-14,   3.33333333e+01,<br>         5.00000000e+01])<br><br>In [7]: p.domain<br>Out[7]: array([  0.,  10.])<br>
<br>Note that the data is mapped to the domain [-1, 1] and then fitted with the Legendre polynomials. The 'p' polynomial keeps track of that. The Chebyshev polynomials probably work as well as the Legendre polynomials for most things. Plot produced is attached.<br>
<br>Chuck.<br></div></div>