ó 2ÄÈ[c@`sUdZddlmZmZmZddlZddlZddlj Z ddl m Z ddl mZddlmZdd d d d d ddddddddddddddddddd d!d"d#d$d%d&gZejZd'„Zd(„Zejd)dgƒZejdgƒZejdgƒZejddgƒZd*„Zd+„Zd,„Zd-„Zd.„Z d/„Z!d0„Z"d1d2„Z#dddd3„Z$dgdddd4„Z%e&d5„Z'd6„Z(d7„Z)d8„Z*d9„Z+d:„Z,d;„Z-d<„Z.de0dd=„Z1d>„Z2d?„Z3d@„Z4dA„Z5defdB„ƒYZ6dS(CsÈ Legendre Series (:mod: `numpy.polynomial.legendre`) =================================================== .. currentmodule:: numpy.polynomial.polynomial This module provides a number of objects (mostly functions) useful for dealing with Legendre series, including a `Legendre` class that encapsulates the usual arithmetic operations. (General information on how this module represents and works with such polynomials is in the docstring for its "parent" sub-package, `numpy.polynomial`). Constants --------- .. autosummary:: :toctree: generated/ legdomain Legendre series default domain, [-1,1]. legzero Legendre series that evaluates identically to 0. legone Legendre series that evaluates identically to 1. legx Legendre series for the identity map, ``f(x) = x``. Arithmetic ---------- .. autosummary:: :toctree: generated/ legmulx multiply a Legendre series in P_i(x) by x. legadd add two Legendre series. legsub subtract one Legendre series from another. legmul multiply two Legendre series. legdiv divide one Legendre series by another. legpow raise a Legendre series to an positive integer power legval evaluate a Legendre series at given points. legval2d evaluate a 2D Legendre series at given points. legval3d evaluate a 3D Legendre series at given points. leggrid2d evaluate a 2D Legendre series on a Cartesian product. leggrid3d evaluate a 3D Legendre series on a Cartesian product. Calculus -------- .. autosummary:: :toctree: generated/ legder differentiate a Legendre series. legint integrate a Legendre series. Misc Functions -------------- .. autosummary:: :toctree: generated/ legfromroots create a Legendre series with specified roots. legroots find the roots of a Legendre series. legvander Vandermonde-like matrix for Legendre polynomials. legvander2d Vandermonde-like matrix for 2D power series. legvander3d Vandermonde-like matrix for 3D power series. leggauss Gauss-Legendre quadrature, points and weights. legweight Legendre weight function. legcompanion symmetrized companion matrix in Legendre form. legfit least-squares fit returning a Legendre series. legtrim trim leading coefficients from a Legendre series. legline Legendre series representing given straight line. leg2poly convert a Legendre series to a polynomial. poly2leg convert a polynomial to a Legendre series. Classes ------- Legendre A Legendre series class. See also -------- numpy.polynomial.polynomial numpy.polynomial.chebyshev numpy.polynomial.laguerre numpy.polynomial.hermite numpy.polynomial.hermite_e i(tdivisiontabsolute_importtprint_functionN(tnormalize_axis_indexi(t polyutils(t ABCPolyBasetlegzerotlegonetlegxt legdomaintleglinetlegaddtlegsubtlegmulxtlegmultlegdivtlegpowtlegvaltlegdertleginttleg2polytpoly2legt legfromrootst legvandertlegfittlegtrimtlegrootstLegendretlegval2dtlegval3dt leggrid2dt leggrid3dt legvander2dt legvander3dt legcompaniontleggausst legweightcC`setj|gƒ\}t|ƒd}d}x3t|ddƒD]}tt|ƒ||ƒ}q>W|S(s$ Convert a polynomial to a Legendre series. Convert an array representing the coefficients of a polynomial (relative to the "standard" basis) ordered from lowest degree to highest, to an array of the coefficients of the equivalent Legendre series, ordered from lowest to highest degree. Parameters ---------- pol : array_like 1-D array containing the polynomial coefficients Returns ------- c : ndarray 1-D array containing the coefficients of the equivalent Legendre series. See Also -------- leg2poly Notes ----- The easy way to do conversions between polynomial basis sets is to use the convert method of a class instance. Examples -------- >>> from numpy import polynomial as P >>> p = P.Polynomial(np.arange(4)) >>> p Polynomial([ 0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1]) >>> c = P.Legendre(P.legendre.poly2leg(p.coef)) >>> c Legendre([ 1. , 3.25, 1. , 0.75], domain=[-1, 1], window=[-1, 1]) iiiÿÿÿÿ(tput as_seriestlentrangeR R (tpoltdegtresti((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRis (c C`sçddlm}m}m}tj|gƒ\}t|ƒ}|dkrM|S|d}|d}xlt|dddƒD]T}|}|||d||d|ƒ}||||ƒd|d|ƒ}qxW||||ƒƒSdS(s„ Convert a Legendre series to a polynomial. Convert an array representing the coefficients of a Legendre series, ordered from lowest degree to highest, to an array of the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest to highest degree. Parameters ---------- c : array_like 1-D array containing the Legendre series coefficients, ordered from lowest order term to highest. Returns ------- pol : ndarray 1-D array containing the coefficients of the equivalent polynomial (relative to the "standard" basis) ordered from lowest order term to highest. See Also -------- poly2leg Notes ----- The easy way to do conversions between polynomial basis sets is to use the convert method of a class instance. Examples -------- >>> c = P.Legendre(range(4)) >>> c Legendre([ 0., 1., 2., 3.], [-1., 1.]) >>> p = c.convert(kind=P.Polynomial) >>> p Polynomial([-1. , -3.5, 3. , 7.5], [-1., 1.]) >>> P.leg2poly(range(4)) array([-1. , -3.5, 3. , 7.5]) i(tpolyaddtpolysubtpolymulxiiþÿÿÿiÿÿÿÿiN(t polynomialR-R.R/R%R&R'R(( tcR-R.R/tntc0tc1R,ttmp((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR™s,    #)iÿÿÿÿcC`s3|dkrtj||gƒStj|gƒSdS(s  Legendre series whose graph is a straight line. Parameters ---------- off, scl : scalars The specified line is given by ``off + scl*x``. Returns ------- y : ndarray This module's representation of the Legendre series for ``off + scl*x``. See Also -------- polyline, chebline Examples -------- >>> import numpy.polynomial.legendre as L >>> L.legline(3,2) array([3, 2]) >>> L.legval(-3, L.legline(3,2)) # should be -3 -3.0 iN(tnptarray(tofftscl((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR çs cC`s t|ƒdkrtjdƒStj|gdtƒ\}|jƒg|D]}t| dƒ^qK}t|ƒ}x‰|dkrþt|dƒ\}}gt |ƒD]!}t |||||ƒ^q¤}|rït |d|dƒ|d>> import numpy.polynomial.legendre as L >>> L.legfromroots((-1,0,1)) # x^3 - x relative to the standard basis array([ 0. , -0.4, 0. , 0.4]) >>> j = complex(0,1) >>> L.legfromroots((-j,j)) # x^2 + 1 relative to the standard basis array([ 1.33333333+0.j, 0.00000000+0.j, 0.66666667+0.j]) iittrimiiÿÿÿÿN( R'R6tonesR%R&tFalsetsortR tdivmodR(R(trootstrtpR2tmR,R5((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR s1  # 4 cC`sutj||gƒ\}}t|ƒt|ƒkrO||jc |7*|}n||jc |7*|}tj|ƒS(sò Add one Legendre series to another. Returns the sum of two Legendre series `c1` + `c2`. The arguments are sequences of coefficients ordered from lowest order term to highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Parameters ---------- c1, c2 : array_like 1-D arrays of Legendre series coefficients ordered from low to high. Returns ------- out : ndarray Array representing the Legendre series of their sum. See Also -------- legsub, legmul, legdiv, legpow Notes ----- Unlike multiplication, division, etc., the sum of two Legendre series is a Legendre series (without having to "reproject" the result onto the basis set) so addition, just like that of "standard" polynomials, is simply "component-wise." Examples -------- >>> from numpy.polynomial import legendre as L >>> c1 = (1,2,3) >>> c2 = (3,2,1) >>> L.legadd(c1,c2) array([ 4., 4., 4.]) (R%R&R'tsizettrimseq(R4tc2tret((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR Ms( cC`s|tj||gƒ\}}t|ƒt|ƒkrO||jc |8*|}n | }||jc |7*|}tj|ƒS(sH Subtract one Legendre series from another. Returns the difference of two Legendre series `c1` - `c2`. The sequences of coefficients are from lowest order term to highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``. Parameters ---------- c1, c2 : array_like 1-D arrays of Legendre series coefficients ordered from low to high. Returns ------- out : ndarray Of Legendre series coefficients representing their difference. See Also -------- legadd, legmul, legdiv, legpow Notes ----- Unlike multiplication, division, etc., the difference of two Legendre series is a Legendre series (without having to "reproject" the result onto the basis set) so subtraction, just like that of "standard" polynomials, is simply "component-wise." Examples -------- >>> from numpy.polynomial import legendre as L >>> c1 = (1,2,3) >>> c2 = (3,2,1) >>> L.legsub(c1,c2) array([-2., 0., 2.]) >>> L.legsub(c2,c1) # -C.legsub(c1,c2) array([ 2., 0., -2.]) (R%R&R'RCRD(R4RERF((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR s* cC`sñtj|gƒ\}t|ƒdkr;|ddkr;|Stjt|ƒdd|jƒ}|dd|d<|d|d>> from numpy.polynomial import legendre as L >>> c1 = (1,2,3) >>> c2 = (3,2) >>> P.legmul(c1,c2) # multiplication requires "reprojection" array([ 4.33333333, 10.4 , 11.66666667, 3.6 ]) iiiiþÿÿÿiÿÿÿÿi(R%R&R'R(R R R (R4RER1txsR3tndR,R5((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRâs*)     $)c C`s@tj||gƒ\}}|ddkr7tƒ‚nt|ƒ}t|ƒ}||krm|d d|fS|dkr“||d|d dfStj||dd|jƒ}|}xmt||ddƒD]U}tdg|dg|ƒ}|d|d}|d ||d }|||>> from numpy.polynomial import legendre as L >>> c1 = (1,2,3) >>> c2 = (3,2,1) >>> L.legdiv(c1,c2) # quotient "intuitive," remainder not (array([ 3.]), array([-8., -4.])) >>> c2 = (0,1,2,3) >>> L.legdiv(c2,c1) # neither "intuitive" (array([-0.07407407, 1.66666667]), array([-1.03703704, -2.51851852])) iÿÿÿÿiiRGN( R%R&tZeroDivisionErrorR'R6RHRGR(RRD( R4REtlc1tlc2tquotremR,RAtq((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR&s"/      icC`sßtj|gƒ\}t|ƒ}||ks9|dkrHtdƒ‚n“|dk ro||krotdƒ‚nl|dkr”tjdgd|jƒS|dkr¤|S|}x*td|dƒD]}t ||ƒ}q¾W|SdS(sùRaise a Legendre series to a power. Returns the Legendre series `c` raised to the power `pow`. The argument `c` is a sequence of coefficients ordered from low to high. i.e., [1,2,3] is the series ``P_0 + 2*P_1 + 3*P_2.`` Parameters ---------- c : array_like 1-D array of Legendre 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 unmanageable size. Default is 16 Returns ------- coef : ndarray Legendre series of power. See Also -------- legadd, legsub, legmul, legdiv Examples -------- is%Power must be a non-negative integer.sPower is too largeiRGiN( R%R&tintt ValueErrortNoneR6R7RGR(R(R1tpowtmaxpowertpowerRIR,((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRjs    c C`stj|ddddƒ}|jjdkrB|jtjƒ}ng||gD]}t|ƒ^qO\}}||krˆtdƒ‚n|dkr£tdƒ‚n||kr¾tdƒ‚nt||j ƒ}|dkrà|Stj ||dƒ}t |ƒ}||kr|d d}nÙxÖt |ƒD]È}|d}||9}tj |f|jdd |jƒ} xPt |d d ƒD]<} d | d|| | | d<|| d c|| 7>> from numpy.polynomial import legendre as L >>> c = (1,2,3,4) >>> L.legder(c) array([ 6., 9., 20.]) >>> L.legder(c, 3) array([ 60.]) >>> L.legder(c, scl=-1) array([ -6., -9., -20.]) >>> L.legder(c, 2,-1) array([ 9., 60.]) tndminitcopys ?bBhHiIlLqQpPs'The order of derivation must be integeris,The order of derivation must be non-negativesThe axis must be integerRGiiÿÿÿÿi(R6R7RGtchartastypetdoubleRURVRtndimtmoveaxisR'R(RHtshape( R1RBR9taxistttcnttiaxisR2R,tderRJ((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRs<<+        &  c C`stj|ddddƒ}|jjdkrB|jtjƒ}ntj|ƒs]|g}ng||gD]}t|ƒ^qj\}}||kr£tdƒ‚n|dkr¾tdƒ‚nt |ƒ|krßtdƒ‚ntj |ƒdkrtd ƒ‚ntj |ƒdkr'td ƒ‚n||krBtd ƒ‚nt ||j ƒ}|dkrd|Stj ||dƒ}t |ƒdg|t |ƒ}xJt|ƒD]<} t |ƒ} ||9}| dkrÿtj|ddkƒrÿ|dc|| 7} || d| d}|| | d<| | dc|8 m``, ``np.ndim(lbnd) != 0``, or ``np.ndim(scl) != 0``. See Also -------- legder Notes ----- Note that the result of each integration is *multiplied* by `scl`. Why is this important to note? Say one is making a linear change of variable :math:`u = ax + b` in an integral relative to `x`. Then :math:`dx = du/a`, so one will need to set `scl` equal to :math:`1/a` - perhaps not what one would have first thought. Also note that, in general, the result of integrating a C-series needs to be "reprojected" onto the C-series basis set. Thus, typically, the result of this function is "unintuitive," albeit correct; see Examples section below. Examples -------- >>> from numpy.polynomial import legendre as L >>> c = (1,2,3) >>> L.legint(c) array([ 0.33333333, 0.4 , 0.66666667, 0.6 ]) >>> L.legint(c, 3) array([ 1.66666667e-02, -1.78571429e-02, 4.76190476e-02, -1.73472348e-18, 1.90476190e-02, 9.52380952e-03]) >>> L.legint(c, k=3) array([ 3.33333333, 0.4 , 0.66666667, 0.6 ]) >>> L.legint(c, lbnd=-2) array([ 7.33333333, 0.4 , 0.66666667, 0.6 ]) >>> L.legint(c, scl=2) array([ 0.66666667, 0.8 , 1.33333333, 1.2 ]) R[iR\s ?bBhHiIlLqQpPs(The order of integration must be integeris-The order of integration must be non-negativesToo many integration constantsslbnd must be a scalar.sscl must be a scalar.sThe axis must be integerRGii(R6R7RGR]R^R_titerableRURVR'R`RRatlistR(tallRHRbR( R1RBRKtlbndR9RcRdReRfR,R2R5RJ((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRýsRU +    !  %* ! cC`sˆtj|ddddƒ}|jjdkrB|jtjƒ}nt|ttfƒritj |ƒ}nt|tj ƒr¡|r¡|j |j d |j ƒ}nt|ƒdkrÆ|d}d}n¶t|ƒdkrï|d}|d}nt|ƒ}|d}|d}xjtd t|ƒdƒD]O}|}|d}|| ||d|}|||d|d|}q)W|||S( sg Evaluate a Legendre series at points x. If `c` is of length `n + 1`, this function returns the value: .. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x) The parameter `x` is converted to an array only if it is a tuple or a list, otherwise it is treated as a scalar. In either case, either `x` or its elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` is a 1-D array, then `p(x)` will have the same shape as `x`. If `c` is multidimensional, then the shape of the result depends on the value of `tensor`. If `tensor` is true the shape will be c.shape[1:] + x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that scalars have shape (,). Trailing zeros in the coefficients will be used in the evaluation, so they should be avoided if efficiency is a concern. Parameters ---------- x : array_like, compatible object If `x` is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar. In either case, `x` or its elements must support addition and multiplication with with themselves and with the elements of `c`. c : array_like Array of coefficients ordered so that the coefficients for terms of degree n are contained in c[n]. If `c` is multidimensional the remaining indices enumerate multiple polynomials. In the two dimensional case the coefficients may be thought of as stored in the columns of `c`. tensor : boolean, optional If True, the shape of the coefficient array is extended with ones on the right, one for each dimension of `x`. Scalars have dimension 0 for this action. The result is that every column of coefficients in `c` is evaluated for every element of `x`. If False, `x` is broadcast over the columns of `c` for the evaluation. This keyword is useful when `c` is multidimensional. The default value is True. .. versionadded:: 1.7.0 Returns ------- values : ndarray, algebra_like The shape of the return value is described above. See Also -------- legval2d, leggrid2d, legval3d, leggrid3d Notes ----- The evaluation uses Clenshaw recursion, aka synthetic division. Examples -------- R[iR\is ?bBhHiIlLqQpPiiþÿÿÿiÿÿÿÿi(i(R6R7RGR]R^R_t isinstancettupleRitasarraytndarraytreshapeRbR`R'R((txR1ttensorR3R4RNR,R5((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRs,>          "cC`smy%tj||fddƒ\}}Wntk rDtdƒ‚nXt||ƒ}t||dtƒ}|S(sD Evaluate a 2-D Legendre series at points (x, y). This function returns the values: .. math:: p(x,y) = \sum_{i,j} c_{i,j} * L_i(x) * L_j(y) The parameters `x` and `y` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars and they must have the same shape after conversion. In either case, either `x` and `y` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` is a 1-D array a one is implicitly appended to its shape to make it 2-D. The shape of the result will be c.shape[2:] + x.shape. Parameters ---------- x, y : array_like, compatible objects The two dimensional series is evaluated at the points `(x, y)`, where `x` and `y` must have the same shape. If `x` or `y` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and if it isn't an ndarray it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension greater than two the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the two dimensional Legendre series at points formed from pairs of corresponding values from `x` and `y`. See Also -------- legval, leggrid2d, legval3d, leggrid3d Notes ----- .. versionadded:: 1.7.0 R\isx, y are incompatibleRr(R6R7t ExceptionRVRR<(RqtyR1((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRÙs.% cC`s"t||ƒ}t||ƒ}|S(sã Evaluate a 2-D Legendre series on the Cartesian product of x and y. This function returns the values: .. math:: p(a,b) = \sum_{i,j} c_{i,j} * L_i(a) * L_j(b) where the points `(a, b)` consist of all pairs formed by taking `a` from `x` and `b` from `y`. The resulting points form a grid with `x` in the first dimension and `y` in the second. The parameters `x` and `y` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars. In either case, either `x` and `y` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` has fewer than two dimensions, ones are implicitly appended to its shape to make it 2-D. The shape of the result will be c.shape[2:] + x.shape + y.shape. Parameters ---------- x, y : array_like, compatible objects The two dimensional series is evaluated at the points in the Cartesian product of `x` and `y`. If `x` or `y` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and, if it isn't an ndarray, it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in `c[i,j]`. If `c` has dimension greater than two the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the two dimensional Chebyshev series at points in the Cartesian product of `x` and `y`. See Also -------- legval, legval2d, legval3d, leggrid3d Notes ----- .. versionadded:: 1.7.0 (R(RqRtR1((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRs2cC`sˆy+tj|||fddƒ\}}}Wntk rJtdƒ‚nXt||ƒ}t||dtƒ}t||dtƒ}|S(sž Evaluate a 3-D Legendre series at points (x, y, z). This function returns the values: .. math:: p(x,y,z) = \sum_{i,j,k} c_{i,j,k} * L_i(x) * L_j(y) * L_k(z) The parameters `x`, `y`, and `z` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars and they must have the same shape after conversion. In either case, either `x`, `y`, and `z` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` has fewer than 3 dimensions, ones are implicitly appended to its shape to make it 3-D. The shape of the result will be c.shape[3:] + x.shape. Parameters ---------- x, y, z : array_like, compatible object The three dimensional series is evaluated at the points `(x, y, z)`, where `x`, `y`, and `z` must have the same shape. If any of `x`, `y`, or `z` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and if it isn't an ndarray it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficient of the term of multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension greater than 3 the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the multidimensional polynomial on points formed with triples of corresponding values from `x`, `y`, and `z`. See Also -------- legval, legval2d, leggrid2d, leggrid3d Notes ----- .. versionadded:: 1.7.0 R\isx, y, z are incompatibleRr(R6R7RsRVRR<(RqRttzR1((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRHs0+ cC`s1t||ƒ}t||ƒ}t||ƒ}|S(sK Evaluate a 3-D Legendre series on the Cartesian product of x, y, and z. This function returns the values: .. math:: p(a,b,c) = \sum_{i,j,k} c_{i,j,k} * L_i(a) * L_j(b) * L_k(c) where the points `(a, b, c)` consist of all triples formed by taking `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form a grid with `x` in the first dimension, `y` in the second, and `z` in the third. The parameters `x`, `y`, and `z` are converted to arrays only if they are tuples or a lists, otherwise they are treated as a scalars. In either case, either `x`, `y`, and `z` or their elements must support multiplication and addition both with themselves and with the elements of `c`. If `c` has fewer than three dimensions, ones are implicitly appended to its shape to make it 3-D. The shape of the result will be c.shape[3:] + x.shape + y.shape + z.shape. Parameters ---------- x, y, z : array_like, compatible objects The three dimensional series is evaluated at the points in the Cartesian product of `x`, `y`, and `z`. If `x`,`y`, or `z` is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and, if it isn't an ndarray, it is treated as a scalar. c : array_like Array of coefficients ordered so that the coefficients for terms of degree i,j are contained in ``c[i,j]``. If `c` has dimension greater than two the remaining indices enumerate multiple sets of coefficients. Returns ------- values : ndarray, compatible object The values of the two dimensional polynomial at points in the Cartesian product of `x` and `y`. See Also -------- legval, legval2d, leggrid2d, legval3d Notes ----- .. versionadded:: 1.7.0 (R(RqRtRuR1((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRƒs5cC`s)t|ƒ}||kr'tdƒ‚n|dkrBtdƒ‚ntj|ddddƒd}|df|j}|j}tj|d|ƒ}|dd|d<|dkr||dcC`sâtj|ƒd}tj|ƒd}tj|ƒ}|jdkse|jjdkse|jdkrttdƒ‚n|jƒdkr•tdƒ‚n|jdkr³tdƒ‚n|jdkrÑtdƒ‚n|jdksï|jd krþtd ƒ‚nt |ƒt |ƒkr%td ƒ‚n|jdkrV|}|d}t ||ƒ}nDtj |ƒ}|d }t |ƒ}t ||ƒd d …|f}|j } |j } |d k r'tj|ƒd}|jdkrétdƒ‚nt |ƒt |ƒkrtdƒ‚n| |} | |} n|d krUt |ƒtj|jƒj}nt| jjtjƒr¤tjtj| jƒtj| jƒjdƒƒ} n!tjtj| ƒjdƒƒ} d| | dk= 1.11.0 a list of integers specifying the degrees of the terms to include may be used instead. 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. w : array_like, shape (`M`,), optional Weights. If not None, the contribution of each point ``(x[i],y[i])`` to the fit is weighted by `w[i]`. Ideally the weights are chosen so that the errors of the products ``w[i]*y[i]`` all have the same variance. The default value is None. .. versionadded:: 1.5.0 Returns ------- coef : ndarray, shape (M,) or (M, K) Legendre 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`. If `deg` is specified as a list, coefficients for terms not included in the fit are set equal to zero in the returned `coef`. [residuals, rank, singular_values, rcond] : list These values are only returned if `full` = True resid -- sum of squared residuals of the least squares fit rank -- the numerical rank of the scaled Vandermonde matrix sv -- singular values of the scaled Vandermonde matrix rcond -- 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 -------- chebfit, polyfit, lagfit, hermfit, hermefit legval : Evaluates a Legendre series. legvander : Vandermonde matrix of Legendre series. legweight : Legendre weight function (= 1). linalg.lstsq : Computes a least-squares fit from the matrix. scipy.interpolate.UnivariateSpline : Computes spline fits. Notes ----- The solution is the coefficients of the Legendre series `p` that minimizes the sum of the weighted squared errors .. math:: E = \sum_j w_j^2 * |y_j - p(x_j)|^2, where :math:`w_j` are the weights. This problem is solved by setting up as the (typically) overdetermined matrix equation .. math:: V(x) * c = w * y, where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the coefficients to be solved for, `w` are the weights, and `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 coefficient 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 Legendre series are usually better conditioned than fits using power series, but much can 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 -------- gitiuis0deg must be an int or non-empty 1-D array of intsexpected deg >= 0sexpected 1D vector for xsexpected non-empty vector for xisexpected 1D or 2D array for ys$expected x and y to have same lengthiÿÿÿÿNsexpected 1D vector for ws$expected x and w to have same lengthRGs!The fit may be poorly conditionedt stacklevel( R6RnR`RGtkindRCt TypeErrortminRVR'RR=tTRWtfinfotepst issubclassttypetcomplexfloatingtsqrttsquaretrealtimagtsumtlatlstsqtzerosRbtwarningstwarnR%t RankWarning(RqRtR*trcondtfulltwtlmaxtordertvantlhstrhsR9R1tresidstrankRLtcctmsg((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRusjy0         "7!+,  cC`sytj|gƒ\}t|ƒdkr6tdƒ‚nt|ƒdkrhtj|d |dggƒSt|ƒd}tj||fd|jƒ}dtjdtj |ƒdƒ}|j dƒdd|d…}|j dƒ|d|d…}tj d|ƒ||d |d|!|d <||d <|dd…dfc|d |d||d|d|d8<|S( s”Return the scaled companion matrix of c. The basis polynomials are scaled so that the companion matrix is symmetric when `c` is an Legendre basis polynomial. This provides better eigenvalue estimates than the unscaled case and for basis polynomials the eigenvalues are guaranteed to be real if `numpy.linalg.eigvalsh` is used to obtain them. Parameters ---------- c : array_like 1-D array of Legendre series coefficients ordered from low to high degree. Returns ------- mat : ndarray Scaled companion matrix of dimensions (deg, deg). Notes ----- .. versionadded:: 1.7.0 is.Series must have maximum degree of at least 1.iiRGgð?iÿÿÿÿN.( R%R&R'RVR6R7R–RGRtarangeRp(R1R2tmatR9ttoptbot((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR";s $  - DcC`s•tj|gƒ\}t|ƒdkr=tjgd|jƒSt|ƒdkrltj|d |dgƒSt|ƒ}tj|ƒ}|j ƒ|S(s3 Compute the roots of a Legendre series. Return the roots (a.k.a. "zeros") of the polynomial .. math:: p(x) = \sum_i c[i] * L_i(x). Parameters ---------- c : 1-D array_like 1-D array of coefficients. Returns ------- out : ndarray Array of the roots of the series. If all the roots are real, then `out` is also real, otherwise it is complex. See Also -------- polyroots, chebroots, lagroots, hermroots, hermeroots Notes ----- The root estimates are obtained as the eigenvalues of the companion matrix, Roots far from the origin of the complex plane may have large errors due to the numerical instability of the series for such values. Roots with multiplicity greater than 1 will also show larger errors as the value of the series near such points is relatively insensitive to errors in the roots. Isolated roots near the origin can be improved by a few iterations of Newton's method. The Legendre series basis polynomials aren't powers of ``x`` so the results of this function may seem unintuitive. Examples -------- >>> import numpy.polynomial.legendre as leg >>> leg.legroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0, all real roots array([-0.85099543, -0.11407192, 0.51506735]) iRGii( R%R&R'R6R7RGR"R”teigvalsR=(R1RBR@((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRgs,  c C`sDt|ƒ}||ks$|dkr3tdƒ‚ntjdg|dgƒ}t|ƒ}tj|ƒ}t||ƒ}t|t|ƒƒ}|||8}t||dƒ}|tj |ƒj ƒ}|tj |ƒj ƒ}d||}||ddd…d}||ddd…d}|d|j ƒ9}||fS(sé Gauss-Legendre quadrature. Computes the sample points and weights for Gauss-Legendre quadrature. These sample points and weights will correctly integrate polynomials of degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with the weight function :math:`f(x) = 1`. Parameters ---------- deg : int Number of sample points and weights. It must be >= 1. Returns ------- x : ndarray 1-D ndarray containing the sample points. y : ndarray 1-D ndarray containing the weights. Notes ----- .. versionadded:: 1.7.0 The results have only been tested up to degree 100, higher degrees may be problematic. The weights are determined by using the fact that .. math:: w_k = c / (L'_n(x_k) * L_{n-1}(x_k)) where :math:`c` is a constant independent of :math:`k` and :math:`x_k` is the k'th root of :math:`L_n`, and then scaling the results to get the right value when integrating 1. is"deg must be a non-negative integeriNiÿÿÿÿig@( RURVR6R7R"R”teigvalshRRtabstmaxR“( R*RvR1RBRqtdytdftfmRœ((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR#Ÿs"$  cC`s|dd}|S(sé Weight function of the Legendre polynomials. The weight function is :math:`1` and the interval of integration is :math:`[-1, 1]`. The Legendre polynomials are orthogonal, but not normalized, with respect to this weight function. Parameters ---------- x : array_like Values at which the weight function will be computed. Returns ------- w : ndarray The weight function at `x`. Notes ----- .. versionadded:: 1.7.0 ggð?((RqRœ((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyR$ãscB`sÂeZdZeeƒZeeƒZeeƒZ ee ƒZ ee ƒZ eeƒZeeƒZeeƒZeeƒZeeƒZeeƒZeeƒZdZejeƒZ ejeƒZ!RS(sA Legendre series class. The Legendre class provides the standard Python numerical methods '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the attributes and methods listed in the `ABCPolyBase` documentation. Parameters ---------- coef : array_like Legendre coefficients in order of increasing degree, i.e., ``(1, 2, 3)`` gives ``1*P_0(x) + 2*P_1(x) + 3*P_2(x)``. domain : (2,) array_like, optional Domain to use. The interval ``[domain[0], domain[1]]`` is mapped to the interval ``[window[0], window[1]]`` by shifting and scaling. The default value is [-1, 1]. window : (2,) array_like, optional Window, see `domain` for its use. The default value is [-1, 1]. .. versionadded:: 1.6.0 tleg("t__name__t __module__t__doc__t staticmethodR t_addR t_subRt_mulRt_divRt_powRt_valRt_intRt_derRt_fitR t_lineRt_rootsRt _fromrootstnicknameR6R7R tdomaintwindow(((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pyRs             (7R´t __future__RRRR—tnumpyR6t numpy.linalgtlinalgR”tnumpy.core.multiarrayRtRR%t _polybaseRt__all__ttrimcoefRRRR7R RRRR RR R R RRRRRtTrueRRRRRRR R!RWR<RR"RR#R$R(((s8/tmp/pip-build-fiC0ax/numpy/numpy/polynomial/legendre.pytSsX     0 B $ B 2 5 . D D 3`„ X 8 7 ; ; 7 ? AÆ , 8 D