本文整理汇总了Python中sympy.Expr._from_mpmath方法的典型用法代码示例。如果您正苦于以下问题:Python Expr._from_mpmath方法的具体用法?Python Expr._from_mpmath怎么用?Python Expr._from_mpmath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Expr
的用法示例。
在下文中一共展示了Expr._from_mpmath方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: jn_zeros
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def jn_zeros(n, k, method="sympy", dps=15):
"""
Zeros of the spherical Bessel function of the first kind.
This returns an array of zeros of jn up to the k-th zero.
* method = "sympy": uses mpmath besseljzero
* method = "scipy": uses the SciPy's sph_jn and newton to find all
roots, which is faster than computing the zeros using a general
numerical solver, but it requires SciPy and only works with low
precision floating point numbers. [the function used with
method="sympy" is a recent addition to mpmath, before that a general
solver was used]
Examples
========
>>> from sympy import jn_zeros
>>> jn_zeros(2, 4, dps=5)
[5.7635, 9.095, 12.323, 15.515]
See Also
========
jn, yn, besselj, besselk, bessely
"""
from math import pi
if method == "sympy":
from sympy.mpmath import besseljzero
from sympy.mpmath.libmp.libmpf import dps_to_prec
from sympy import Expr
prec = dps_to_prec(dps)
return [Expr._from_mpmath(besseljzero(S(n + 0.5)._to_mpmath(prec),
int(k)), prec)
for k in xrange(1, k + 1)]
elif method == "scipy":
from scipy.special import sph_jn
from scipy.optimize import newton
f = lambda x: sph_jn(n, x)[0][-1]
else:
raise NotImplementedError("Unknown method.")
def solver(f, x):
if method == "scipy":
root = newton(f, x)
else:
raise NotImplementedError("Unknown method.")
return root
# we need to approximate the position of the first root:
root = n + pi
# determine the first root exactly:
root = solver(f, root)
roots = [root]
for i in range(k - 1):
# estimate the position of the next root using the last root + pi:
root = solver(f, root + pi)
roots.append(root)
return roots
示例2: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
# The default code is insufficient for polar arguments.
# mpmath provides an optional argument "r", which evaluates
# G(z**(1/r)). I am not sure what its intended use is, but we hijack it
# here in the following way: to evaluate at a number z of |argument|
# less than (say) n*pi, we put r=1/n, compute z' = root(z, n)
# (carefully so as not to loose the branch information), and evaluate
# G(z'**(1/r)) = G(z'**n) = G(z).
from sympy.functions import exp_polar, ceiling
from sympy import Expr
import mpmath
z = self.argument
znum = self.argument._eval_evalf(prec)
if znum.has(exp_polar):
znum, branch = znum.as_coeff_mul(exp_polar)
if len(branch) != 1:
return
branch = branch[0].args[0]/I
else:
branch = S(0)
n = ceiling(abs(branch/S.Pi)) + 1
znum = znum**(S(1)/n)*exp(I*branch / n)
# Convert all args to mpf or mpc
try:
[z, r, ap, bq] = [arg._to_mpmath(prec)
for arg in [znum, 1/n, self.args[0], self.args[1]]]
except ValueError:
return
with mpmath.workprec(prec):
v = mpmath.meijerg(ap, bq, z, r)
return Expr._from_mpmath(v, prec)
示例3: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
from sympy.mpmath import mp, workprec
from sympy import Expr
z = self.args[0]._to_mpmath(prec)
with workprec(prec):
res = mp.airybi(z, derivative=1)
return Expr._from_mpmath(res, prec)
示例4: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
from mpmath import mp, workprec
from sympy import Expr
a = self.args[0]._to_mpmath(prec)
z = self.args[1]._to_mpmath(prec)
with workprec(prec):
res = mp.gammainc(a, z, mp.inf)
return Expr._from_mpmath(res, prec)
示例5: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
from sympy.mpmath import mp
from sympy import Expr
z = self.args[0]._to_mpmath(prec)
oprec = mp.prec
mp.prec = prec
res = mp.airybi(z, derivative=1)
mp.prec = oprec
return Expr._from_mpmath(res, prec)
示例6: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
from sympy.mpmath import mp
from sympy import Expr
a = self.args[0]._to_mpmath(prec)
z = self.args[1]._to_mpmath(prec)
oprec = mp.prec
mp.prec = prec
res = mp.gammainc(a, z, mp.inf)
mp.prec = oprec
return Expr._from_mpmath(res, prec)
示例7: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
m = self.args[0]
if m.is_Integer and m.is_nonnegative:
from mpmath import mp
from sympy import Expr
m = m._to_mpmath(prec)
with workprec(prec):
res = mp.eulernum(m)
return Expr._from_mpmath(res, prec)
示例8: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
from mpmath import mp, workprec
from sympy import Expr
if all(x.is_number for x in self.args):
a = self.args[0]._to_mpmath(prec)
z = self.args[1]._to_mpmath(prec)
with workprec(prec):
res = mp.gammainc(a, 0, z)
return Expr._from_mpmath(res, prec)
else:
return self
示例9: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
m = self.args[0]
if m.is_Integer and m.is_nonnegative:
from sympy.mpmath import mp
from sympy import Expr
m = m._to_mpmath(prec)
oprec = mp.prec
mp.prec = prec
res = mp.eulernum(m)
mp.prec = oprec
return Expr._from_mpmath(res, prec)
示例10: _eval_evalf
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def _eval_evalf(self, prec):
# Note: works without this function by just calling
# mpmath for Legendre polynomials. But using
# the dedicated function directly is cleaner.
from mpmath import mp, workprec
from sympy import Expr
n = self.args[0]._to_mpmath(prec)
m = self.args[1]._to_mpmath(prec)
theta = self.args[2]._to_mpmath(prec)
phi = self.args[3]._to_mpmath(prec)
with workprec(prec):
res = mp.spherharm(n, m, theta, phi)
return Expr._from_mpmath(res, prec)
示例11: test_issue_2387_bug
# 需要导入模块: from sympy import Expr [as 别名]
# 或者: from sympy.Expr import _from_mpmath [as 别名]
def test_issue_2387_bug():
from sympy import I, Expr
assert abs(Expr._from_mpmath(I._to_mpmath(15), 15) - I) < 1.0e-15