本文整理汇总了Python中sage.calculus.calculus.maxima.eval函数的典型用法代码示例。如果您正苦于以下问题:Python eval函数的具体用法?Python eval怎么用?Python eval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了eval函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: assume
def assume(self):
"""
TEST::
sage: from sage.symbolic.assumptions import GenericDeclaration
sage: decl = GenericDeclaration(x, 'even')
sage: decl.assume()
sage: cos(x*pi).simplify()
1
sage: decl2 = GenericDeclaration(x, 'odd')
sage: decl2.assume()
Traceback (most recent call last):
...
ValueError: Assumption is inconsistent
sage: decl.forget()
"""
from sage.calculus.calculus import maxima
if self._context is None:
# We get the list here because features may be added with time.
valid_features = list(maxima("features"))
if self._assumption not in [repr(x).strip() for x in list(valid_features)]:
raise ValueError, "%s not a valid assumption, must be one of %s" % (self._assumption, valid_features)
cur = maxima.get("context")
self._context = maxima.newcontext('context' + maxima._next_var_name())
try:
maxima.eval("declare(%s, %s)" % (repr(self._var), self._assumption))
# except TypeError, mess:
# if 'inconsistent' in str(mess): # note Maxima doesn't tell you if declarations are redundant
# raise ValueError, "Assumption is inconsistent"
except RuntimeError, mess:
if 'inconsistent' in str(mess): # note Maxima doesn't tell you if declarations are redundant
raise ValueError, "Assumption is inconsistent"
else:
raise
maxima.set("context", cur)
开发者ID:sageb0t,项目名称:testsage,代码行数:35,代码来源:assumptions.py
示例2: _init
def _init():
"""
Internal function which checks if Maxima has loaded the
"orthopoly" package. All functions using this in this
file should call this function first.
TEST:
The global starts ``False``::
sage: sage.functions.orthogonal_polys._done
False
Then after using one of these functions, it changes::
sage: from sage.functions.orthogonal_polys import chebyshev_T
sage: chebyshev_T(2,x)
2*(x - 1)^2 + 4*x - 3
sage: sage.functions.orthogonal_polys._done
True
Note that because here we use a Pynac variable ``x``,
the representation of the function is different from
its actual doctest, where a polynomial indeterminate
``x`` is used.
"""
global _done
if _done:
return
maxima.eval('load("orthopoly");')
# TODO -- make it possible to use the intervals returned
# instead of just discarding this info!
maxima.eval("orthopoly_returns_intervals:false;")
_done = True
开发者ID:sageb0t,项目名称:testsage,代码行数:34,代码来源:orthogonal_polys.py
示例3: _init
def _init():
"""
Internal function which checks if Maxima has loaded the
"orthopoly" package. All functions using this in this
file should call this function first.
TEST:
The global starts ``False``::
sage: sage.functions.special._done
False
Then after using one of these functions, it changes::
sage: from sage.functions.special import airy_ai
sage: airy_ai(1.0)
0.135292416313
sage: sage.functions.special._done
True
"""
global _done
if _done:
return
maxima.eval('load("orthopoly");')
maxima.eval('orthopoly_returns_intervals:false;')
_done = True
开发者ID:pombredanne,项目名称:sage-1,代码行数:27,代码来源:special.py
示例4: _init
def _init():
"""
Internal function which checks if Maxima has loaded the
"orthopoly" package. All functions using this in this
file should call this function first.
TEST:
The global starts ``False``::
sage: sage.functions.special._done
False
Then after using one of the MaximaFunctions, it changes::
sage: from sage.functions.special import elliptic_ec
sage: elliptic_ec(0.1)
1.53075763689776
sage: sage.functions.special._done
True
"""
global _done
if _done:
return
maxima.eval('load("orthopoly");')
maxima.eval('orthopoly_returns_intervals:false;')
_done = True
开发者ID:Babyll,项目名称:sage,代码行数:28,代码来源:special.py
示例5: gen_laguerre
def gen_laguerre(n, a, x):
"""
Returns the generalized Laguerre polynomial for integers `n > -1`.
Typically, a = 1/2 or a = -1/2.
REFERENCE:
- table on page 789 in AS.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: gen_laguerre(2,1,x)
1/2*x^2 - 3*x + 3
sage: gen_laguerre(2,1/2,x)
1/2*x^2 - 5/2*x + 15/8
sage: gen_laguerre(2,-1/2,x)
1/2*x^2 - 3/2*x + 3/8
sage: gen_laguerre(2,0,x)
1/2*x^2 - 2*x + 1
sage: gen_laguerre(3,0,x)
-1/6*x^3 + 3/2*x^2 - 3*x + 1
"""
from sage.functions.all import sqrt
_init()
return sage_eval(maxima.eval("gen_laguerre(%s,%s,x)" % (ZZ(n), a)), locals={"x": x})
开发者ID:sageb0t,项目名称:testsage,代码行数:27,代码来源:orthogonal_polys.py
示例6: legendre_P
def legendre_P(n, x):
"""
Returns the Legendre polynomial of the first kind for integers
`n > -1`.
REFERENCE:
- AS 22.5.35 page 779.
EXAMPLES::
sage: P.<t> = QQ[]
sage: legendre_P(2,t)
3/2*t^2 - 1/2
sage: legendre_P(3, 1.1)
1.67750000000000
sage: legendre_P(3, 1 + I)
7/2*I - 13/2
sage: legendre_P(3, MatrixSpace(ZZ, 2)([1, 2, -4, 7]))
[-179 242]
[-484 547]
sage: legendre_P(3, GF(11)(5))
8
"""
_init()
return sage_eval(maxima.eval("legendre_p(%s,x)" % ZZ(n)), locals={"x": x})
开发者ID:sageb0t,项目名称:testsage,代码行数:26,代码来源:orthogonal_polys.py
示例7: gen_laguerre
def gen_laguerre(n, a, x):
"""
Returns the generalized Laguerre polynomial for integers `n > -1`.
Typically, `a = 1/2` or `a = -1/2`.
REFERENCES:
- Table on page 789 in [ASHandbook]_.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: gen_laguerre(2,1,x)
1/2*x^2 - 3*x + 3
sage: gen_laguerre(2,1/2,x)
1/2*x^2 - 5/2*x + 15/8
sage: gen_laguerre(2,-1/2,x)
1/2*x^2 - 3/2*x + 3/8
sage: gen_laguerre(2,0,x)
1/2*x^2 - 2*x + 1
sage: gen_laguerre(3,0,x)
-1/6*x^3 + 3/2*x^2 - 3*x + 1
"""
_init()
return sage_eval(maxima.eval("gen_laguerre(%s,%s,x)" % (ZZ(n), a)), locals={"x": x})
开发者ID:jeromeca,项目名称:sage,代码行数:25,代码来源:orthogonal_polys.py
示例8: ultraspherical
def ultraspherical(n, a, x):
"""
Returns the ultraspherical (or Gegenbauer) polynomial for integers
`n > -1`.
Computed using Maxima.
REFERENCE:
- AS 22.5.27
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: ultraspherical(2,3/2,x)
15/2*x^2 - 3/2
sage: ultraspherical(2,1/2,x)
3/2*x^2 - 1/2
sage: ultraspherical(1,1,x)
2*x
sage: t = PolynomialRing(RationalField(),"t").gen()
sage: gegenbauer(3,2,t)
32*t^3 - 12*t
"""
_init()
return sage_eval(maxima.eval("ultraspherical(%s,%s,x)" % (ZZ(n), a)), locals={"x": x})
开发者ID:sageb0t,项目名称:testsage,代码行数:26,代码来源:orthogonal_polys.py
示例9: hermite
def hermite(n, x):
"""
Returns the Hermite polynomial for integers `n > -1`.
REFERENCE:
- AS 22.5.40 and 22.5.41, page 779.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: hermite(2,x)
4*x^2 - 2
sage: hermite(3,x)
8*x^3 - 12*x
sage: hermite(3,2)
40
sage: S.<y> = PolynomialRing(RR)
sage: hermite(3,y)
8.00000000000000*y^3 - 12.0000000000000*y
sage: R.<x,y> = QQ[]
sage: hermite(3,y^2)
8*y^6 - 12*y^2
sage: w = var('w')
sage: hermite(3,2*w)
8*(8*w^2 - 3)*w
"""
_init()
return sage_eval(maxima.eval("hermite(%s,x)" % ZZ(n)), locals={"x": x})
开发者ID:sageb0t,项目名称:testsage,代码行数:29,代码来源:orthogonal_polys.py
示例10: bessel_Y
def bessel_Y(nu,z,algorithm="maxima", prec=53):
r"""
Implements the "Y-Bessel function", or "Bessel function of the 2nd
kind", with index (or "order") nu and argument z.
.. note::
Currently only prec=53 is supported.
Defn::
cos(pi n)*bessel_J(nu, z) - bessel_J(-nu, z)
-------------------------------------------------
sin(nu*pi)
if nu is not an integer and by taking a limit otherwise.
Sometimes bessel_Y(n,z) is denoted Y_n(z) in the literature.
This is computed using Maxima by default.
EXAMPLES::
sage: bessel_Y(2,1.1,"scipy")
-1.4314714939...
sage: bessel_Y(2,1.1)
-1.4314714939590...
sage: bessel_Y(3.001,2.1)
-1.0299574976424...
TESTS::
sage: bessel_Y(2,1.1, algorithm="pari")
Traceback (most recent call last):
...
NotImplementedError: The Y-Bessel function is only implemented for the maxima and scipy algorithms
"""
if algorithm=="scipy":
if prec != 53:
raise ValueError, "for the scipy algorithm the precision must be 53"
import scipy.special
ans = str(scipy.special.yv(float(nu),complex(real(z),imag(z))))
ans = ans.replace("(","")
ans = ans.replace(")","")
ans = ans.replace("j","*I")
ans = sage_eval(ans)
return real(ans) if z in RR else ans
elif algorithm == "maxima":
if prec != 53:
raise ValueError, "for the maxima algorithm the precision must be 53"
return RR(maxima.eval("bessel_y(%s,%s)"%(float(nu),float(z))))
elif algorithm == "pari":
raise NotImplementedError, "The Y-Bessel function is only implemented for the maxima and scipy algorithms"
else:
raise ValueError, "unknown algorithm '%s'"%algorithm
开发者ID:pombredanne,项目名称:sage-1,代码行数:55,代码来源:special.py
示例11: _maxima_init_evaled_
def _maxima_init_evaled_(self, n, x):
"""
Evaluate the Chebyshev polynomial ``self`` with maxima.
EXAMPLES::
sage: var('n, x')
(n, x)
sage: chebyshev_T._maxima_init_evaled_(1,x)
'_SAGE_VAR_x'
sage: maxima(chebyshev_T(n, chebyshev_T(n, x)))
chebyshev_t(_SAGE_VAR_n,chebyshev_t(_SAGE_VAR_n,_SAGE_VAR_x))
"""
return maxima.eval("chebyshev_t({0},{1})".format(n._maxima_init_(), x._maxima_init_()))
开发者ID:jeromeca,项目名称:sage,代码行数:14,代码来源:orthogonal_polys.py
示例12: chebyshev_U
def chebyshev_U(n, x):
"""
Returns the Chebyshev function of the second kind for integers `n>-1`.
REFERENCE:
- AS, 22.8.3 page 783 and AS 6.1.22 page 256.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: chebyshev_U(2,x)
4*x^2 - 1
"""
_init()
return sage_eval(maxima.eval("chebyshev_u(%s,x)" % ZZ(n)), locals={"x": x})
开发者ID:sageb0t,项目名称:testsage,代码行数:16,代码来源:orthogonal_polys.py
示例13: hermite
def hermite(n,x):
"""
Returns the Hermite polynomial for integers `n > -1`.
REFERENCE:
- [ASHandbook]_ 22.5.40 and 22.5.41, page 779.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: hermite(2,x)
4*x^2 - 2
sage: hermite(3,x)
8*x^3 - 12*x
sage: hermite(3,2)
40
sage: S.<y> = PolynomialRing(RR)
sage: hermite(3,y)
8.00000000000000*y^3 - 12.0000000000000*y
sage: R.<x,y> = QQ[]
sage: hermite(3,y^2)
8*y^6 - 12*y^2
sage: w = var('w')
sage: hermite(3,2*w)
8*(8*w^2 - 3)*w
Check that :trac:`17192` is fixed::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: hermite(0,x)
1
sage: hermite(-1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
sage: hermite(-7,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
_init()
return sage_eval(maxima.eval('hermite(%s,x)'%ZZ(n)), locals={'x':x})
开发者ID:BlairArchibald,项目名称:sage,代码行数:47,代码来源:orthogonal_polys.py
示例14: chebyshev_T
def chebyshev_T(n, x):
"""
Returns the Chebyshev function of the first kind for integers
`n>-1`.
REFERENCE:
- AS 22.5.31 page 778 and AS 6.1.22 page 256.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: chebyshev_T(2,x)
2*x^2 - 1
"""
_init()
return sage_eval(maxima.eval("chebyshev_t(%s,x)" % ZZ(n)), locals={"x": x})
开发者ID:sageb0t,项目名称:testsage,代码行数:17,代码来源:orthogonal_polys.py
示例15: ultraspherical
def ultraspherical(n,a,x):
"""
Returns the ultraspherical (or Gegenbauer) polynomial for integers
`n > -1`.
Computed using Maxima.
REFERENCE:
- [ASHandbook]_ 22.5.27
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: ultraspherical(2,3/2,x)
15/2*x^2 - 3/2
sage: ultraspherical(2,1/2,x)
3/2*x^2 - 1/2
sage: ultraspherical(1,1,x)
2*x
sage: t = PolynomialRing(RationalField(),"t").gen()
sage: gegenbauer(3,2,t)
32*t^3 - 12*t
Check that :trac:`17192` is fixed::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: ultraspherical(0,1,x)
1
sage: ultraspherical(-1,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
sage: ultraspherical(-7,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
_init()
return sage_eval(maxima.eval('ultraspherical(%s,%s,x)'%(ZZ(n),a)), locals={'x':x})
开发者ID:BlairArchibald,项目名称:sage,代码行数:44,代码来源:orthogonal_polys.py
示例16: gen_laguerre
def gen_laguerre(n,a,x):
"""
Returns the generalized Laguerre polynomial for integers `n > -1`.
Typically, `a = 1/2` or `a = -1/2`.
REFERENCES:
- Table on page 789 in [ASHandbook]_.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: gen_laguerre(2,1,x)
1/2*x^2 - 3*x + 3
sage: gen_laguerre(2,1/2,x)
1/2*x^2 - 5/2*x + 15/8
sage: gen_laguerre(2,-1/2,x)
1/2*x^2 - 3/2*x + 3/8
sage: gen_laguerre(2,0,x)
1/2*x^2 - 2*x + 1
sage: gen_laguerre(3,0,x)
-1/6*x^3 + 3/2*x^2 - 3*x + 1
Check that :trac:`17192` is fixed::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: gen_laguerre(0,1,x)
1
sage: gen_laguerre(-1,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
sage: gen_laguerre(-7,1,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
_init()
return sage_eval(maxima.eval('gen_laguerre(%s,%s,x)'%(ZZ(n),a)), locals={'x':x})
开发者ID:BlairArchibald,项目名称:sage,代码行数:43,代码来源:orthogonal_polys.py
示例17: legendre_Q
def legendre_Q(n,x):
"""
Returns the Legendre function of the second kind.
Computed using Maxima.
EXAMPLES::
sage: P.<t> = QQ[]
sage: legendre_Q(2, t)
3/4*t^2*log(-(t + 1)/(t - 1)) - 3/2*t - 1/4*log(-(t + 1)/(t - 1))
sage: legendre_Q(3, 0.5)
-0.198654771479482
sage: legendre_Q(4, 2)
443/16*I*pi + 443/16*log(3) - 365/12
sage: legendre_Q(4, 2.0)
0.00116107583162324 + 86.9828465962674*I
"""
_init()
return sage_eval(maxima.eval('legendre_q(%s,x)'%ZZ(n)), locals={'x':x})
开发者ID:BlairArchibald,项目名称:sage,代码行数:20,代码来源:orthogonal_polys.py
示例18: laguerre
def laguerre(n, x):
"""
Returns the Laguerre polynomial for integers `n > -1`.
REFERENCE:
- AS 22.5.16, page 778 and AS page 789.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: laguerre(2,x)
1/2*x^2 - 2*x + 1
sage: laguerre(3,x)
-1/6*x^3 + 3/2*x^2 - 3*x + 1
sage: laguerre(2,2)
-1
"""
_init()
return sage_eval(maxima.eval("laguerre(%s,x)" % ZZ(n)), locals={"x": x})
开发者ID:sageb0t,项目名称:testsage,代码行数:20,代码来源:orthogonal_polys.py
示例19: jacobi_P
def jacobi_P(n,a,b,x):
r"""
Returns the Jacobi polynomial `P_n^{(a,b)}(x)` for
integers `n > -1` and a and b symbolic or `a > -1`
and `b > -1`. The Jacobi polynomials are actually defined
for all a and b. However, the Jacobi polynomial weight
`(1-x)^a(1+x)^b` isn't integrable for `a \leq -1`
or `b \leq -1`.
REFERENCE:
- Table on page 789 in [ASHandbook]_.
EXAMPLES::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: jacobi_P(2,0,0,x)
3/2*x^2 - 1/2
sage: jacobi_P(2,1,2,1.2) # random output of low order bits
5.009999999999998
Check that :trac:`17192` is fixed::
sage: x = PolynomialRing(QQ, 'x').gen()
sage: jacobi_P(0,0,0,x)
1
sage: jacobi_P(-1,0,0,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -1
sage: jacobi_P(-7,0,0,x)
Traceback (most recent call last):
...
ValueError: n must be greater than -1, got n = -7
"""
if not (n > -1):
raise ValueError("n must be greater than -1, got n = {0}".format(n))
_init()
return sage_eval(maxima.eval('jacobi_p(%s,%s,%s,x)'%(ZZ(n),a,b)), locals={'x':x})
开发者ID:BlairArchibald,项目名称:sage,代码行数:41,代码来源:orthogonal_polys.py
示例20: gen_legendre_P
def gen_legendre_P(n, m, x):
r"""
Returns the generalized (or associated) Legendre function of the
first kind for integers `n > -1, m > -1`.
The awkward code for when m is odd and 1 results from the fact that
Maxima is happy with, for example, `(1 - t^2)^3/2`, but
Sage is not. For these cases the function is computed from the
(m-1)-case using one of the recursions satisfied by the Legendre
functions.
REFERENCE:
- Gradshteyn and Ryzhik 8.706 page 1000.
EXAMPLES::
sage: P.<t> = QQ[]
sage: gen_legendre_P(2, 0, t)
3/2*t^2 - 1/2
sage: gen_legendre_P(2, 0, t) == legendre_P(2, t)
True
sage: gen_legendre_P(3, 1, t)
-3/2*sqrt(-t^2 + 1)*(5*t^2 - 1)
sage: gen_legendre_P(4, 3, t)
105*sqrt(-t^2 + 1)*(t^2 - 1)*t
sage: gen_legendre_P(7, 3, I).expand()
-16695*sqrt(2)
sage: gen_legendre_P(4, 1, 2.5)
-583.562373654533*I
"""
from sage.functions.all import sqrt
_init()
if m.mod(2).is_zero() or m.is_one():
return sage_eval(maxima.eval("assoc_legendre_p(%s,%s,x)" % (ZZ(n), ZZ(m))), locals={"x": x})
else:
return sqrt(1 - x ** 2) * (
((n - m + 1) * x * gen_legendre_P(n, m - 1, x) - (n + m - 1) * gen_legendre_P(n - 1, m - 1, x))
/ (1 - x ** 2)
)
开发者ID:sageb0t,项目名称:testsage,代码行数:41,代码来源:orthogonal_polys.py
注:本文中的sage.calculus.calculus.maxima.eval函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论