Ñò
,ÏÐKc           @   s   d  Z  d d k l Z d d d d d d d	 d
 d d d d d d d d d d g Z d d k Z d d k i Z d d k	 Z
 d d k Z d d k l Z e
 i Z e i d d g ƒ Z e i d g ƒ Z e i d g ƒ Z e i d d g ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d d d  „ Z d g  d d d! „ Z d" „  Z d# „  Z d e  d$ „ Z! d% „  Z" e i# d& d d' d( d) d* ƒ d Ud S(+   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ÿÿÿÿ(   t   divisiont   polyzerot   polyonet   polyxt
   polydomaint   polylinet   polyaddt   polysubt   polymult   polydivt   polyvalt   polydert   polyintt   polyfromrootst
   polyvandert   polyfitt   polytrimt	   polyrootst
   PolynomialN(   t   polytemplatei   i    c         C   s5   | d j o t  i |  | g ƒ St  i |  g ƒ Sd S(   s2  Polynomial 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``.

    i    N(   t   npt   array(   t   offt   scl(    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   O   s    c      
   C   s¶   t  |  ƒ d j o t i d ƒ St i |  g d t ƒ\ }  t i t  |  ƒ d d |  i ƒ} d | d <xC t t  |  ƒ ƒ D]/ } | | d d c !|  | | | d 8+q{ W| Sd S(   sÛ  Generate a polynomial with given roots.

    Generate a polynomial whose roots are given by `roots`. The resulting
    series is the produet `(x - roots[0])*(x - roots[1])*...`

    Inputs
    ------
    roots : array_like
        1-d array containing the roots in sorted order.

    Returns
    -------
    series : ndarray
        1-d array containing the coefficients of the Chebeshev series
        ordered from low to high.

    See Also
    --------
    polyroots

    i    i   t   trimt   dtypeiÿÿÿÿi   N(	   t   lenR   t   onest   put	   as_seriest   Falset   zerosR   t   range(   t   rootst   prdt   i(    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   d   s    "
 -c         C   sw   t  i |  | g ƒ \ }  } t |  ƒ t | ƒ j o |  | i c  | 7*|  } n | |  i c  |  7*| } t  i | ƒ S(   sð  Add one polynomial to another.

    Returns the sum of two polynomials `c1` + `c2`. The arguments are
    sequences of coefficients ordered from low to high, i.e., [1,2,3] is
    the polynomial ``1 + 2*x + 3*x**2"``.

    Parameters
    ----------
    c1, c2 : array_like
        1d arrays of polynomial coefficients ordered from low to
        high.

    Returns
    -------
    out : ndarray
        polynomial of the sum.

    See Also
    --------
    polysub, polymul, polydiv, polypow

    (   R   R   R   t   sizet   trimseq(   t   c1t   c2t   ret(    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   …   s    
c         C   s~   t  i |  | g ƒ \ }  } t |  ƒ t | ƒ j o |  | i c  | 8*|  } n! | } | |  i c  |  7*| } t  i | ƒ S(   s  Subtract one polynomial from another.

    Returns the difference of two polynomials `c1` - `c2`. The arguments
    are sequences of coefficients ordered from low to high, i.e., [1,2,3]
    is the polynomial ``1 + 2*x + 3*x**2``.

    Parameters
    ----------
    c1, c2 : array_like
        1d arrays of polynomial coefficients ordered from low to
        high.

    Returns
    -------
    out : ndarray
        polynomial of the difference.

    See Also
    --------
    polyadd, polymul, polydiv, polypow

    Examples
    --------

    (   R   R   R   R$   R%   (   R&   R'   R(   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   §   s    
c         C   s:   t  i |  | g ƒ \ }  } t i |  | ƒ } t  i | ƒ S(   s  Multiply one polynomial by another.

    Returns the product of two polynomials `c1` * `c2`. The arguments
    are sequences of coefficients ordered from low to high, i.e., [1,2,3]
    is the polynomial  ``1 + 2*x + 3*x**2.``

    Parameters
    ----------
    c1, c2 : array_like
        1d arrays of polyyshev series coefficients ordered from low to
        high.

    Returns
    -------
    out : ndarray
        polynomial of the product.

    See Also
    --------
    polyadd, polysub, polydiv, polypow

    (   R   R   R   t   convolveR%   (   R&   R'   R(   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   Í   s    c      	   C   s:  t  i |  | g ƒ \ }  } | d d j o t ƒ  ‚ n t |  ƒ } t | ƒ } | d j o |  | d |  d  d f S| | j  o |  d  d |  f S| | } | d } | d  | } | } | d } xA | d j o3 |  | | c !| |  | 8+| d 8} | d 8} qÎ W|  | d | t  i |  | d  ƒ f Sd S(   s/  Divide one polynomial by another.

    Returns the quotient of two polynomials `c1` / `c2`. The arguments are
    sequences of coefficients ordered from low to high, i.e., [1,2,3] is
    the series  ``1 + 2*x + 3*x**2.``

    Parameters
    ----------
    c1, c2 : array_like
        1d arrays of chebyshev series coefficients ordered from low to
        high.

    Returns
    -------
    [quo, rem] : ndarray
        polynomial of the quotient and remainder.

    See Also
    --------
    polyadd, polysub, polymul, polypow

    Examples
    --------

    iÿÿÿÿi    i   N(   R   R   t   ZeroDivisionErrorR   R%   (   R&   R'   t   len1t   len2t   dlenR   R#   t   j(    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR	   ê   s(    


 
c         C   sì   t  i |  g ƒ \ }  t | ƒ } | | j p | d j  o t d ƒ ‚ nž | d j	 o | | j o t d ƒ ‚ nt | d j o t i d g d |  i ƒS| d j o |  S|  } x- t d | d ƒ D] } t i	 | |  ƒ } qÈ W| Sd S(   só  Raise a polynomial to a power.

    Returns the polynomial `cs` raised to the power `pow`. The argument
    `cs` is a sequence of coefficients ordered from low to high. i.e.,
    [1,2,3] is the series  ``1 + 2*x + 3*x**2.``

    Parameters
    ----------
    cs : array_like
        1d array of chebyshev series coefficients ordered from low to
        high.
    pow : integer
        Power to which the series will be raised
    maxpower : integer, optional
        Maximum power allowed. This is mainly to limit growth of the series
        to umanageable size. Default is 16

    Returns
    -------
    coef : ndarray
        Chebyshev series of power.

    See Also
    --------
    chebadd, chebsub, chebmul, chebdiv

    Examples
    --------

    i    s%   Power must be a non-negative integer.s   Power is too largei   R   i   N(
   R   R   t   intt
   ValueErrort   NoneR   R   R   R    R)   (   t   cst   powt   maxpowert   powerR"   R#   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyt   polypow  s      c         C   sâ   t  i |  g ƒ \ }  | d j  o t d ‚ n t i | ƒ p t d ‚ n | d j o |  S| t |  ƒ j o |  d  d St |  ƒ } t i | ƒ | } x, t | ƒ D] } |  | c | | |  9)qª W|  | d i ƒ  Sd S(   s#  Differentiate a polynomial.

    Returns the polynomial `cs` differentiated `m` times. The argument `cs`
    is a sequence of coefficients ordered from low to high. i.e., [1,2,3]
    is the series  ``1 + 2*x + 3*x**2.``

    Parameters
    ----------
    cs: array_like
        1d array of chebyshev series coefficients ordered from low to high.
    m : int, optional
        Order of differentiation, must be non-negative. (default: 1)
    scl : scalar, optional
        The result of each derivation is multiplied by `scl`. The end
        result is multiplication by `scl`**`m`. This is for use in a linear
        change of variable. (default: 1)

    Returns
    -------
    der : ndarray
        polynomial of the derivative.

    See Also
    --------
    polyint

    Examples
    --------

    i    s(   The order of derivation must be positives"   The scl parameter must be a scalari   N(	   R   R   R0   R   t   isscalarR   t   arangeR    t   copy(   R2   t   mR   t   nt   dR#   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   M  s      c         C   s…  t  i | ƒ o | g } n | d j  o t d ‚ n t | ƒ | j o t d ‚ n t  i | ƒ p t d ‚ n t  i | ƒ p t d ‚ n t i |  g ƒ \ }  t | ƒ d g | t | ƒ } t  i d t |  ƒ | ƒ | } t  i t |  ƒ | d |  i	 ƒ} |  | | )xk t
 | ƒ D]] } | | | c | t |  ƒ |  )| | | d c | | t | | | | d ƒ 7<q W| S(   s–  Integrate a polynomial.

    Returns the polynomial `cs` integrated from `lbnd` to x `m` times. At
    each iteration the resulting series is multiplied by `scl` and an
    integration constant specified by `k` is added. The scaling factor is
    for use in a linear change of variable. The argument `cs` is a sequence
    of coefficients ordered from low to high. i.e., [1,2,3] is the
    polynomial ``1 + 2*x + 3*x**2``.


    Parameters
    ----------
    cs : array_like
        1d array of chebyshev series coefficients ordered from low to high.
    m : int, optional
        Order of integration, must be positeve. (default: 1)
    k : {[], list, scalar}, optional
        Integration constants. The value of the first integral at zero is
        the first value in the list, the value of the second integral at
        zero is the second value in the list, and so on. If ``[]``
        (default), all constants are set zero.  If `m = 1`, a single scalar
        can be given instead of a list.
    lbnd : scalar, optional
        The lower bound of the integral. (default: 0)
    scl : scalar, optional
        Following each integration the result is multiplied by `scl` before
        the integration constant is added. (default: 1)

    Returns
    -------
    der : ndarray
        polynomial of the integral.

    Raises
    ------
    ValueError

    See Also
    --------
    polyder

    Examples
    --------

    i   s)   The order of integration must be positives   Too many integration constantss#   The lbnd parameter must be a scalars"   The scl parameter must be a scalari    R   (   R   R7   R0   R   R   R   t   listR8   R   R   R    R
   (   R2   R:   t   kt   lbndR   t   facR(   R#   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   ~  s(    .! "
 "9c         C   s•   t  i | g ƒ \ } t |  t ƒ p t |  t ƒ o t i |  ƒ }  n | d |  d } x4 t d t | ƒ d ƒ D] } | | | |  } qt W| S(   s§  Evaluate a polynomial.

    If `cs` is of length `n`, this function returns :

    ``p(x) = cs[0] + cs[1]*x + ... + cs[n-1]*x**(n-1)``

    If x is a sequence or array then p(x) will have the same shape as x.
    If r is a ring_like object that supports multiplication and addition
    by the values in `cs`, then an object of the same type is returned.

    Parameters
    ----------
    x : array_like, ring_like
        If x is a list or tuple, it is converted to an ndarray. Otherwise
        it must support addition and multiplication with itself and the
        elements of `cs`.
    cs : array_like
        1-d array of Chebyshev coefficients ordered from low to high.

    Returns
    -------
    values : ndarray
        The return array has the same shape as `x`.

    See Also
    --------
    polyfit

    Examples
    --------

    Notes
    -----
    The evaluation uses Horner's method.

    Examples
    --------

    iÿÿÿÿi    i   i   (	   R   R   t
   isinstancet   tupleR=   R   t   asarrayR    R   (   t   xR2   t   c0R#   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR
   Â  s    )  c         C   s    t  i |  ƒ d }  t | ƒ d } t  i |  i | f d |  i ƒ} | d j oJ |  | d <x= t d | ƒ D]( } |  | d | d f | d | f <ql Wn | S(   s  Vandermonde matrix of given degree.

    Returns the Vandermonde matrix of degree `deg` and sample points `x`.
    This isn't a true Vandermonde matrix because `x` can be an arbitrary
    ndarray. If ``V`` is the returned matrix and `x` is a 2d array, then
    the elements of ``V`` are ``V[i,j,k] = x[i,j]**k``

    Parameters
    ----------
    x : array_like
        Array of points. The values are converted to double or complex doubles.
    deg : integer
        Degree of the resulting matrix.

    Returns
    -------
    vander : Vandermonde matrix.
        The shape of the returned matrix is ``x.shape + (deg+1,)``. The last
        index is the degree.

    g        i   R   .i   (   .i   (   R   RC   R/   R   t   shapeR   R    (   RD   t   degt   ordert   vR#   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   ô  s    "
 *c         C   sÇ  t  | ƒ d } t i |  ƒ d }  t i | ƒ d } | d j  o t d ‚ n |  i d j o t d ‚ n |  i d j o t d ‚ n | i d j  p | i d j o t d ‚ n |  i d | i d j o t d	 ‚ n | d j o# t	 |  ƒ t i
 |  i ƒ i } n t |  | ƒ } t i | | i d ƒ ƒ } t i | | | | ƒ \ } }	 }
 } | i | i } |
 | j o% | o d
 } t i | t i ƒ n | o | |	 |
 | | g f S| Sd S(   s¾  Least squares fit of polynomial to data.

    Fit a polynomial ``p(x) = p[0] * T_{deq}(x) + ... + p[deg] *
    T_{0}(x)`` of degree `deg` to points `(x, y)`. Returns a vector of
    coefficients `p` that minimises the squared error.

    Parameters
    ----------
    x : array_like, shape (M,)
        x-coordinates of the M sample points ``(x[i], y[i])``.
    y : array_like, shape (M,) or (M, K)
        y-coordinates of the sample points. Several data sets of sample
        points sharing the same x-coordinates can be fitted at once by
        passing in a 2D-array that contains one dataset per column.
    deg : int
        Degree of the fitting polynomial
    rcond : float, optional
        Relative condition number of the fit. Singular values smaller than
        this relative to the largest singular value will be ignored. The
        default value is len(x)*eps, where eps is the relative precision of
        the float type, about 2e-16 in most cases.
    full : bool, optional
        Switch determining nature of return value. When it is False (the
        default) just the coefficients are returned, when True diagnostic
        information from the singular value decomposition is also returned.

    Returns
    -------
    coef : ndarray, shape (M,) or (M, K)
        Polynomial coefficients ordered from low to high. If `y` was 2-D,
        the coefficients for the data in column k  of `y` are in column
        `k`.

    [residuals, rank, singular_values, rcond] : present when `full` = True
        Residuals of the least-squares fit, the effective rank of the
        scaled Vandermonde matrix and its singular values, and the
        specified value of `rcond`. For more details, see `linalg.lstsq`.

    Warns
    -----
    RankWarning
        The rank of the coefficient matrix in the least-squares fit is
        deficient. The warning is only raised if `full` = False.  The
        warnings can be turned off by

        >>> 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
    --------

    i   g        i    s   expected deg >= 0s   expected 1D vector for xs   expected non-empty vector for xi   s   expected 1D or 2D array for ys$   expected x and y to have same lengths!   The fit may be poorly conditionedN(   R/   R   RC   R0   t   ndimt	   TypeErrorR$   RF   R1   R   t   finfoR   t   epsR   t   sqrtt   sumt   lat   lstsqt   Tt   warningst   warnR   t   RankWarning(   RD   t   yRG   t   rcondt   fullRH   t   AR   t   ct   residst   rankt   st   msg(    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR     s2    ` #%c         C   sý   t  i |  g ƒ \ }  t |  ƒ d j o t i g  d |  i ƒSt |  ƒ d j o t i |  d |  d g ƒ St |  ƒ d } t i | | f d |  i ƒ} d | i | d | d … <| d d … d f c |  d  |  d 8<t i	 | ƒ } | i
 ƒ  | S(   sí  Roots of a polynomial.

    Compute the roots of the Chebyshev series `cs`. The argument `cs` is a
    sequence of coefficients ordered from low to high. i.e., [1,2,3] is the
    polynomial ``1 + 2*x + 3*x**2``.

    Parameters
    ----------
    cs : array_like of shape(M,)
        1D array of polynomial coefficients ordered from low to high.

    Returns
    -------
    out : ndarray
        An array containing the complex roots of the polynomial series.

    Examples
    --------

    i   R   i   i    Niÿÿÿÿ(   R   R   R   R   R   R   R   t   flatRP   t   eigvalst   sort(   R2   R;   t   cmatR!   (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyR   ˜  s    (
t   namet   nickt   polyt   domains   [-1,1]($   t   __doc__t
   __future__R    t   __all__t   numpyR   t   numpy.linalgt   linalgRP   t	   polyutilsR   RS   R   t   trimcoefR   R   R   R   R   R   R   R   R   R   R   R	   R1   R6   R   R   R
   R   R   R   R   t
   substitute(    (    (    sK   P:\graphics\Tools\Python26\lib\site-packages\numpy\polynomial\polynomial.pyt   <module>*   s:   			!	"	&		121D	2	…	(