summaryrefslogtreecommitdiff
path: root/numpy/polynomial
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/polynomial')
-rw-r--r--numpy/polynomial/hermite.py170
-rw-r--r--numpy/polynomial/hermite_e.py171
-rw-r--r--numpy/polynomial/laguerre.py169
3 files changed, 263 insertions, 247 deletions
diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py
index 550e316de..d266a6453 100644
--- a/numpy/polynomial/hermite.py
+++ b/numpy/polynomial/hermite.py
@@ -96,13 +96,9 @@ def poly2herm(pol) :
Examples
--------
- >>> from numpy import polynomial as P
- >>> p = P.Polynomial(np.arange(4))
- >>> p
- Polynomial([ 0., 1., 2., 3.], [-1., 1.])
- >>> c = P.Hermite(P.poly2herm(p.coef))
- >>> c
- Hermite([ 1. , 3.25, 1. , 0.75], [-1., 1.])
+ >>> from numpy.polynomial.hermite_e import poly2herme
+ >>> poly2herm(np.arange(4))
+ array([ 1. , 2.75 , 0.5 , 0.375])
"""
[pol] = pu.as_series([pol])
@@ -146,15 +142,9 @@ def herm2poly(cs) :
Examples
--------
- >>> c = P.Hermite(range(4))
- >>> c
- Hermite([ 0., 1., 2., 3.], [-1., 1.])
- >>> p = c.convert(kind=P.Polynomial)
- >>> p
- Polynomial([-1. , -3.5, 3. , 7.5], [-1., 1.])
- >>> P.herm2poly(range(4))
- array([-1. , -3.5, 3. , 7.5])
-
+ >>> from numpy.polynomial.hermite import herm2poly
+ >>> herm2poly([ 1. , 2.75 , 0.5 , 0.375])
+ array([ 0., 1., 2., 3.])
"""
from polynomial import polyadd, polysub, polymulx
@@ -217,11 +207,11 @@ def hermline(off, scl) :
Examples
--------
- >>> import numpy.polynomial.legendre as L
- >>> L.hermline(3,2)
- array([3, 2])
- >>> L.hermval(-3, L.hermline(3,2)) # should be -3
- -3.0
+ >>> from numpy.polynomial.hermite import hermline, hermval
+ >>> hermval(0,hermline(3, 2))
+ 3.0
+ >>> hermval(1,hermline(3, 2))
+ 5.0
"""
if scl != 0 :
@@ -274,12 +264,13 @@ def hermfromroots(roots) :
Examples
--------
- >>> import numpy.polynomial.legendre as L
- >>> L.hermfromroots((-1,0,1)) # x^3 - x relative to the standard basis
- array([ 0. , -0.4, 0. , 0.4])
- >>> j = complex(0,1)
- >>> L.hermfromroots((-j,j)) # x^2 + 1 relative to the standard basis
- array([ 1.33333333+0.j, 0.00000000+0.j, 0.66666667+0.j])
+ >>> from numpy.polynomial.hermite import hermfromroots, hermval
+ >>> coef = hermfromroots((-1, 0, 1))
+ >>> hermval((-1, 0, 1), coef)
+ array([ 0., 0., 0.])
+ >>> coef = hermfromroots((-1j, 1j))
+ >>> hermval((-1j, 1j), coef)
+ array([ 0.+0.j, 0.+0.j])
"""
if len(roots) == 0 :
@@ -324,11 +315,9 @@ def hermadd(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.hermadd(c1,c2)
- array([ 4., 4., 4.])
+ >>> from numpy.polynomial.hermite import hermadd
+ >>> hermadd([1, 2, 3], [1, 2, 3, 4])
+ array([ 2., 4., 6., 4.])
"""
# c1, c2 are trimmed copies
@@ -374,13 +363,9 @@ def hermsub(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.hermsub(c1,c2)
- array([-2., 0., 2.])
- >>> L.hermsub(c2,c1) # -C.hermsub(c1,c2)
- array([ 2., 0., -2.])
+ >>> from numpy.polynomial.hermite import hermsub
+ >>> hermsub([1, 2, 3, 4], [1, 2, 3])
+ array([ 0., 0., 0., 4.])
"""
# c1, c2 are trimmed copies
@@ -420,7 +405,13 @@ def hermmulx(cs):
.. math::
- xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
+ xP_i(x) = (P_{i + 1}(x)/2 + i*P_{i - 1}(x))
+
+ Examples
+ --------
+ >>> from numpy.polynomial.hermite import hermmulx
+ >>> hermmulx([1, 2, 3])
+ array([ 2. , 6.5, 1. , 1.5])
"""
# cs is a trimmed copy
@@ -471,11 +462,9 @@ def hermmul(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2)
- >>> P.hermmul(c1,c2) # multiplication requires "reprojection"
- array([ 4.33333333, 10.4 , 11.66666667, 3.6 ])
+ >>> from numpy.polynomial.hermite import hermmul
+ >>> hermmul([1, 2, 3], [0, 1, 2])
+ array([ 52., 29., 52., 7., 6.])
"""
# s1, s2 are trimmed copies
@@ -542,14 +531,13 @@ def hermdiv(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.hermdiv(c1,c2) # quotient "intuitive," remainder not
- (array([ 3.]), array([-8., -4.]))
- >>> c2 = (0,1,2,3)
- >>> L.hermdiv(c2,c1) # neither "intuitive"
- (array([-0.07407407, 1.66666667]), array([-1.03703704, -2.51851852]))
+ >>> from numpy.polynomial.hermite import hermdiv
+ >>> hermdiv([ 52., 29., 52., 7., 6.], [0, 1, 2])
+ (array([ 1., 2., 3.]), array([ 0.]))
+ >>> hermdiv([ 54., 31., 52., 7., 6.], [0, 1, 2])
+ (array([ 1., 2., 3.]), array([ 2., 2.]))
+ >>> hermdiv([ 53., 30., 52., 7., 6.], [0, 1, 2])
+ (array([ 1., 2., 3.]), array([ 1., 1.]))
"""
# c1, c2 are trimmed copies
@@ -603,6 +591,9 @@ def hermpow(cs, pow, maxpower=16) :
Examples
--------
+ >>> from numpy.polynomial.hermite import hermpow
+ >>> hermpow([1, 2, 3], 2)
+ array([ 81., 52., 82., 12., 9.])
"""
# cs is a trimmed copy
@@ -664,16 +655,11 @@ def hermder(cs, m=1, scl=1) :
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> cs = (1,2,3,4)
- >>> L.hermder(cs)
- array([ 6., 9., 20.])
- >>> L.hermder(cs,3)
- array([ 60.])
- >>> L.hermder(cs,scl=-1)
- array([ -6., -9., -20.])
- >>> L.hermder(cs,2,-1)
- array([ 9., 60.])
+ >>> from numpy.polynomial.hermite import hermder
+ >>> hermder([ 1. , 0.5, 0.5, 0.5])
+ array([ 1., 2., 3.])
+ >>> hermder([-0.5, 1./2., 1./8., 1./12., 1./16.], m=2)
+ array([ 1., 2., 3.])
"""
cnt = int(m)
@@ -762,19 +748,17 @@ def hermint(cs, m=1, k=[], lbnd=0, scl=1):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> cs = (1,2,3)
- >>> L.hermint(cs)
- array([ 0.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.hermint(cs,3)
- array([ 1.66666667e-02, -1.78571429e-02, 4.76190476e-02,
- -1.73472348e-18, 1.90476190e-02, 9.52380952e-03])
- >>> L.hermint(cs, k=3)
- array([ 3.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.hermint(cs, lbnd=-2)
- array([ 7.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.hermint(cs, scl=2)
- array([ 0.66666667, 0.8 , 1.33333333, 1.2 ])
+ >>> from numpy.polynomial.hermite import hermint
+ >>> hermint([1,2,3]) # integrate once, value 0 at 0.
+ array([ 1. , 0.5, 0.5, 0.5])
+ >>> hermint([1,2,3], m=2) # integrate twice, value & deriv 0 at 0
+ array([-0.5 , 0.5 , 0.125 , 0.08333333, 0.0625 ])
+ >>> hermint([1,2,3], k=1) # integrate once, value 1 at 0.
+ array([ 2. , 0.5, 0.5, 0.5])
+ >>> hermint([1,2,3], lbnd=-1) # integrate once, value 0 at -1
+ array([-2. , 0.5, 0.5, 0.5])
+ >>> hermint([1,2,3], m=2, k=[1,2], lbnd=-1)
+ array([ 1.66666667, -0.5 , 0.125 , 0.08333333, 0.0625 ])
"""
cnt = int(m)
@@ -847,6 +831,13 @@ def hermval(x, cs):
Examples
--------
+ >>> from numpy.polynomial.hermite import hermval
+ >>> coef = [1,2,3]
+ >>> hermval(1, coef)
+ 11.0
+ >>> hermval([[1,2],[3,4]], coef)
+ array([[ 11., 51.],
+ [ 115., 203.]])
"""
# cs is a trimmed copy
@@ -897,6 +888,15 @@ def hermvander(x, deg) :
The shape of the returned matrix is ``x.shape + (deg+1,)``. The last
index is the degree.
+ Examples
+ --------
+ >>> from numpy.polynomial.hermite import hermvander
+ >>> x = np.array([-1, 0, 1])
+ >>> hermvander(x, 3)
+ array([[ 1., -2., 2., 4.],
+ [ 1., 0., -2., -0.],
+ [ 1., 2., 2., -4.]])
+
"""
ideg = int(deg)
if ideg != deg:
@@ -1015,6 +1015,12 @@ def hermfit(x, y, deg, rcond=None, full=False, w=None):
Examples
--------
+ >>> from numpy.polynomial.hermite import hermfit, hermval
+ >>> x = np.linspace(-10, 10)
+ >>> err = np.random.randn(len(x))/10
+ >>> y = hermval(x, [1, 2, 3]) + err
+ >>> hermfit(x, y, 2)
+ array([ 0.97902637, 1.99849131, 3.00006 ])
"""
order = int(deg) + 1
@@ -1104,12 +1110,12 @@ def hermroots(cs):
Examples
--------
- >>> import numpy.polynomial as P
- >>> P.polyroots((1, 2, 3, 4)) # 4x^3 + 3x^2 + 2x + 1 has two complex roots
- array([-0.60582959+0.j , -0.07208521-0.63832674j,
- -0.07208521+0.63832674j])
- >>> P.hermroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0 has only real roots
- array([-0.85099543, -0.11407192, 0.51506735])
+ >>> from numpy.polynomial.hermite import hermroots, hermfromroots
+ >>> coef = hermfromroots([-1, 0, 1])
+ >>> coef
+ array([ 0. , 0.25 , 0. , 0.125])
+ >>> hermroots(coef)
+ array([ -1.00000000e+00, -1.38777878e-17, 1.00000000e+00])
"""
# cs is a trimmed copy
diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py
index df0ff4e5e..ecb4bc3c3 100644
--- a/numpy/polynomial/hermite_e.py
+++ b/numpy/polynomial/hermite_e.py
@@ -96,13 +96,9 @@ def poly2herme(pol) :
Examples
--------
- >>> from numpy import polynomial as P
- >>> p = P.Polynomial(np.arange(4))
- >>> p
- Polynomial([ 0., 1., 2., 3.], [-1., 1.])
- >>> c = P.Hermite(P.poly2herme(p.coef))
- >>> c
- Hermite([ 1. , 3.25, 1. , 0.75], [-1., 1.])
+ >>> from numpy.polynomial.hermite_e import poly2herme
+ >>> poly2herme(np.arange(4))
+ array([ 2., 10., 2., 3.])
"""
[pol] = pu.as_series([pol])
@@ -146,15 +142,9 @@ def herme2poly(cs) :
Examples
--------
- >>> c = P.Hermite(range(4))
- >>> c
- Hermite([ 0., 1., 2., 3.], [-1., 1.])
- >>> p = c.convert(kind=P.Polynomial)
- >>> p
- Polynomial([-1. , -3.5, 3. , 7.5], [-1., 1.])
- >>> P.herme2poly(range(4))
- array([-1. , -3.5, 3. , 7.5])
-
+ >>> from numpy.polynomial.hermite_e import herme2poly
+ >>> herme2poly([ 2., 10., 2., 3.])
+ array([ 0., 1., 2., 3.])
"""
from polynomial import polyadd, polysub, polymulx
@@ -216,11 +206,12 @@ def hermeline(off, scl) :
Examples
--------
- >>> import numpy.polynomial.legendre as L
- >>> L.hermeline(3,2)
- array([3, 2])
- >>> L.hermeval(-3, L.hermeline(3,2)) # should be -3
- -3.0
+ >>> from numpy.polynomial.hermite_e import hermeline
+ >>> from numpy.polynomial.hermite_e import hermeline, hermeval
+ >>> hermeval(0,hermeline(3, 2))
+ 3.0
+ >>> hermeval(1,hermeline(3, 2))
+ 5.0
"""
if scl != 0 :
@@ -273,12 +264,13 @@ def hermefromroots(roots) :
Examples
--------
- >>> import numpy.polynomial.legendre as L
- >>> L.hermefromroots((-1,0,1)) # x^3 - x relative to the standard basis
- array([ 0. , -0.4, 0. , 0.4])
- >>> j = complex(0,1)
- >>> L.hermefromroots((-j,j)) # x^2 + 1 relative to the standard basis
- array([ 1.33333333+0.j, 0.00000000+0.j, 0.66666667+0.j])
+ >>> from numpy.polynomial.hermite_e import hermefromroots, hermeval
+ >>> coef = hermefromroots((-1, 0, 1))
+ >>> hermeval((-1, 0, 1), coef)
+ array([ 0., 0., 0.])
+ >>> coef = hermefromroots((-1j, 1j))
+ >>> hermeval((-1j, 1j), coef)
+ array([ 0.+0.j, 0.+0.j])
"""
if len(roots) == 0 :
@@ -323,11 +315,9 @@ def hermeadd(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.hermeadd(c1,c2)
- array([ 4., 4., 4.])
+ >>> from numpy.polynomial.hermite_e import hermeadd
+ >>> hermeadd([1, 2, 3], [1, 2, 3, 4])
+ array([ 2., 4., 6., 4.])
"""
# c1, c2 are trimmed copies
@@ -373,13 +363,9 @@ def hermesub(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.hermesub(c1,c2)
- array([-2., 0., 2.])
- >>> L.hermesub(c2,c1) # -C.hermesub(c1,c2)
- array([ 2., 0., -2.])
+ >>> from numpy.polynomial.hermite_e import hermesub
+ >>> hermesub([1, 2, 3, 4], [1, 2, 3])
+ array([ 0., 0., 0., 4.])
"""
# c1, c2 are trimmed copies
@@ -419,7 +405,13 @@ def hermemulx(cs):
.. math::
- xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
+ xP_i(x) = (P_{i + 1}(x) + iP_{i - 1}(x)))
+
+ Examples
+ --------
+ >>> from numpy.polynomial.hermite_e import hermemulx
+ >>> hermemulx([1, 2, 3])
+ array([ 2., 7., 2., 3.])
"""
# cs is a trimmed copy
@@ -470,11 +462,9 @@ def hermemul(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2)
- >>> P.hermemul(c1,c2) # multiplication requires "reprojection"
- array([ 4.33333333, 10.4 , 11.66666667, 3.6 ])
+ >>> from numpy.polynomial.hermite_e import hermemul
+ >>> hermemul([1, 2, 3], [0, 1, 2])
+ array([ 14., 15., 28., 7., 6.])
"""
# s1, s2 are trimmed copies
@@ -541,14 +531,11 @@ def hermediv(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.hermediv(c1,c2) # quotient "intuitive," remainder not
- (array([ 3.]), array([-8., -4.]))
- >>> c2 = (0,1,2,3)
- >>> L.hermediv(c2,c1) # neither "intuitive"
- (array([-0.07407407, 1.66666667]), array([-1.03703704, -2.51851852]))
+ >>> from numpy.polynomial.hermite_e import hermediv
+ >>> hermediv([ 14., 15., 28., 7., 6.], [0, 1, 2])
+ (array([ 1., 2., 3.]), array([ 0.]))
+ >>> hermediv([ 15., 17., 28., 7., 6.], [0, 1, 2])
+ (array([ 1., 2., 3.]), array([ 1., 2.]))
"""
# c1, c2 are trimmed copies
@@ -602,6 +589,9 @@ def hermepow(cs, pow, maxpower=16) :
Examples
--------
+ >>> from numpy.polynomial.hermite_e import hermepow
+ >>> hermepow([1, 2, 3], 2)
+ array([ 23., 28., 46., 12., 9.])
"""
# cs is a trimmed copy
@@ -663,16 +653,11 @@ def hermeder(cs, m=1, scl=1) :
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> cs = (1,2,3,4)
- >>> L.hermeder(cs)
- array([ 6., 9., 20.])
- >>> L.hermeder(cs,3)
- array([ 60.])
- >>> L.hermeder(cs,scl=-1)
- array([ -6., -9., -20.])
- >>> L.hermeder(cs,2,-1)
- array([ 9., 60.])
+ >>> from numpy.polynomial.hermite_e import hermeder
+ >>> hermeder([ 1., 1., 1., 1.])
+ array([ 1., 2., 3.])
+ >>> hermeder([-0.25, 1., 1./2., 1./3., 1./4 ], m=2)
+ array([ 1., 2., 3.])
"""
cnt = int(m)
@@ -761,19 +746,17 @@ def hermeint(cs, m=1, k=[], lbnd=0, scl=1):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> cs = (1,2,3)
- >>> L.hermeint(cs)
- array([ 0.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.hermeint(cs,3)
- array([ 1.66666667e-02, -1.78571429e-02, 4.76190476e-02,
- -1.73472348e-18, 1.90476190e-02, 9.52380952e-03])
- >>> L.hermeint(cs, k=3)
- array([ 3.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.hermeint(cs, lbnd=-2)
- array([ 7.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.hermeint(cs, scl=2)
- array([ 0.66666667, 0.8 , 1.33333333, 1.2 ])
+ >>> from numpy.polynomial.hermite_e import hermeint
+ >>> hermeint([1, 2, 3]) # integrate once, value 0 at 0.
+ array([ 1., 1., 1., 1.])
+ >>> hermeint([1, 2, 3], m=2) # integrate twice, value & deriv 0 at 0
+ array([-0.25 , 1. , 0.5 , 0.33333333, 0.25 ])
+ >>> hermeint([1, 2, 3], k=1) # integrate once, value 1 at 0.
+ array([ 2., 1., 1., 1.])
+ >>> hermeint([1, 2, 3], lbnd=-1) # integrate once, value 0 at -1
+ array([-1., 1., 1., 1.])
+ >>> hermeint([1, 2, 3], m=2, k=[1,2], lbnd=-1)
+ array([ 1.83333333, 0. , 0.5 , 0.33333333, 0.25 ])
"""
cnt = int(m)
@@ -846,6 +829,13 @@ def hermeval(x, cs):
Examples
--------
+ >>> from numpy.polynomial.hermite_e import hermeval
+ >>> coef = [1,2,3]
+ >>> hermeval(1, coef)
+ 3.0
+ >>> hermeval([[1,2],[3,4]], coef)
+ array([[ 3., 14.],
+ [ 31., 54.]])
"""
# cs is a trimmed copy
@@ -895,6 +885,15 @@ def hermevander(x, deg) :
The shape of the returned matrix is ``x.shape + (deg+1,)``. The last
index is the degree.
+ Examples
+ --------
+ >>> from numpy.polynomial.hermite_e import hermevander
+ >>> x = np.array([-1, 0, 1])
+ >>> hermevander(x, 3)
+ array([[ 1., -1., 0., 2.],
+ [ 1., 0., -1., -0.],
+ [ 1., 1., 0., -2.]])
+
"""
ideg = int(deg)
if ideg != deg:
@@ -1012,6 +1011,12 @@ def hermefit(x, y, deg, rcond=None, full=False, w=None):
Examples
--------
+ >>> from numpy.polynomial.hermite_e import hermefit, hermeval
+ >>> x = np.linspace(-10, 10)
+ >>> err = np.random.randn(len(x))/10
+ >>> y = hermeval(x, [1, 2, 3]) + err
+ >>> hermefit(x, y, 2)
+ array([ 1.01690445, 1.99951418, 2.99948696])
"""
order = int(deg) + 1
@@ -1020,7 +1025,7 @@ def hermefit(x, y, deg, rcond=None, full=False, w=None):
# check arguments.
if deg < 0 :
- raise ValueError, "expected deg >= 0"
+ raise valueerror, "expected deg >= 0"
if x.ndim != 1:
raise TypeError, "expected 1D vector for x"
if x.size == 0:
@@ -1101,12 +1106,12 @@ def hermeroots(cs):
Examples
--------
- >>> import numpy.polynomial as P
- >>> P.polyroots((1, 2, 3, 4)) # 4x^3 + 3x^2 + 2x + 1 has two complex roots
- array([-0.60582959+0.j , -0.07208521-0.63832674j,
- -0.07208521+0.63832674j])
- >>> P.hermeroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0 has only real roots
- array([-0.85099543, -0.11407192, 0.51506735])
+ >>> from numpy.polynomial.hermite_e import hermeroots, hermefromroots
+ >>> coef = hermefromroots([-1, 0, 1])
+ >>> coef
+ array([ 0., 2., 0., 1.])
+ >>> hermeroots(coef)
+ array([-1., 0., 1.])
"""
# cs is a trimmed copy
diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py
index 94c495deb..b6389bf63 100644
--- a/numpy/polynomial/laguerre.py
+++ b/numpy/polynomial/laguerre.py
@@ -96,13 +96,9 @@ def poly2lag(pol) :
Examples
--------
- >>> from numpy import polynomial as P
- >>> p = P.Polynomial(np.arange(4))
- >>> p
- Polynomial([ 0., 1., 2., 3.], [-1., 1.])
- >>> c = P.Laguerre(P.poly2lag(p.coef))
- >>> c
- Laguerre([ 1. , 3.25, 1. , 0.75], [-1., 1.])
+ >>> from numpy.polynomial.laguerre import poly2lag
+ >>> poly2lag(np.arange(4))
+ array([ 23., -63., 58., -18.])
"""
[pol] = pu.as_series([pol])
@@ -146,15 +142,9 @@ def lag2poly(cs) :
Examples
--------
- >>> c = P.Laguerre(range(4))
- >>> c
- Laguerre([ 0., 1., 2., 3.], [-1., 1.])
- >>> p = c.convert(kind=P.Polynomial)
- >>> p
- Polynomial([-1. , -3.5, 3. , 7.5], [-1., 1.])
- >>> P.lag2poly(range(4))
- array([-1. , -3.5, 3. , 7.5])
-
+ >>> from numpy.polynomial.laguerre import lag2poly
+ >>> lag2poly([ 23., -63., 58., -18.])
+ array([ 0., 1., 2., 3.])
"""
from polynomial import polyadd, polysub, polymulx
@@ -214,11 +204,11 @@ def lagline(off, scl) :
Examples
--------
- >>> import numpy.polynomial.legendre as L
- >>> L.lagline(3,2)
- array([3, 2])
- >>> L.lagval(-3, L.lagline(3,2)) # should be -3
- -3.0
+ >>> from numpy.polynomial.laguerre import lagline, lagval
+ >>> lagval(0,lagline(3, 2))
+ 3.0
+ >>> lagval(1,lagline(3, 2))
+ 5.0
"""
if scl != 0 :
@@ -271,12 +261,13 @@ def lagfromroots(roots) :
Examples
--------
- >>> import numpy.polynomial.legendre as L
- >>> L.lagfromroots((-1,0,1)) # x^3 - x relative to the standard basis
- array([ 0. , -0.4, 0. , 0.4])
- >>> j = complex(0,1)
- >>> L.lagfromroots((-j,j)) # x^2 + 1 relative to the standard basis
- array([ 1.33333333+0.j, 0.00000000+0.j, 0.66666667+0.j])
+ >>> from numpy.polynomial.laguerre import lagfromroots, lagval
+ >>> coef = lagfromroots((-1, 0, 1))
+ >>> lagval((-1, 0, 1), coef)
+ array([ 0., 0., 0.])
+ >>> coef = lagfromroots((-1j, 1j))
+ >>> lagval((-1j, 1j), coef)
+ array([ 0.+0.j, 0.+0.j])
"""
if len(roots) == 0 :
@@ -321,11 +312,10 @@ def lagadd(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.lagadd(c1,c2)
- array([ 4., 4., 4.])
+ >>> from numpy.polynomial.laguerre import lagadd
+ >>> lagadd([1, 2, 3], [1, 2, 3, 4])
+ array([ 2., 4., 6., 4.])
+
"""
# c1, c2 are trimmed copies
@@ -371,13 +361,9 @@ def lagsub(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.lagsub(c1,c2)
- array([-2., 0., 2.])
- >>> L.lagsub(c2,c1) # -C.lagsub(c1,c2)
- array([ 2., 0., -2.])
+ >>> from numpy.polynomial.laguerre import lagsub
+ >>> lagsub([1, 2, 3, 4], [1, 2, 3])
+ array([ 0., 0., 0., 4.])
"""
# c1, c2 are trimmed copies
@@ -417,7 +403,13 @@ def lagmulx(cs):
.. math::
- xP_i(x) = ((i + 1)*P_{i + 1}(x) + i*P_{i - 1}(x))/(2i + 1)
+ xP_i(x) = (-(i + 1)*P_{i + 1}(x) + (2i + 1)P_{i}(x) - iP_{i - 1}(x))
+
+ Examples
+ --------
+ >>> from numpy.polynomial.laguerre import lagmulx
+ >>> lagmulx([1, 2, 3])
+ array([ -1., -1., 11., -9.])
"""
# cs is a trimmed copy
@@ -469,11 +461,9 @@ def lagmul(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2)
- >>> P.lagmul(c1,c2) # multiplication requires "reprojection"
- array([ 4.33333333, 10.4 , 11.66666667, 3.6 ])
+ >>> from numpy.polynomial.laguerre import lagmul
+ >>> lagmul([1, 2, 3], [0, 1, 2])
+ array([ 8., -13., 38., -51., 36.])
"""
# s1, s2 are trimmed copies
@@ -540,14 +530,11 @@ def lagdiv(c1, c2):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> c1 = (1,2,3)
- >>> c2 = (3,2,1)
- >>> L.lagdiv(c1,c2) # quotient "intuitive," remainder not
- (array([ 3.]), array([-8., -4.]))
- >>> c2 = (0,1,2,3)
- >>> L.lagdiv(c2,c1) # neither "intuitive"
- (array([-0.07407407, 1.66666667]), array([-1.03703704, -2.51851852]))
+ >>> from numpy.polynomial.laguerre import lagdiv
+ >>> lagdiv([ 8., -13., 38., -51., 36.], [0, 1, 2])
+ (array([ 1., 2., 3.]), array([ 0.]))
+ >>> lagdiv([ 9., -12., 38., -51., 36.], [0, 1, 2])
+ (array([ 1., 2., 3.]), array([ 1., 1.]))
"""
# c1, c2 are trimmed copies
@@ -601,6 +588,9 @@ def lagpow(cs, pow, maxpower=16) :
Examples
--------
+ >>> from numpy.polynomial.laguerre import lagpow
+ >>> lagpow([1, 2, 3], 2)
+ array([ 14., -16., 56., -72., 54.])
"""
# cs is a trimmed copy
@@ -662,16 +652,11 @@ def lagder(cs, m=1, scl=1) :
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> cs = (1,2,3,4)
- >>> L.lagder(cs)
- array([ 6., 9., 20.])
- >>> L.lagder(cs,3)
- array([ 60.])
- >>> L.lagder(cs,scl=-1)
- array([ -6., -9., -20.])
- >>> L.lagder(cs,2,-1)
- array([ 9., 60.])
+ >>> from numpy.polynomial.laguerre import lagder
+ >>> lagder([ 1., 1., 1., -3.])
+ array([ 1., 2., 3.])
+ >>> lagder([ 1., 0., 0., -4., 3.], m=2)
+ array([ 1., 2., 3.])
"""
cnt = int(m)
@@ -761,19 +746,17 @@ def lagint(cs, m=1, k=[], lbnd=0, scl=1):
Examples
--------
- >>> from numpy.polynomial import legendre as L
- >>> cs = (1,2,3)
- >>> L.lagint(cs)
- array([ 0.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.lagint(cs,3)
- array([ 1.66666667e-02, -1.78571429e-02, 4.76190476e-02,
- -1.73472348e-18, 1.90476190e-02, 9.52380952e-03])
- >>> L.lagint(cs, k=3)
- array([ 3.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.lagint(cs, lbnd=-2)
- array([ 7.33333333, 0.4 , 0.66666667, 0.6 ])
- >>> L.lagint(cs, scl=2)
- array([ 0.66666667, 0.8 , 1.33333333, 1.2 ])
+ >>> from numpy.polynomial.laguerre import lagint
+ >>> lagint([1,2,3])
+ array([ 1., 1., 1., -3.])
+ >>> lagint([1,2,3], m=2)
+ array([ 1., 0., 0., -4., 3.])
+ >>> lagint([1,2,3], k=1)
+ array([ 2., 1., 1., -3.])
+ >>> lagint([1,2,3], lbnd=-1)
+ array([ 11.5, 1. , 1. , -3. ])
+ >>> lagint([1,2], m=2, k=[1,2], lbnd=-1)
+ array([ 11.16666667, -5. , -3. , 2. ])
"""
cnt = int(m)
@@ -847,6 +830,13 @@ def lagval(x, cs):
Examples
--------
+ >>> from numpy.polynomial.laguerre import lagval
+ >>> coef = [1,2,3]
+ >>> lagval(1, coef)
+ -0.5
+ >>> lagval([[1,2],[3,4]], coef)
+ array([[-0.5, -4. ],
+ [-4.5, -2. ]])
"""
# cs is a trimmed copy
@@ -896,6 +886,15 @@ def lagvander(x, deg) :
The shape of the returned matrix is ``x.shape + (deg+1,)``. The last
index is the degree.
+ Examples
+ --------
+ >>> from numpy.polynomial.laguerre import lagvander
+ >>> x = np.array([0, 1, 2])
+ >>> lagvander(x, 3)
+ array([[ 1. , 1. , 1. , 1. ],
+ [ 1. , 0. , -0.5 , -0.66666667],
+ [ 1. , -1. , -1. , -0.33333333]])
+
"""
ideg = int(deg)
if ideg != deg:
@@ -1013,6 +1012,12 @@ def lagfit(x, y, deg, rcond=None, full=False, w=None):
Examples
--------
+ >>> from numpy.polynomial.laguerre import lagfit, lagval
+ >>> x = np.linspace(0, 10)
+ >>> err = np.random.randn(len(x))/10
+ >>> y = lagval(x, [1, 2, 3]) + err
+ >>> lagfit(x, y, 2)
+ array([ 0.96971004, 2.00193749, 3.00288744])
"""
order = int(deg) + 1
@@ -1102,12 +1107,12 @@ def lagroots(cs):
Examples
--------
- >>> import numpy.polynomial as P
- >>> P.polyroots((1, 2, 3, 4)) # 4x^3 + 3x^2 + 2x + 1 has two complex roots
- array([-0.60582959+0.j , -0.07208521-0.63832674j,
- -0.07208521+0.63832674j])
- >>> P.lagroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0 has only real roots
- array([-0.85099543, -0.11407192, 0.51506735])
+ >>> from numpy.polynomial.laguerre import lagroots, lagfromroots
+ >>> coef = lagfromroots([0, 1, 2])
+ >>> coef
+ array([ 2., -8., 12., -6.])
+ >>> lagroots(coef)
+ array([ -4.44089210e-16, 1.00000000e+00, 2.00000000e+00])
"""
# cs is a trimmed copy