Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
legendre.cpython-313.pyc1323 linesDownload Raw Back to __pycache__
1�

2z�j�����SrSSKrSSKJr SSKJr /SQr\Rr3SrSr\R"S	S4/5r\R"S/5r\R"S/5r\R"SS/5rSrSrS
rSrSrSrSrS$SjrS%SjrS/SSS4SjrS&SjrSrSrSrSr Sr!Sr"Sr#S'Sjr$Sr%Sr&S r'S!r("S"S#\5r)g)(a�5==================================================6Legendre Series (:mod:`numpy.polynomial.legendre`)7==================================================8 9This module provides a number of objects (mostly functions) useful for10dealing with Legendre series, including a `Legendre` class that11encapsulates the usual arithmetic operations.  (General information12on how this module represents and works with such polynomials is in the13docstring for its "parent" sub-package, `numpy.polynomial`).14 15Classes16-------17.. autosummary::18   :toctree: generated/19 20    Legendre21 22Constants23---------24 25.. autosummary::26   :toctree: generated/27 28   legdomain29   legzero30   legone31   legx32 33Arithmetic34----------35 36.. autosummary::37   :toctree: generated/38 39   legadd40   legsub41   legmulx42   legmul43   legdiv44   legpow45   legval46   legval2d47   legval3d48   leggrid2d49   leggrid3d50 51Calculus52--------53 54.. autosummary::55   :toctree: generated/56 57   legder58   legint59 60Misc Functions61--------------62 63.. autosummary::64   :toctree: generated/65 66   legfromroots67   legroots68   legvander69   legvander2d70   legvander3d71   leggauss72   legweight73   legcompanion74   legfit75   legtrim76   legline77   leg2poly78   poly2leg79 80See also81--------82numpy.polynomial83 84�N�)�	polyutils)�ABCPolyBase)�legzero�legone�legx�	legdomain�legline�legadd�legsub�legmulx�legmul�legdiv�legpow�legval�legder�legint�leg2poly�poly2leg�legfromroots�	legvander�legfit�legtrim�legroots�Legendre�legval2d�legval3d�	leggrid2d�	leggrid3d�legvander2d�legvander3d�legcompanion�leggauss�	legweightc��[R"U/5un[U5S-85nSn[USS5Hn[	[U5X5nM U$)a�86Convert a polynomial to a Legendre series.87 88Convert an array representing the coefficients of a polynomial (relative89to the "standard" basis) ordered from lowest degree to highest, to an90array of the coefficients of the equivalent Legendre series, ordered91from lowest to highest degree.92 93Parameters94----------95pol : array_like96    1-D array containing the polynomial coefficients97 98Returns99-------100c : ndarray101    1-D array containing the coefficients of the equivalent Legendre102    series.103 104See Also105--------106leg2poly107 108Notes109-----110The easy way to do conversions between polynomial basis sets111is to use the convert method of a class instance.112 113Examples114--------115>>> import numpy as np116>>> from numpy import polynomial as P117>>> p = P.Polynomial(np.arange(4))118>>> p119Polynomial([0.,  1.,  2.,  3.], domain=[-1.,  1.], window=[-1.,  1.], ...120>>> c = P.Legendre(P.legendre.poly2leg(p.coef))121>>> c122Legendre([ 1.  ,  3.25,  1.  ,  0.75], domain=[-1,  1], window=[-1,  1]) # may vary123 124rr�����)�pu�	as_series�len�rangerr
)�pol�deg�res�is    �_D:\code\apps\devtools\python\user_packages\Python313\site-packages\numpy/polynomial/legendre.pyrrbsS��R
�L�L�#���E�S�125
�c�(�Q�,�C�126�C�
�3��B�
���W�S�\�3�6�*�� ��J�c�0�SSKJnJnJn [R127"U/5un[
U5nUS:aU$USnUSn[US-128SS5H5nUnU"XS-129XgS-130-U-5nU"X�"U5SU-S-131-U-5nM7 U"XR"U55$)ae132Convert a Legendre series to a polynomial.133 134Convert an array representing the coefficients of a Legendre series,135ordered from lowest degree to highest, to an array of the coefficients136of the equivalent polynomial (relative to the "standard" basis) ordered137from lowest to highest degree.138 139Parameters140----------141c : array_like142    1-D array containing the Legendre series coefficients, ordered143    from lowest order term to highest.144 145Returns146-------147pol : ndarray148    1-D array containing the coefficients of the equivalent polynomial149    (relative to the "standard" basis) ordered from lowest order term150    to highest.151 152See Also153--------154poly2leg155 156Notes157-----158The easy way to do conversions between polynomial basis sets159is to use the convert method of a class instance.160 161Examples162--------163>>> from numpy import polynomial as P164>>> c = P.Legendre(range(4))165>>> c166Legendre([0., 1., 2., 3.], domain=[-1.,  1.], window=[-1.,  1.], symbol='x')167>>> p = c.convert(kind=P.Polynomial)168>>> p169Polynomial([-1. , -3.5,  3. ,  7.5], domain=[-1.,  1.], window=[-1., ...170>>> P.legendre.leg2poly(range(4))171array([-1. , -3.5,  3. ,  7.5])172 173 174r)�polyadd�polymulx�polysub������r&�)�175polynomialr2r3r4r'r(r)r*)	�cr2r3r4�n�c0�c1r.�tmps	         r/rr�s���Z7�6�176�,�,��s�177�C�Q��A��A��1�u���
�r�U��
�r�U���q�1�u�a��$�A��C���q�5��B�a�%�L�A�#5�6�B���x��|�q�1�u�q�y�9�Q�>�?�B�%��r�8�B�<�(�(r0g���?c�j�US:wa[R"X/5$[R"U/5$)aX178Legendre series whose graph is a straight line.179 180 181 182Parameters183----------184off, scl : scalars185    The specified line is given by ``off + scl*x``.186 187Returns188-------189y : ndarray190    This module's representation of the Legendre series for191    ``off + scl*x``.192 193See Also194--------195numpy.polynomial.polynomial.polyline196numpy.polynomial.chebyshev.chebline197numpy.polynomial.laguerre.lagline198numpy.polynomial.hermite.hermline199numpy.polynomial.hermite_e.hermeline200 201Examples202--------203>>> import numpy.polynomial.legendre as L204>>> L.legline(3,2)205array([3, 2])206>>> L.legval(-3, L.legline(3,2)) # should be -3207-3.0208 209r)�np�array)�off�scls  r/r210r211�s-��D�a�x��x�x��212�#�#��x�x����r0c�B�[R"[[U5$)a213Generate a Legendre series with given roots.214 215The function returns the coefficients of the polynomial216 217.. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),218 219in Legendre form, where the :math:`r_n` are the roots specified in `roots`.220If a zero has multiplicity n, then it must appear in `roots` n times.221For instance, if 2 is a root of multiplicity three and 3 is a root of222multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The223roots can appear in any order.224 225If the returned coefficients are `c`, then226 227.. math:: p(x) = c_0 + c_1 * L_1(x) + ... +  c_n * L_n(x)228 229The coefficient of the last term is not generally 1 for monic230polynomials in Legendre form.231 232Parameters233----------234roots : array_like235    Sequence containing the roots.236 237Returns238-------239out : ndarray240    1-D array of coefficients.  If all roots are real then `out` is a241    real array, if some of the roots are complex, then `out` is complex242    even if all the coefficients in the result are real (see Examples243    below).244 245See Also246--------247numpy.polynomial.polynomial.polyfromroots248numpy.polynomial.chebyshev.chebfromroots249numpy.polynomial.laguerre.lagfromroots250numpy.polynomial.hermite.hermfromroots251numpy.polynomial.hermite_e.hermefromroots252 253Examples254--------255>>> import numpy.polynomial.legendre as L256>>> L.legfromroots((-1,0,1)) # x^3 - x relative to the standard basis257array([ 0. , -0.4,  0. ,  0.4])258>>> j = complex(0,1)259>>> L.legfromroots((-j,j)) # x^2 + 1 relative to the standard basis260array([ 1.33333333+0.j,  0.00000000+0.j,  0.66666667+0.j]) # may vary261 262)r'�263_fromrootsr264r)�rootss r/rrs��h�=�=��&�%�0�0r0c�.�[R"X5$)a�265Add one Legendre series to another.266 267Returns the sum of two Legendre series `c1` + `c2`.  The arguments268are sequences of coefficients ordered from lowest order term to269highest, i.e., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.270 271Parameters272----------273c1, c2 : array_like274    1-D arrays of Legendre series coefficients ordered from low to275    high.276 277Returns278-------279out : ndarray280    Array representing the Legendre series of their sum.281 282See Also283--------284legsub, legmulx, legmul, legdiv, legpow285 286Notes287-----288Unlike multiplication, division, etc., the sum of two Legendre series289is a Legendre series (without having to "reproject" the result onto290the basis set) so addition, just like that of "standard" polynomials,291is simply "component-wise."292 293Examples294--------295>>> from numpy.polynomial import legendre as L296>>> c1 = (1,2,3)297>>> c2 = (3,2,1)298>>> L.legadd(c1,c2)299array([4.,  4.,  4.])300 301)r'�_add�r<�c2s  r/rrBs��N�7�7�2�?�r0c�.�[R"X5$)a�302Subtract one Legendre series from another.303 304Returns the difference of two Legendre series `c1` - `c2`.  The305sequences of coefficients are from lowest order term to highest, i.e.,306[1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.307 308Parameters309----------310c1, c2 : array_like311    1-D arrays of Legendre series coefficients ordered from low to312    high.313 314Returns315-------316out : ndarray317    Of Legendre series coefficients representing their difference.318 319See Also320--------321legadd, legmulx, legmul, legdiv, legpow322 323Notes324-----325Unlike multiplication, division, etc., the difference of two Legendre326series is a Legendre series (without having to "reproject" the result327onto the basis set) so subtraction, just like that of "standard"328polynomials, is simply "component-wise."329 330Examples331--------332>>> from numpy.polynomial import legendre as L333>>> c1 = (1,2,3)334>>> c2 = (3,2,1)335>>> L.legsub(c1,c2)336array([-2.,  0.,  2.])337>>> L.legsub(c2,c1) # -C.legsub(c1,c2)338array([ 2.,  0., -2.])339 340)r'�_subrIs  r/rrls��R�7�7�2�?�r0c�|�[R"U/5un[U5S:XaUSS:XaU$[R"[U5S-UR341S9nUSS-US'USUS'[
S[U55H1nUS-nUS-342nX#-nXU-U-X'X==XU-U--
ss'M3 U$)a�Multiply a Legendre series by x.343 344Multiply the Legendre series `c` by x, where x is the independent345variable.346 347 348Parameters349----------350c : array_like351    1-D array of Legendre series coefficients ordered from low to352    high.353 354Returns355-------356out : ndarray357    Array representing the result of the multiplication.358 359See Also360--------361legadd, legsub, legmul, legdiv, legpow362 363Notes364-----365The multiplication uses the recursion relationship for Legendre366polynomials in the form367 368.. math::369 370  xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)371 372Examples373--------374>>> from numpy.polynomial import legendre as L375>>> L.legmulx([1,2,3])376array([ 0.66666667, 2.2, 1.33333333, 1.8]) # may vary377 378rr��dtype)r'r(r)r@�emptyrOr*)r9�prdr.�j�k�ss      r/r
r
�s���N
�,�,��s�379�C�Q�380�1�v��{�q��t�q�y���381�(�(�3�q�6�A�:�Q�W�W�382-�C�
�q�T�A�X�C��F�
�q�T�C��F�
�1�c�!�f�
��
��E��
��E��
�E���$��(�a������1�4�!�8�q�.� ����Jr0c��[R"X/5up[U5[U5:�aUnUnOUnUn[U5S:XaUSU-nSnO�[U5S:XaUSU-nUSU-nO|[U5nUSU-nUSU-n[S[U5S-5HEnUnUS-383n[	X&*U-XS-384-U-5n[U[
U5SU-S-385-U-5nMG [U[
U55$)a=386Multiply one Legendre series by another.387 388Returns the product of two Legendre series `c1` * `c2`.  The arguments389are sequences of coefficients, from lowest order "term" to highest,390e.g., [1,2,3] represents the series ``P_0 + 2*P_1 + 3*P_2``.391 392Parameters393----------394c1, c2 : array_like395    1-D arrays of Legendre series coefficients ordered from low to396    high.397 398Returns399-------400out : ndarray401    Of Legendre series coefficients representing their product.402 403See Also404--------405legadd, legsub, legmulx, legdiv, legpow406 407Notes408-----409In general, the (polynomial) product of two C-series results in terms410that are not in the Legendre polynomial basis set.  Thus, to express411the product as a Legendre series, it is necessary to "reproject" the412product onto said basis set, which may produce "unintuitive" (but413correct) results; see Examples section below.414 415Examples416--------417>>> from numpy.polynomial import legendre as L418>>> c1 = (1,2,3)419>>> c2 = (3,2)420>>> L.legmul(c1,c2) # multiplication requires "reprojection"421array([  4.33333333,  10.4       ,  11.66666667,   3.6       ]) # may vary422 423rrr7r6r&r5)r'r(r)r*rrr
)r<rJr9�xsr;�ndr.r=s        r/rr�s��R�|�|�R�H�%�H�R�424�2�w��R�����
����
��425�1�v��{�
�q�T�B�Y��
��	�Q��1��
�q�T�B�Y��
�q�T�B�Y��
��V��
�r�U�R�Z��
�r�U�R�Z���q�#�a�&�1�*�%�A��C��a��B���"���426�R��6�]�b�$8�9�B���g�b�k�Q��V�a�Z�8�B�>�?�B�	&�427�"�g�b�k�"�"r0c�8�[R"[X5$)a�428Divide one Legendre series by another.429 430Returns the quotient-with-remainder of two Legendre series431`c1` / `c2`.  The arguments are sequences of coefficients from lowest432order "term" to highest, e.g., [1,2,3] represents the series433``P_0 + 2*P_1 + 3*P_2``.434 435Parameters436----------437c1, c2 : array_like438    1-D arrays of Legendre series coefficients ordered from low to439    high.440 441Returns442-------443quo, rem : ndarrays444    Of Legendre series coefficients representing the quotient and445    remainder.446 447See Also448--------449legadd, legsub, legmulx, legmul, legpow450 451Notes452-----453In general, the (polynomial) division of one Legendre series by another454results in quotient and remainder terms that are not in the Legendre455polynomial basis set.  Thus, to express these results as a Legendre456series, it is necessary to "reproject" the results onto the Legendre457basis set, which may produce "unintuitive" (but correct) results; see458Examples section below.459 460Examples461--------462>>> from numpy.polynomial import legendre as L463>>> c1 = (1,2,3)464>>> c2 = (3,2,1)465>>> L.legdiv(c1,c2) # quotient "intuitive," remainder not466(array([3.]), array([-8., -4.]))467>>> c2 = (0,1,2,3)468>>> L.legdiv(c2,c1) # neither "intuitive"469(array([-0.07407407,  1.66666667]), array([-1.03703704, -2.51851852])) # may vary470 471)r'�_divrrIs  r/rrs��\�7�7�6�2�"�"r0c�:�[R"[XU5$)a�Raise a Legendre series to a power.472 473Returns the Legendre series `c` raised to the power `pow`. The474argument `c` is a sequence of coefficients ordered from low to high.475i.e., [1,2,3] is the series  ``P_0 + 2*P_1 + 3*P_2.``476 477Parameters478----------479c : array_like480    1-D array of Legendre series coefficients ordered from low to481    high.482pow : integer483    Power to which the series will be raised484maxpower : integer, optional485    Maximum power allowed. This is mainly to limit growth of the series486    to unmanageable size. Default is 16487 488Returns489-------490coef : ndarray491    Legendre series of power.492 493See Also494--------495legadd, legsub, legmulx, legmul, legdiv496 497)r'�_powr)r9�pow�maxpowers   r/rrEs��8�7�7�6�1�8�,�,r0c�b�[R"USSS9nURRS;aUR	[R4985n[R"US5n[R"US5nUS:a[S5e[RRRXPR5nUS:XaU$[R"XS5n[U5nXF:�a	US	SS-nO�[U5H�nUS-499nX-n[R "U4UR"SS	-URS5009n[USS5H&n	SU	-S-501X	-X�S-502'X	S-503==X	-
ss'M( US:�aS
US-US'USUS'UnM� [R"USU5nU$)a�504Differentiate a Legendre series.505 506Returns the Legendre series coefficients `c` differentiated `m` times507along `axis`.  At each iteration the result is multiplied by `scl` (the508scaling factor is for use in a linear change of variable). The argument509`c` is an array of coefficients from low to high degree along each510axis, e.g., [1,2,3] represents the series ``1*L_0 + 2*L_1 + 3*L_2``511while [[1,2],[1,2]] represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) +5122*L_0(x)*L_1(y) + 2*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is513``y``.514 515Parameters516----------517c : array_like518    Array of Legendre series coefficients. If c is multidimensional the519    different axis correspond to different variables with the degree in520    each axis given by the corresponding index.521m : int, optional522    Number of derivatives taken, must be non-negative. (Default: 1)523scl : scalar, optional524    Each differentiation is multiplied by `scl`.  The end result is525    multiplication by ``scl**m``.  This is for use in a linear change of526    variable. (Default: 1)527axis : int, optional528    Axis over which the derivative is taken. (Default: 0).529 530Returns531-------532der : ndarray533    Legendre series of the derivative.534 535See Also536--------537legint538 539Notes540-----541In general, the result of differentiating a Legendre series does not542resemble the same operation on a power series. Thus the result of this543function may be "unintuitive," albeit correct; see Examples section544below.545 546Examples547--------548>>> from numpy.polynomial import legendre as L549>>> c = (1,2,3,4)550>>> L.legder(c)551array([  6.,   9.,  20.])552>>> L.legder(c, 3)553array([60.])554>>> L.legder(c, scl=-1)555array([ -6.,  -9., -20.])556>>> L.legder(c, 2,-1)557array([  9.,  60.])558 559rT��ndmin�copy�
?bBhHiIlLqQpPzthe order of derivation�the axisrz,The order of derivation must be non-negativeNrNr7r&r5)r@rArO�char�astype�doubler'�_as_int�560ValueError�lib�array_utils�normalize_axis_index�ndim�moveaxisr)r*rP�shape)561r9�mrC�axis�cnt�iaxisr:r.�derrRs562          r/rrds���t	����!�$�'�A��w�w�|�|��&�
�H�H�R�Y�Y���563�*�*�Q�1�5642�C��J�J�t�Z�(�E�565�Q�w��G�H�H��F�F���3�3�E�6�6�B�E�566�a�x���567���A�a� �A��A��A�568�x�
�b�q�E�A�I���s��A��A��A�
�H�A��(�(�A�4�!�'�'�!�"�+�-�Q�W�W�=�C��1�a��_���!�e�a�i�1�4�/���E�569��a�%��A�D� ��%��1�u��Q�q�T���A���q�T�C��F��A��	���A�q�%� �A��Hr0c	�<�[R"USSS9nURRS;aUR	[R5705n[R"U5(dU/n[R"US5n[R"US5nUS:a[S5e[U5U:�a[S	5e[R"U5S:wa[S5715e[R"U5S:wa[S5e[RRRXpR5nUS:XaU$[R"XS5n[!U5S/U[U5-572--n[#U5H�n[U5n	X-nU	S:Xa2[R$"USS:H5(aUS==X(-
ss'MJ[R&"U	S-4UR(SS-URS
9n573USS-U574S'USU575S'U	S:�aUSS-U576S'[#SU	5H&nXSU-S--nX�US-'X�S-577==U-ss'M( U578S==X([+X:5-579-
ss'U580nM� [R"USU5nU$)a.581Integrate a Legendre series.582 583Returns the Legendre series coefficients `c` integrated `m` times from584`lbnd` along `axis`. At each iteration the resulting series is585**multiplied** by `scl` and an integration constant, `k`, is added.586The scaling factor is for use in a linear change of variable.  ("Buyer587beware": note that, depending on what one is doing, one may want `scl`588to be the reciprocal of what one might expect; for more information,589see the Notes section below.)  The argument `c` is an array of590coefficients from low to high degree along each axis, e.g., [1,2,3]591represents the series ``L_0 + 2*L_1 + 3*L_2`` while [[1,2],[1,2]]592represents ``1*L_0(x)*L_0(y) + 1*L_1(x)*L_0(y) + 2*L_0(x)*L_1(y) +5932*L_1(x)*L_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.594 595Parameters596----------597c : array_like598    Array of Legendre series coefficients. If c is multidimensional the599    different axis correspond to different variables with the degree in600    each axis given by the corresponding index.601m : int, optional602    Order of integration, must be positive. (Default: 1)603k : {[], list, scalar}, optional604    Integration constant(s).  The value of the first integral at605    ``lbnd`` is the first value in the list, the value of the second606    integral at ``lbnd`` is the second value, etc.  If ``k == []`` (the607    default), all constants are set to zero.  If ``m == 1``, a single608    scalar can be given instead of a list.609lbnd : scalar, optional610    The lower bound of the integral. (Default: 0)611scl : scalar, optional612    Following each integration the result is *multiplied* by `scl`613    before the integration constant is added. (Default: 1)614axis : int, optional615    Axis over which the integral is taken. (Default: 0).616 617Returns618-------619S : ndarray620    Legendre series coefficient array of the integral.621 622Raises623------624ValueError625    If ``m < 0``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or626    ``np.ndim(scl) != 0``.627 628See Also629--------630legder631 632Notes633-----634Note that the result of each integration is *multiplied* by `scl`.635Why is this important to note?  Say one is making a linear change of636variable :math:`u = ax + b` in an integral relative to `x`.  Then637:math:`dx = du/a`, so one will need to set `scl` equal to638:math:`1/a` - perhaps not what one would have first thought.639 640Also note that, in general, the result of integrating a C-series needs641to be "reprojected" onto the C-series basis set.  Thus, typically,642the result of this function is "unintuitive," albeit correct; see643Examples section below.644 645Examples646--------647>>> from numpy.polynomial import legendre as L648>>> c = (1,2,3)649>>> L.legint(c)650array([ 0.33333333,  0.4       ,  0.66666667,  0.6       ]) # may vary651>>> L.legint(c, 3)652array([  1.66666667e-02,  -1.78571429e-02,   4.76190476e-02, # may vary653         -1.73472348e-18,   1.90476190e-02,   9.52380952e-03])654>>> L.legint(c, k=3)655 array([ 3.33333333,  0.4       ,  0.66666667,  0.6       ]) # may vary656>>> L.legint(c, lbnd=-2)657array([ 7.33333333,  0.4       ,  0.66666667,  0.6       ]) # may vary658>>> L.legint(c, scl=2)659array([ 0.66666667,  0.8       ,  1.33333333,  1.2       ]) # may vary660 661rTr_rbzthe order of integrationrcrz-The order of integration must be non-negativezToo many integration constantszlbnd must be a scalar.zscl must be a scalar.NrNr5r7)r@rArOrdrerf�iterabler'rgrhr)rlrirjrkrm�listr*�allrPrnr)
r9rorS�lbndrCrprqrrr.r:r=rR�ts
             r/rr�sH��f	����!�$�'�A��w�w�|�|��&�
�H�H�R�Y�Y���
�;�;�q�>�>�
�C��662�*�*�Q�2�6633�C��J�J�t�Z�(�E�664�Q�w��H�I�I�665�1�v��|��9�:�:�	�w�w�t�}����1�2�2�	�w�w�s�|�q���0�1�1��F�F���3�3�E�6�6�B�E�666�a�x���667���A�a� �A��Q��1�#��s�1�v��&�&�A�
�3�Z����F��	�����6�b�f�f�Q�q�T�Q�Y�'�'�
�a�D�A�D�L�D��(�(�A��E�8�a�g�g�a�b�k�1����A�C��q�T�A�X�C��F��q�T�C��F��1�u��1�����A���1�a�[���D�A��E�A�I�&���A��E�668���E�669�a��670�!�
��F�a�d�V�D�.�.�.�F��A�!�"	���A�q�%� �A��Hr0c���[R"USSS9nURRS;aUR	[R6715n[
U[[45(a[R"U5n[
U[R5(a2U(a+URURSUR--5n[U5S:XaUSnSnOx[U5S:XaUSnUSnO^[U5nUSnUS	n[S672[U5S-5H-nUnUS-673nX*XES-674U---675nXtU-SU-S-676U---nM/ X4U--$)av677Evaluate a Legendre series at points x.678 679If `c` is of length ``n + 1``, this function returns the value:680 681.. math:: p(x) = c_0 * L_0(x) + c_1 * L_1(x) + ... + c_n * L_n(x)682 683The parameter `x` is converted to an array only if it is a tuple or a684list, otherwise it is treated as a scalar. In either case, either `x`685or its elements must support multiplication and addition both with686themselves and with the elements of `c`.687 688If `c` is a 1-D array, then ``p(x)`` will have the same shape as `x`.  If689`c` is multidimensional, then the shape of the result depends on the690value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +691x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that692scalars have shape (,).693 694Trailing zeros in the coefficients will be used in the evaluation, so695they should be avoided if efficiency is a concern.696 697Parameters698----------699x : array_like, compatible object700    If `x` is a list or tuple, it is converted to an ndarray, otherwise701    it is left unchanged and treated as a scalar. In either case, `x`702    or its elements must support addition and multiplication with703    themselves and with the elements of `c`.704c : array_like705    Array of coefficients ordered so that the coefficients for terms of706    degree n are contained in c[n]. If `c` is multidimensional the707    remaining indices enumerate multiple polynomials. In the two708    dimensional case the coefficients may be thought of as stored in709    the columns of `c`.710tensor : boolean, optional711    If True, the shape of the coefficient array is extended with ones712    on the right, one for each dimension of `x`. Scalars have dimension 0713    for this action. The result is that every column of coefficients in714    `c` is evaluated for every element of `x`. If False, `x` is broadcast715    over the columns of `c` for the evaluation.  This keyword is useful716    when `c` is multidimensional. The default value is True.717 718Returns719-------720values : ndarray, algebra_like721    The shape of the return value is described above.722 723See Also724--------725legval2d, leggrid2d, legval3d, leggrid3d726 727Notes728-----729The evaluation uses Clenshaw recursion, aka synthetic division.730 731rNr_rb)rrr7r6r&r5)r@rArOrdrerf�732isinstance�tuplerv�asarray�ndarray�reshapernrlr)r*)�xr9�tensorr;r<rWr.r=s        r/rr<sF��r	����!�$�'�A��w�w�|�|��&�
�H�H�R�Y�Y����!�e�T�]�#�#��J�J�q�M���!�R�Z�Z� � �V�
�I�I�a�g�g��q�v�v�
�-�.��733�1�v��{�
�q�T��
��	�Q��1��
�q�T��
�q�T��
��V��
�r�U��
�r�U���q�#�a�&�1�*�%�A��C��a��B��2���Q��"�}�-�-�B��A�v�!�b�&�1�*��!2�3�3�B�	&�734�Q��;�r0c�:�[R"[X U5$)a�735Evaluate a 2-D Legendre series at points (x, y).736 737This function returns the values:738 739.. math:: p(x,y) = \sum_{i,j} c_{i,j} * L_i(x) * L_j(y)740 741The parameters `x` and `y` are converted to arrays only if they are742tuples or a lists, otherwise they are treated as a scalars and they743must have the same shape after conversion. In either case, either `x`744and `y` or their elements must support multiplication and addition both745with themselves and with the elements of `c`.746 747If `c` is a 1-D array a one is implicitly appended to its shape to make748it 2-D. The shape of the result will be c.shape[2:] + x.shape.749 750Parameters751----------752x, y : array_like, compatible objects753    The two dimensional series is evaluated at the points ``(x, y)``,754    where `x` and `y` must have the same shape. If `x` or `y` is a list755    or tuple, it is first converted to an ndarray, otherwise it is left756    unchanged and if it isn't an ndarray it is treated as a scalar.757c : array_like758    Array of coefficients ordered so that the coefficient of the term759    of multi-degree i,j is contained in ``c[i,j]``. If `c` has760    dimension greater than two the remaining indices enumerate multiple761    sets of coefficients.762 763Returns764-------765values : ndarray, compatible object766    The values of the two dimensional Legendre series at points formed767    from pairs of corresponding values from `x` and `y`.768 769See Also770--------771legval, leggrid2d, legval3d, leggrid3d772�r'�_valndr�r��yr9s   r/rr�s��P�9�9�V�Q�1�%�%r0c�:�[R"[X U5$)a,773Evaluate a 2-D Legendre series on the Cartesian product of x and y.774 775This function returns the values:776 777.. math:: p(a,b) = \sum_{i,j} c_{i,j} * L_i(a) * L_j(b)778 779where the points ``(a, b)`` consist of all pairs formed by taking780`a` from `x` and `b` from `y`. The resulting points form a grid with781`x` in the first dimension and `y` in the second.782 783The parameters `x` and `y` are converted to arrays only if they are784tuples or a lists, otherwise they are treated as a scalars. In either785case, either `x` and `y` or their elements must support multiplication786and addition both with themselves and with the elements of `c`.787 788If `c` has fewer than two dimensions, ones are implicitly appended to789its shape to make it 2-D. The shape of the result will be c.shape[2:] +790x.shape + y.shape.791 792Parameters793----------794x, y : array_like, compatible objects795    The two dimensional series is evaluated at the points in the796    Cartesian product of `x` and `y`.  If `x` or `y` is a list or797    tuple, it is first converted to an ndarray, otherwise it is left798    unchanged and, if it isn't an ndarray, it is treated as a scalar.799c : array_like800    Array of coefficients ordered so that the coefficient of the term of801    multi-degree i,j is contained in ``c[i,j]``. If `c` has dimension802    greater than two the remaining indices enumerate multiple sets of803    coefficients.804 805Returns806-------807values : ndarray, compatible object808    The values of the two dimensional Chebyshev series at points in the809    Cartesian product of `x` and `y`.810 811See Also812--------813legval, legval2d, legval3d, leggrid3d814�r'�_gridndrr�s   r/rr�s��X�:�:�f�a�A�&�&r0c�:�[R"[X0X5$)a�815Evaluate a 3-D Legendre series at points (x, y, z).816 817This function returns the values:818 819.. math:: p(x,y,z) = \sum_{i,j,k} c_{i,j,k} * L_i(x) * L_j(y) * L_k(z)820 821The parameters `x`, `y`, and `z` are converted to arrays only if822they are tuples or a lists, otherwise they are treated as a scalars and823they must have the same shape after conversion. In either case, either824`x`, `y`, and `z` or their elements must support multiplication and825addition both with themselves and with the elements of `c`.826 827If `c` has fewer than 3 dimensions, ones are implicitly appended to its828shape to make it 3-D. The shape of the result will be c.shape[3:] +829x.shape.830 831Parameters832----------833x, y, z : array_like, compatible object834    The three dimensional series is evaluated at the points835    ``(x, y, z)``, where `x`, `y`, and `z` must have the same shape.  If836    any of `x`, `y`, or `z` is a list or tuple, it is first converted837    to an ndarray, otherwise it is left unchanged and if it isn't an838    ndarray it is  treated as a scalar.839c : array_like840    Array of coefficients ordered so that the coefficient of the term of841    multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension842    greater than 3 the remaining indices enumerate multiple sets of843    coefficients.844 845Returns846-------847values : ndarray, compatible object848    The values of the multidimensional polynomial on points formed with849    triples of corresponding values from `x`, `y`, and `z`.850 851See Also852--------853legval, legval2d, leggrid2d, leggrid3d854r��r�r��zr9s    r/rr�s��T�9�9�V�Q�1�(�(r0c�:�[R"[X0X5$)a�855Evaluate a 3-D Legendre series on the Cartesian product of x, y, and z.856 857This function returns the values:858 859.. math:: p(a,b,c) = \sum_{i,j,k} c_{i,j,k} * L_i(a) * L_j(b) * L_k(c)860 861where the points ``(a, b, c)`` consist of all triples formed by taking862`a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form863a grid with `x` in the first dimension, `y` in the second, and `z` in864the third.865 866The parameters `x`, `y`, and `z` are converted to arrays only if they867are tuples or a lists, otherwise they are treated as a scalars. In868either case, either `x`, `y`, and `z` or their elements must support869multiplication and addition both with themselves and with the elements870of `c`.871 872If `c` has fewer than three dimensions, ones are implicitly appended to873its shape to make it 3-D. The shape of the result will be c.shape[3:] +874x.shape + y.shape + z.shape.875 876Parameters877----------878x, y, z : array_like, compatible objects879    The three dimensional series is evaluated at the points in the880    Cartesian product of `x`, `y`, and `z`.  If `x`, `y`, or `z` is a881    list or tuple, it is first converted to an ndarray, otherwise it is882    left unchanged and, if it isn't an ndarray, it is treated as a883    scalar.884c : array_like885    Array of coefficients ordered so that the coefficients for terms of886    degree i,j are contained in ``c[i,j]``. If `c` has dimension887    greater than two the remaining indices enumerate multiple sets of888    coefficients.889 890Returns891-------892values : ndarray, compatible object893    The values of the two dimensional polynomial at points in the Cartesian894    product of `x` and `y`.895 896See Also897--------898legval, legval2d, leggrid2d, legval3d899r�r�s    r/rrs��^�:�:�f�a�A�)�)r0c��[R"US5nUS:a[S5e[R"USSS9S-nUS-4UR900-nURn[R"X4S9nUS-S-US'US:�a@XS'[S	US-5H)nXVS-901U-S	U-S-902-XVS	-903US-904--905U-XV'M+ [R"USS9065$)a�Pseudo-Vandermonde matrix of given degree.907 908Returns the pseudo-Vandermonde matrix of degree `deg` and sample points909`x`. The pseudo-Vandermonde matrix is defined by910 911.. math:: V[..., i] = L_i(x)912 913where ``0 <= i <= deg``. The leading indices of `V` index the elements of914`x` and the last index is the degree of the Legendre polynomial.915 916If `c` is a 1-D array of coefficients of length ``n + 1`` and `V` is the917array ``V = legvander(x, n)``, then ``np.dot(V, c)`` and918``legval(x, c)`` are the same up to roundoff. This equivalence is919useful both for least squares fitting and for the evaluation of a large920number of Legendre series of the same degree and sample points.921 922Parameters923----------924x : array_like925    Array of points. The dtype is converted to float64 or complex128926    depending on whether any of the elements are complex. If `x` is927    scalar it is converted to a 1-D array.928deg : int929    Degree of the resulting matrix.930 931Returns932-------933vander : ndarray934    The pseudo-Vandermonde matrix. The shape of the returned matrix is935    ``x.shape + (deg + 1,)``, where The last index is the degree of the936    corresponding Legendre polynomial.  The dtype will be the same as937    the converted `x`.938 939r,rzdeg must be non-negativeNr)rar`�rNr7r&)940r'rgrhr@rArnrOrPr*rm)r�r,�ideg�dims�dtyp�vr.s       r/rrHs���F�:�:�c�5�!�D��a�x��3�4�4�941�����Q�'�#�-�A��1�H�;���� �D��7�7�D�942����"�A�
�q�5�1�9�A�a�D��a�x��!���q�$��(�#�A��!�e�H�q�L�A��E�A�I�.��q�5��Q��U�1C�C�q�H�A�D�$�
�;�;�q�!�R� � r0c�H�[R"[[4X4U5$)a�Pseudo-Vandermonde matrix of given degrees.943 944Returns the pseudo-Vandermonde matrix of degrees `deg` and sample945points ``(x, y)``. The pseudo-Vandermonde matrix is defined by946 947.. math:: V[..., (deg[1] + 1)*i + j] = L_i(x) * L_j(y),948 949where ``0 <= i <= deg[0]`` and ``0 <= j <= deg[1]``. The leading indices of950`V` index the points ``(x, y)`` and the last index encodes the degrees of951the Legendre polynomials.952 953If ``V = legvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`954correspond to the elements of a 2-D coefficient array `c` of shape955(xdeg + 1, ydeg + 1) in the order956 957.. math:: c_{00}, c_{01}, c_{02}, ... , c_{10}, c_{11}, c_{12}, ...958 959and ``np.dot(V, c.flat)`` and ``legval2d(x, y, c)`` will be the same960up to roundoff. This equivalence is useful both for least squares961fitting and for the evaluation of a large number of 2-D Legendre962series of the same degrees and sample points.963 964Parameters965----------966x, y : array_like967    Arrays of point coordinates, all of the same shape. The dtypes968    will be converted to either float64 or complex128 depending on969    whether any of the elements are complex. Scalars are converted to970    1-D arrays.971deg : list of ints972    List of maximum degrees of the form [x_deg, y_deg].973 974Returns975-------976vander2d : ndarray977    The shape of the returned matrix is ``x.shape + (order,)``, where978    :math:`order = (deg[0]+1)*(deg[1]+1)`.  The dtype will be the same979    as the converted `x` and `y`.980 981See Also982--------983legvander, legvander3d, legval2d, legval3d984�r'�_vander_nd_flatr)r�r�r,s   r/r r }s!��X���y�)�4�q�f�c�B�Br0c�T�[R"[[[4XU4U5$)alPseudo-Vandermonde matrix of given degrees.985 986Returns the pseudo-Vandermonde matrix of degrees `deg` and sample987points ``(x, y, z)``. If `l`, `m`, `n` are the given degrees in `x`, `y`, `z`,988then The pseudo-Vandermonde matrix is defined by989 990.. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = L_i(x)*L_j(y)*L_k(z),991 992where ``0 <= i <= l``, ``0 <= j <= m``, and ``0 <= j <= n``.  The leading993indices of `V` index the points ``(x, y, z)`` and the last index encodes994the degrees of the Legendre polynomials.995 996If ``V = legvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns997of `V` correspond to the elements of a 3-D coefficient array `c` of998shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order999 1000.. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...1001 1002and ``np.dot(V, c.flat)`` and ``legval3d(x, y, z, c)`` will be the1003same up to roundoff. This equivalence is useful both for least squares1004fitting and for the evaluation of a large number of 3-D Legendre1005series of the same degrees and sample points.1006 1007Parameters1008----------1009x, y, z : array_like1010    Arrays of point coordinates, all of the same shape. The dtypes will1011    be converted to either float64 or complex128 depending on whether1012    any of the elements are complex. Scalars are converted to 1-D1013    arrays.1014deg : list of ints1015    List of maximum degrees of the form [x_deg, y_deg, z_deg].1016 1017Returns1018-------1019vander3d : ndarray1020    The shape of the returned matrix is ``x.shape + (order,)``, where1021    :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`.  The dtype will1022    be the same as the converted `x`, `y`, and `z`.1023 1024See Also1025--------1026legvander, legvander3d, legval2d, legval3d1027r�)r�r�r�r,s    r/r!r!�s%��Z���y�)�Y�?�!���C�P�Pr0c	�<�[R"[XX#XE5$)a1028Least squares fit of Legendre series to data.1029 1030Return the coefficients of a Legendre series of degree `deg` that is the1031least squares fit to the data values `y` given at points `x`. If `y` is10321-D the returned coefficients will also be 1-D. If `y` is 2-D multiple1033fits are done, one for each column of `y`, and the resulting1034coefficients are stored in the corresponding columns of a 2-D return.1035The fitted polynomial(s) are in the form1036 1037.. math::  p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x),1038 1039where `n` is `deg`.1040 1041Parameters1042----------1043x : array_like, shape (M,)1044    x-coordinates of the M sample points ``(x[i], y[i])``.1045y : array_like, shape (M,) or (M, K)1046    y-coordinates of the sample points. Several data sets of sample1047    points sharing the same x-coordinates can be fitted at once by1048    passing in a 2D-array that contains one dataset per column.1049deg : int or 1-D array_like1050    Degree(s) of the fitting polynomials. If `deg` is a single integer1051    all terms up to and including the `deg`'th term are included in the1052    fit. For NumPy versions >= 1.11.0 a list of integers specifying the1053    degrees of the terms to include may be used instead.1054rcond : float, optional1055    Relative condition number of the fit. Singular values smaller than1056    this relative to the largest singular value will be ignored. The1057    default value is len(x)*eps, where eps is the relative precision of1058    the float type, about 2e-16 in most cases.1059full : bool, optional1060    Switch determining nature of return value. When it is False (the1061    default) just the coefficients are returned, when True diagnostic1062    information from the singular value decomposition is also returned.1063w : array_like, shape (`M`,), optional1064    Weights. If not None, the weight ``w[i]`` applies to the unsquared1065    residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are1066    chosen so that the errors of the products ``w[i]*y[i]`` all have the1067    same variance.  When using inverse-variance weighting, use1068    ``w[i] = 1/sigma(y[i])``.  The default value is None.1069 1070Returns1071-------1072coef : ndarray, shape (M,) or (M, K)1073    Legendre coefficients ordered from low to high. If `y` was1074    2-D, the coefficients for the data in column k of `y` are in1075    column `k`. If `deg` is specified as a list, coefficients for1076    terms not included in the fit are set equal to zero in the1077    returned `coef`.1078 1079[residuals, rank, singular_values, rcond] : list1080    These values are only returned if ``full == True``1081 1082    - residuals -- sum of squared residuals of the least squares fit1083    - rank -- the numerical rank of the scaled Vandermonde matrix1084    - singular_values -- singular values of the scaled Vandermonde matrix1085    - rcond -- value of `rcond`.1086 1087    For more details, see `numpy.linalg.lstsq`.1088 1089Warns1090-----1091RankWarning1092    The rank of the coefficient matrix in the least-squares fit is1093    deficient. The warning is only raised if ``full == False``.  The1094    warnings can be turned off by1095 1096    >>> import warnings1097    >>> warnings.simplefilter('ignore', np.exceptions.RankWarning)1098 1099See Also1100--------1101numpy.polynomial.polynomial.polyfit1102numpy.polynomial.chebyshev.chebfit1103numpy.polynomial.laguerre.lagfit1104numpy.polynomial.hermite.hermfit1105numpy.polynomial.hermite_e.hermefit1106legval : Evaluates a Legendre series.1107legvander : Vandermonde matrix of Legendre series.1108legweight : Legendre weight function (= 1).1109numpy.linalg.lstsq : Computes a least-squares fit from the matrix.1110scipy.interpolate.UnivariateSpline : Computes spline fits.1111 1112Notes1113-----1114The solution is the coefficients of the Legendre series `p` that1115minimizes the sum of the weighted squared errors1116 1117.. math:: E = \sum_j w_j^2 * |y_j - p(x_j)|^2,1118 1119where :math:`w_j` are the weights. This problem is solved by setting up1120as the (typically) overdetermined matrix equation1121 1122.. math:: V(x) * c = w * y,1123 1124where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the1125coefficients to be solved for, `w` are the weights, and `y` are the1126observed values.  This equation is then solved using the singular value1127decomposition of `V`.1128 1129If some of the singular values of `V` are so small that they are1130neglected, then a `~exceptions.RankWarning` will be issued. This means that1131the coefficient values may be poorly determined. Using a lower order fit1132will usually get rid of the warning.  The `rcond` parameter can also be1133set to a value smaller than its default, but the resulting fit may be1134spurious and have large contributions from roundoff error.1135 1136Fits using Legendre series are usually better conditioned than fits1137using power series, but much can depend on the distribution of the1138sample points and the smoothness of the data. If the quality of the fit1139is inadequate splines may be a good alternative.1140 1141References1142----------1143.. [1] Wikipedia, "Curve fitting",1144       https://en.wikipedia.org/wiki/Curve_fitting1145 1146Examples1147--------1148 1149)r'�_fitr)r�r�r,�rcond�full�ws      r/rr�s��x�7�7�9�a�C��8�8r0c��[R"U/5un[U5S:a[S5e[U5S:Xa"[R1150"US*US-//5$[U5S-1151n[R"X4URS9nS[R"S[R"U5-S-5-nURS5SSUS-2nURS5USUS-2n[R"SU5USUS-1152-USU-US	'XES	'USS2S4==USSUS-X3S--USU-S-1153---ss'U$)1154a%Return the scaled companion matrix of c.1155 1156The basis polynomials are scaled so that the companion matrix is1157symmetric when `c` is an Legendre basis polynomial. This provides1158better eigenvalue estimates than the unscaled case and for basis1159polynomials the eigenvalues are guaranteed to be real if1160`numpy.linalg.eigvalsh` is used to obtain them.1161 1162Parameters1163----------1164c : array_like1165    1-D array of Legendre series coefficients ordered from low to high1166    degree.1167 1168Returns1169-------1170mat : ndarray1171    Scaled companion matrix of dimensions (deg, deg).1172r7z.Series must have maximum degree of at least 1.rrrNr>r&N.)r'r(r)rhr@rA�zerosrO�sqrt�aranger)r9r:�matrC�top�bots      r/r"r"[sO��*
�,�,��s�1173�C�Q�1174�1�v��z��I�J�J�1175�1�v��{��x�x�1�Q�4�%�!�A�$�,��(�)�)��A���1176�A�1177�(�(�A�6����1178)�C�1179�r�w�w�q�2�9�9�Q�<�'�!�+�,�1180,�C�1181
�+�+�b�/�!�(�Q��U�(�1182#�C�1183
�+�+�b�/�!�(�Q��U�(�1184#�C��y�y��A���V�a�!�e��,�s�1�Q�x�7�C��H���H���2��J�1�S�b�6�A�b�E�>�c��G�m�4��Q��U�Q�Y��H�H�J��Jr0c�~�[R"U/5un[U5S:a[R"/UR1185S9$[U5S:Xa![R"US*US-/5$[
U5SSS2SSS24n[RRU5nUR5 U$)a?1186Compute the roots of a Legendre series.1187 1188Return the roots (a.k.a. "zeros") of the polynomial1189 1190.. math:: p(x) = \sum_i c[i] * L_i(x).1191 1192Parameters1193----------1194c : 1-D array_like1195    1-D array of coefficients.1196 1197Returns1198-------1199out : ndarray1200    Array of the roots of the series. If all the roots are real,

Showing the first 1,200 of 1323 lines. Download the file for the rest.

codekingpro/portable-devtools · Team Ai