本文整理汇总了Python中sympy.polys.orthopolys.legendre_poly函数的典型用法代码示例。如果您正苦于以下问题:Python legendre_poly函数的具体用法?Python legendre_poly怎么用?Python legendre_poly使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了legendre_poly函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_legendre_poly
def test_legendre_poly():
raises(ValueError, "legendre_poly(-1, x)")
assert legendre_poly(1, x, polys=True) == Poly(x)
assert legendre_poly(0, x) == 1
assert legendre_poly(1, x) == x
assert legendre_poly(2, x) == Q(3,2)*x**2 - Q(1,2)
assert legendre_poly(3, x) == Q(5,2)*x**3 - Q(3,2)*x
assert legendre_poly(4, x) == Q(35,8)*x**4 - Q(30,8)*x**2 + Q(3,8)
assert legendre_poly(5, x) == Q(63,8)*x**5 - Q(70,8)*x**3 + Q(15,8)*x
assert legendre_poly(6, x) == Q(231,16)*x**6 - Q(315,16)*x**4 + Q(105,16)*x**2 - Q(5,16)
assert legendre_poly(1).dummy_eq(x)
assert legendre_poly(1, polys=True) == Poly(x)
开发者ID:101man,项目名称:sympy,代码行数:15,代码来源:test_orthopolys.py
示例2: gauss_legendre
def gauss_legendre(n, n_digits):
r"""
Computes the Gauss-Legendre quadrature [1] points and weights.
Parameters
==========
n : the order of quadrature
n_digits : number of significant digits of the points and weights to
return
Returns
=======
(x, w) : the ``x`` and ``w`` are lists of points and weights as Floats
The Gauss-Legendre quadrature approximates the integral:
.. math::
\int_{-1}^1 f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)
The points `x_i` and weights `w_i` are returned as ``(x, w)`` tuple of
lists.
Examples
========
>>> from sympy.integrals.quadrature import gauss_legendre
>>> x, w = gauss_legendre(3, 5)
>>> x
[-0.7746, 0, 0.7746]
>>> w
[0.55556, 0.88889, 0.55556]
>>> x, w = gauss_legendre(4, 5)
>>> x
[-0.86114, -0.33998, 0.33998, 0.86114]
>>> w
[0.34786, 0.65215, 0.65215, 0.34786]
[1] http://en.wikipedia.org/wiki/Gaussian_quadrature
"""
x = Dummy("x")
p = legendre_poly(n, x, polys=True)
pd = p.diff(x)
xi = []
w = []
for r in p.real_roots():
if isinstance(r, RootOf):
r = r.eval_rational(S(1)/10**(n_digits+2))
xi.append(r.n(n_digits))
w.append((2/((1-r**2) * pd.subs(x, r)**2)).n(n_digits))
return xi, w
开发者ID:ananyaha93,项目名称:sympy,代码行数:54,代码来源:quadrature.py
示例3: test_RootOf_eval_rational
def test_RootOf_eval_rational():
p = legendre_poly(4, x, polys=True)
roots = [r.eval_rational(S(1)/10**20) for r in p.real_roots()]
for r in roots:
assert isinstance(r, Rational)
# All we know is that the Rational instance will be at most 1/10^20 from
# the exact root. So if we evaluate to 17 digits, it must be exactly equal
# to:
roots = [str(r.n(17)) for r in roots]
assert roots == [
"-0.86113631159405258",
"-0.33998104358485626",
"0.33998104358485626",
"0.86113631159405258",
]
开发者ID:Bercio,项目名称:sympy,代码行数:15,代码来源:test_rootoftools.py
示例4: test_RootOf_evalf
def test_RootOf_evalf():
real = RootOf(x**3 + x + 3, 0).evalf(n=20)
assert real.epsilon_eq(Float("-1.2134116627622296341"))
re, im = RootOf(x**3 + x + 3, 1).evalf(n=20).as_real_imag()
assert re.epsilon_eq( Float("0.60670583138111481707"))
assert im.epsilon_eq(-Float("1.45061224918844152650"))
re, im = RootOf(x**3 + x + 3, 2).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("0.60670583138111481707"))
assert im.epsilon_eq(Float("1.45061224918844152650"))
p = legendre_poly(4, x, polys=True)
roots = [str(r.n(17)) for r in p.real_roots()]
assert roots == [
"-0.86113631159405258",
"-0.33998104358485626",
"0.33998104358485626",
"0.86113631159405258",
]
re = RootOf(x**5 - 5*x + 12, 0).evalf(n=20)
assert re.epsilon_eq(Float("-1.84208596619025438271"))
re, im = RootOf(x**5 - 5*x + 12, 1).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("-0.351854240827371999559"))
assert im.epsilon_eq(Float("-1.709561043370328882010"))
re, im = RootOf(x**5 - 5*x + 12, 2).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("-0.351854240827371999559"))
assert im.epsilon_eq(Float("+1.709561043370328882010"))
re, im = RootOf(x**5 - 5*x + 12, 3).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("+1.272897223922499190910"))
assert im.epsilon_eq(Float("-0.719798681483861386681"))
re, im = RootOf(x**5 - 5*x + 12, 4).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("+1.272897223922499190910"))
assert im.epsilon_eq(Float("+0.719798681483861386681"))
开发者ID:Bercio,项目名称:sympy,代码行数:42,代码来源:test_rootoftools.py
示例5: test_nroots1
def test_nroots1():
n = 64
p = legendre_poly(n, x, polys=True)
raises(sympy.mpmath.mp.NoConvergence, lambda: p.nroots(n=3, maxsteps=5))
roots = p.nroots(n=3)
# The order of roots matters. They are ordered from smallest to the
# largest.
assert [str(r) for r in roots] == \
['-0.999', '-0.996', '-0.991', '-0.983', '-0.973', '-0.961',
'-0.946', '-0.930', '-0.911', '-0.889', '-0.866', '-0.841',
'-0.813', '-0.784', '-0.753', '-0.720', '-0.685', '-0.649',
'-0.611', '-0.572', '-0.531', '-0.489', '-0.446', '-0.402',
'-0.357', '-0.311', '-0.265', '-0.217', '-0.170', '-0.121',
'-0.0730', '-0.0243', '0.0243', '0.0730', '0.121', '0.170',
'0.217', '0.265', '0.311', '0.357', '0.402', '0.446', '0.489',
'0.531', '0.572', '0.611', '0.649', '0.685', '0.720', '0.753',
'0.784', '0.813', '0.841', '0.866', '0.889', '0.911', '0.930',
'0.946', '0.961', '0.973', '0.983', '0.991', '0.996', '0.999']
开发者ID:NalinG,项目名称:sympy,代码行数:20,代码来源:test_polyroots.py
示例6: _eval_at_order
def _eval_at_order(cls, n, m):
P = legendre_poly(n, _x, polys=True).diff((_x, m))
return (-1)**m * (1 - _x**2)**Rational(m, 2) * P.as_expr()
开发者ID:ChaliZhg,项目名称:sympy,代码行数:3,代码来源:polynomials.py
示例7: test_RootOf_evalf
def test_RootOf_evalf():
real = RootOf(x**3 + x + 3, 0).evalf(n=20)
assert real.epsilon_eq(Float("-1.2134116627622296341"))
re, im = RootOf(x**3 + x + 3, 1).evalf(n=20).as_real_imag()
assert re.epsilon_eq( Float("0.60670583138111481707"))
assert im.epsilon_eq(-Float("1.45061224918844152650"))
re, im = RootOf(x**3 + x + 3, 2).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("0.60670583138111481707"))
assert im.epsilon_eq(Float("1.45061224918844152650"))
p = legendre_poly(4, x, polys=True)
roots = [str(r.n(17)) for r in p.real_roots()]
assert roots == [
"-0.86113631159405258",
"-0.33998104358485626",
"0.33998104358485626",
"0.86113631159405258",
]
re = RootOf(x**5 - 5*x + 12, 0).evalf(n=20)
assert re.epsilon_eq(Float("-1.84208596619025438271"))
re, im = RootOf(x**5 - 5*x + 12, 1).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("-0.351854240827371999559"))
assert im.epsilon_eq(Float("-1.709561043370328882010"))
re, im = RootOf(x**5 - 5*x + 12, 2).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("-0.351854240827371999559"))
assert im.epsilon_eq(Float("+1.709561043370328882010"))
re, im = RootOf(x**5 - 5*x + 12, 3).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("+1.272897223922499190910"))
assert im.epsilon_eq(Float("-0.719798681483861386681"))
re, im = RootOf(x**5 - 5*x + 12, 4).evalf(n=20).as_real_imag()
assert re.epsilon_eq(Float("+1.272897223922499190910"))
assert im.epsilon_eq(Float("+0.719798681483861386681"))
# issue 6393
assert str(RootOf(x**5 + 2*x**4 + x**3 - 68719476736, 0).n(3)) == '147.'
eq = (531441*x**11 + 3857868*x**10 + 13730229*x**9 + 32597882*x**8 +
55077472*x**7 + 60452000*x**6 + 32172064*x**5 - 4383808*x**4 -
11942912*x**3 - 1506304*x**2 + 1453312*x + 512)
a, b = RootOf(eq, 1).n(2).as_real_imag()
c, d = RootOf(eq, 2).n(2).as_real_imag()
assert a == c
assert b < d
assert b == -d
# issue 6451
r = RootOf(legendre_poly(64, x), 7)
assert r.n(2) == r.n(100).n(2)
# issue 8617
ans = [w.n(2) for w in solve(x**3 - x - 4)]
assert RootOf(exp(x)**3 - exp(x) - 4, 0).n(2) in ans
# make sure verification is used in case a max/min traps the "root"
assert str(RootOf(4*x**5 + 16*x**3 + 12*x**2 + 7, 0).n(3)) == '-0.976'
开发者ID:rahvar,项目名称:sympy,代码行数:62,代码来源:test_rootoftools.py
示例8: gauss_legendre
def gauss_legendre(n, n_digits):
r"""
Computes the Gauss-Legendre quadrature [1]_ points and weights.
The Gauss-Legendre quadrature approximates the integral:
.. math::
\int_{-1}^1 f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)
The nodes `x_i` of an order `n` quadrature rule are the roots of `P_n`
and the weights `w_i` are given by:
.. math::
w_i = \frac{2}{\left(1-x_i^2\right) \left(P'_n(x_i)\right)^2}
Parameters
==========
n : the order of quadrature
n_digits : number of significant digits of the points and weights to return
Returns
=======
(x, w) : the ``x`` and ``w`` are lists of points and weights as Floats.
The points `x_i` and weights `w_i` are returned as ``(x, w)``
tuple of lists.
Examples
========
>>> from sympy.integrals.quadrature import gauss_legendre
>>> x, w = gauss_legendre(3, 5)
>>> x
[-0.7746, 0, 0.7746]
>>> w
[0.55556, 0.88889, 0.55556]
>>> x, w = gauss_legendre(4, 5)
>>> x
[-0.86114, -0.33998, 0.33998, 0.86114]
>>> w
[0.34786, 0.65215, 0.65215, 0.34786]
See Also
========
gauss_laguerre, gauss_gen_laguerre, gauss_hermite, gauss_chebyshev_t, gauss_chebyshev_u, gauss_jacobi
References
==========
.. [1] http://en.wikipedia.org/wiki/Gaussian_quadrature
.. [2] http://people.sc.fsu.edu/~jburkardt/cpp_src/legendre_rule/legendre_rule.html
"""
x = Dummy("x")
p = legendre_poly(n, x, polys=True)
pd = p.diff(x)
xi = []
w = []
for r in p.real_roots():
if isinstance(r, RootOf):
r = r.eval_rational(S(1)/10**(n_digits+2))
xi.append(r.n(n_digits))
w.append((2/((1-r**2) * pd.subs(x, r)**2)).n(n_digits))
return xi, w
开发者ID:AALEKH,项目名称:sympy,代码行数:66,代码来源:quadrature.py
示例9: gauss_lobatto
def gauss_lobatto(n, n_digits):
r"""
Computes the Gauss-Lobatto quadrature [1]_ points and weights.
The Gauss-Lobatto quadrature approximates the integral:
.. math::
\int_{-1}^1 f(x)\,dx \approx \sum_{i=1}^n w_i f(x_i)
The nodes `x_i` of an order `n` quadrature rule are the roots of `P'_(n-1)`
and the weights `w_i` are given by:
.. math::
&w_i = \frac{2}{n(n-1) \left[P_{n-1}(x_i)\right]^2},\quad x\neq\pm 1\\
&w_i = \frac{2}{n(n-1)},\quad x=\pm 1
Parameters
==========
n : the order of quadrature
n_digits : number of significant digits of the points and weights to return
Returns
=======
(x, w) : the ``x`` and ``w`` are lists of points and weights as Floats.
The points `x_i` and weights `w_i` are returned as ``(x, w)``
tuple of lists.
Examples
========
>>> from sympy.integrals.quadrature import gauss_lobatto
>>> x, w = gauss_lobatto(3, 5)
>>> x
[-1, 0, 1]
>>> w
[0.33333, 1.3333, 0.33333]
>>> x, w = gauss_lobatto(4, 5)
>>> x
[-1, -0.44721, 0.44721, 1]
>>> w
[0.16667, 0.83333, 0.83333, 0.16667]
See Also
========
gauss_legendre,gauss_laguerre, gauss_gen_laguerre, gauss_hermite, gauss_chebyshev_t, gauss_chebyshev_u, gauss_jacobi
References
==========
.. [1] https://en.wikipedia.org/wiki/Gaussian_quadrature#Gauss.E2.80.93Lobatto_rules
.. [2] http://people.math.sfu.ca/~cbm/aands/page_888.htm
"""
x = Dummy("x")
p = legendre_poly(n-1, x, polys=True)
pd = p.diff(x)
xi = []
w = []
for r in pd.real_roots():
if isinstance(r, RootOf):
r = r.eval_rational(S(1)/10**(n_digits+2))
xi.append(r.n(n_digits))
w.append((2/(n*(n-1) * p.subs(x, r)**2)).n(n_digits))
xi.insert(0, -1)
xi.append(1)
w.insert(0, (S(2)/(n*(n-1))).n(n_digits))
w.append((S(2)/(n*(n-1))).n(n_digits))
return xi, w
开发者ID:asmeurer,项目名称:sympy,代码行数:72,代码来源:quadrature.py
示例10: range
for alphavar in range(4):
for nvar in range(4):
print alphavar, nvar, LaguerreP.subs(n, nvar).subs(alpha, alphavar).doit(), LaguerreP.subs(n, nvar).subs(
alpha, alphavar
).doit() == laguerre_poly(
nvar, x, alpha=alphavar
) # True
(LaguerreF.subs(n, n + 1) / LaguerreF).simplify() # (alpha + n + 1)/(-k + n + 1)
(LaguerreF.subs(k, k + 1) / LaguerreF).simplify() # x*(k - n)/((k + 1)*(alpha + k + 1))
LegendreF = Rat(1) / (Rat(2) ** n) * (binomial(n, k)) ** 2 * (x - Rat(1)) ** k * (x + Rat(1)) ** (n - k)
LegendreP = Sum(LegendreF, (k, 0, n))
for nvar in range(4):
legendre_poly(nvar, x) == LegendreP.subs(n, nvar).doit().expand() # True
(LegendreF.subs(n, n + 1) / LegendreF).simplify() # (n + 1)**2*(x + 1)/(2*(k - n - 1)**2)
(LegendreF.subs(k, k + 1) / LegendreF).simplify() # (k - n)**2*(x - 1)/((k + 1)**2*(x + 1))
JacobiF = (
Rat(1)
/ (Rat(2) ** n)
* binomial(n + alpha, n - k)
* binomial(n + beta, k)
* (x - Rat(1)) ** k
* (x + Rat(1)) ** (n - k)
)
JacobiP = Sum(JacobiF, (k, 0, n))
for alphvar in range(5):
for betvar in range(5):
开发者ID:ernestyalumni,项目名称:qSApoly,代码行数:31,代码来源:hypergeo.py
示例11: test_nroots1
def test_nroots1():
n = 64
p = legendre_poly(n, x, polys=True)
raises(sympy.mpmath.mp.NoConvergence, lambda: p.nroots(n=3, maxsteps=5))
roots = p.nroots(n=3)
# The order of roots matters. They are ordered from smallest to the
# largest.
assert [str(r) for r in roots] == [
"-0.999",
"-0.996",
"-0.991",
"-0.983",
"-0.973",
"-0.961",
"-0.946",
"-0.930",
"-0.911",
"-0.889",
"-0.866",
"-0.841",
"-0.813",
"-0.784",
"-0.753",
"-0.720",
"-0.685",
"-0.649",
"-0.611",
"-0.572",
"-0.531",
"-0.489",
"-0.446",
"-0.402",
"-0.357",
"-0.311",
"-0.265",
"-0.217",
"-0.170",
"-0.121",
"-0.0730",
"-0.0243",
"0.0243",
"0.0730",
"0.121",
"0.170",
"0.217",
"0.265",
"0.311",
"0.357",
"0.402",
"0.446",
"0.489",
"0.531",
"0.572",
"0.611",
"0.649",
"0.685",
"0.720",
"0.753",
"0.784",
"0.813",
"0.841",
"0.866",
"0.889",
"0.911",
"0.930",
"0.946",
"0.961",
"0.973",
"0.983",
"0.991",
"0.996",
"0.999",
]
开发者ID:brajeshvit,项目名称:virtual,代码行数:75,代码来源:test_polyroots.py
注:本文中的sympy.polys.orthopolys.legendre_poly函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论