§ <ˆj^É ã óª — d Z ddlZddlmZ ddlmZ ddlm Z ddlmZ g d¢Z e j Zd„ Zd „ Z ej d dg¦ « Z ej dg¦ « Z ej dg¦ « Z ej ddg¦ « Zd„ Zd„ Zd „ Zd„ Zd„ Zd„ Zd„ Zd'd„Zd(d„Zdg dddfd„Z d)d„Z!d„ Z"d„ Z#d„ Z$d„ Z%d„ Z&d„ Z'd„ Z(d*d „Z)d!„ Z*d"„ Z+d#„ Z,d$„ Z- G d%„ d&e¦ « Z.dS )+aÁ ================================================== Legendre Series (:mod:`numpy.polynomial.legendre`) ================================================== 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`). Classes ------- .. autosummary:: :toctree: generated/ Legendre Constants --------- .. autosummary:: :toctree: generated/ legdomain legzero legone legx Arithmetic ---------- .. autosummary:: :toctree: generated/ legadd legsub legmulx legmul legdiv legpow legval legval2d legval3d leggrid2d leggrid3d Calculus -------- .. autosummary:: :toctree: generated/ legder legint Misc Functions -------------- .. autosummary:: :toctree: generated/ legfromroots legroots legvander legvander2d legvander3d leggauss legweight legcompanion legfit legtrim legline leg2poly poly2leg See also -------- numpy.polynomial é N)Únormalize_axis_indexé )Ú 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 óÊ — t j | g¦ « \ } t | ¦ « dz }d}t |dd¦ « D ]%}t t |¦ « | | ¦ « }Œ&|S )a. 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]) # may vary r r éÿÿÿÿ)ÚpuÚ as_seriesÚlenÚranger r )ÚpolÚdegÚresÚis úP/opt/cloudlinux/venv/lib64/python3.11/site-packages/numpy/polynomial/legendre.pyr r d sg € õP ŒL˜#˜ÑÔ�E€SÝ ˆc‰(Œ(�Q‰,€CØ €CÝ �3˜˜BÑ Ô ð +ð +ˆÝ•W˜S‘\”\ 3 q¤6Ñ*Ô*ˆˆØ€Jó c ól — ddl m}m}m} t j | g¦ « \ } t | ¦ « }|dk r| S | d }| d }t |dz dd¦ « D ]C}|} || |dz ||dz z |z ¦ « } || ||¦ « d|z dz z |z ¦ « }ŒD || ||¦ « ¦ « S )aã 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 -------- >>> from numpy import polynomial as P >>> c = P.Legendre(range(4)) >>> c Legendre([0., 1., 2., 3.], domain=[-1, 1], window=[-1, 1]) >>> p = c.convert(kind=P.Polynomial) >>> p Polynomial([-1. , -3.5, 3. , 7.5], domain=[-1., 1.], window=[-1., 1.]) >>> P.legendre.leg2poly(range(4)) array([-1. , -3.5, 3. , 7.5]) r )ÚpolyaddÚpolysubÚpolymulxé éþÿÿÿr' é )Ú polynomialr3 r4 r5 r( r) r* r+ ) Úcr3 r4 r5 ÚnÚc0Úc1r/ Útmps r0 r r ” sñ € ðZ 7Ð6Ð6Ð6Ð6Ð6Ð6Ð6Ð6Ð6å Œ,˜�sÑ Ô �C€Q݈A‰Œ€A؈1‚u€uØˆà ˆrŒUˆØ ˆrŒUˆå�q˜1‘u˜a Ñ$Ô$ð :ð :ˆA؈CØ�˜˜1˜q™5œ B¨¨A©¡J°¡>Ñ2Ô2ˆBØ�˜˜x˜x¨™|œ|¨Q¨q©S°1©WÑ5°qÑ8Ñ9Ô9ˆBˆB؈w�r˜8˜8 B™<œ<Ñ(Ô(Ð(r1 r' c ód — |dk rt j | |g¦ « S t j | g¦ « S )a¼ 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 -------- numpy.polynomial.polynomial.polyline numpy.polynomial.chebyshev.chebline numpy.polynomial.laguerre.lagline numpy.polynomial.hermite.hermline numpy.polynomial.hermite_e.hermeline 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 r )ÚnpÚarray)ÚoffÚscls r0 r r ã s2 € ðD ˆa‚x€xÝŒx˜˜c˜ Ñ#Ô#Ð#åŒx˜˜‰ŒÐr1 c óB — t j t t | ¦ « S )a¨ Generate a Legendre series with given roots. The function returns the coefficients of the polynomial .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n), in Legendre form, where the `r_n` are the roots specified in `roots`. If a zero has multiplicity n, then it must appear in `roots` n times. For instance, if 2 is a root of multiplicity three and 3 is a root of multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The roots can appear in any order. If the returned coefficients are `c`, then .. math:: p(x) = c_0 + c_1 * L_1(x) + ... + c_n * L_n(x) The coefficient of the last term is not generally 1 for monic polynomials in Legendre form. Parameters ---------- roots : array_like Sequence containing the roots. Returns ------- out : ndarray 1-D array of coefficients. If all roots are real then `out` is a real array, if some of the roots are complex, then `out` is complex even if all the coefficients in the result are real (see Examples below). See Also -------- numpy.polynomial.polynomial.polyfromroots numpy.polynomial.chebyshev.chebfromroots numpy.polynomial.laguerre.lagfromroots numpy.polynomial.hermite.hermfromroots numpy.polynomial.hermite_e.hermefromroots Examples -------- >>> 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]) # may vary )r( Ú _fromrootsr r )Úrootss r0 r r s € õh Œ=�¥&¨%Ñ0Ô0Ð0r1 c ó, — t j | |¦ « S )aú 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, legmulx, 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( Ú_add©r= Úc2s r0 r r B s € õN Œ7�2�r‰?Œ?Ðr1 c ó, — t j | |¦ « S )aQ 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, legmulx, 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( Ú_subrI s r0 r r l s € õR Œ7�2�r‰?Œ?Ðr1 c ó¶ — t j | g¦ « \ } t | ¦ « dk r| d dk r| S t j t | ¦ « dz | j ¬¦ « }| d dz |d<