Ñò ]ÐKc@ s dZddklZddddddd d d d d dddddddgZddkZddkiZddk Z ddk Z ddk l Z e i ZeiddgƒZeidgƒZeidgƒZeiddgƒZd„Zd„Zd„Zd„Zd„Zd„Zdd„Zddd „Zdgddd!„Zd"„Zd#„Zde d$„Z!d%„Z"e i#d&dd'd(d)d*ƒdUdS(+s<Functions for dealing with polynomials. This module provides a number of functions that are useful in dealing with polynomials as well as a ``Polynomial`` class that encapsuletes the usual arithmetic operations. All arrays of polynomial coefficients are assumed to be ordered from low to high degree, thus `array([1,2,3])` will be treated as the polynomial ``1 + 2*x + 3*x**2`` Constants --------- - polydomain -- Polynomial default domain - polyzero -- Polynomial that evaluates to 0. - polyone -- Polynomial that evaluates to 1. - polyx -- Polynomial of the identity map (x). Arithmetic ---------- - polyadd -- add a polynomial to another. - polysub -- subtract a polynomial from another. - polymul -- multiply a polynomial by another - polydiv -- divide one polynomial by another. - polyval -- evaluate a polynomial at given points. Calculus -------- - polyder -- differentiate a polynomial. - polyint -- integrate a polynomial. Misc Functions -------------- - polyfromroots -- create a polynomial with specified roots. - polyroots -- find the roots of a polynomial. - polyvander -- Vandermode like matrix for powers. - polyfit -- least squares fit returning a polynomial. - polytrim -- trim leading coefficients from a polynomial. - polyline -- Polynomial of given straight line Classes ------- - Polynomial -- polynomial class. iÿÿÿÿ(tdivisiontpolyzerotpolyonetpolyxt polydomaintpolylinetpolyaddtpolysubtpolymultpolydivtpolyvaltpolydertpolyintt polyfromrootst polyvandertpolyfittpolytrimt polyrootst PolynomialN(t polytemplateiicC s5|djoti||gƒSti|gƒSdS(s2Polynomial whose graph is a straight line. The line has the formula ``off + scl*x`` Parameters: ----------- off, scl : scalars The specified line is given by ``off + scl*x``. Returns: -------- series : 1d ndarray The polynomial equal to ``off + scl*x``. iN(tnptarray(tofftscl((sA/usr/lib64/python2.6/site-packages/numpy/polynomial/polynomial.pyROs c C s¶t|ƒdjotidƒSti|gdtƒ\}tit|ƒdd|iƒ}d|d>> import warnings >>> warnings.simplefilter('ignore', RankWarning) See Also -------- polyval : Evaluates a polynomial. polyvander : Vandermonde matrix for powers. chebfit : least squares fit using Chebyshev series. linalg.lstsq : Computes a least-squares fit from the matrix. scipy.interpolate.UnivariateSpline : Computes spline fits. Notes ----- The solution are the coefficients ``c[i]`` of the polynomial ``P(x)`` that minimizes the squared error ``E = \sum_j |y_j - P(x_j)|^2``. This problem is solved by setting up as the overdetermined matrix equation ``V(x)*c = y``, where ``V`` is the Vandermonde matrix of `x`, the elements of ``c`` are the coefficients to be solved for, and the elements of `y` are the observed values. This equation is then solved using the singular value decomposition of ``V``. If some of the singular values of ``V`` are so small that they are neglected, then a `RankWarning` will be issued. This means that the coeficient values may be poorly determined. Using a lower order fit will usually get rid of the warning. The `rcond` parameter can also be set to a value smaller than its default, but the resulting fit may be spurious and have large contributions from roundoff error. Fits using double precision and polynomials tend to fail at about degree 20. Fits using Chebyshev series are generally better conditioned, but much can still depend on the distribution of the sample points and the smoothness of the data. If the quality of the fit is inadequate splines may be a good alternative. References ---------- .. [1] Wikipedia, "Curve fitting", http://en.wikipedia.org/wiki/Curve_fitting Examples -------- igisexpected deg >= 0sexpected 1D vector for xsexpected non-empty vector for xisexpected 1D or 2D array for ys$expected x and y to have same lengths!The fit may be poorly conditionedN(R/RRCR0tndimt TypeErrorR$RFR1RtfinfoRtepsRtsqrttsumtlatlstsqtTtwarningstwarnRt RankWarning( RDtyRGtrcondtfullRHtARtctresidstranktstmsg((sA/usr/lib64/python2.6/site-packages/numpy/polynomial/polynomial.pyRs2`        #%cC sýti|gƒ\}t|ƒdjotigd|iƒSt|ƒdjoti|d |dgƒSt|ƒd}ti||fd|iƒ}d|i|d|d…<|dd…dfc|d |d8*s:       ! " &  1 21D 2 … (