本文整理汇总了Python中sage.calculus.calculus.maxima函数的典型用法代码示例。如果您正苦于以下问题:Python maxima函数的具体用法?Python maxima怎么用?Python maxima使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了maxima函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _eval_
def _eval_(self, n, m, theta, phi, **kwargs):
r"""
TESTS::
sage: x, y = var('x y')
sage: spherical_harmonic(1, 2, x, y)
0
sage: spherical_harmonic(1, -2, x, y)
0
sage: spherical_harmonic(1/2, 2, x, y)
spherical_harmonic(1/2, 2, x, y)
sage: spherical_harmonic(3, 2, x, y)
15/4*sqrt(7/30)*cos(x)*e^(2*I*y)*sin(x)^2/sqrt(pi)
sage: spherical_harmonic(3, 2, 1, 2)
15/4*sqrt(7/30)*cos(1)*e^(4*I)*sin(1)^2/sqrt(pi)
sage: spherical_harmonic(3 + I, 2., 1, 2)
-0.351154337307488 - 0.415562233975369*I
"""
from sage.structure.coerce import parent
cc = get_coercion_model().canonical_coercion
coerced = cc(phi, cc(theta, cc(n, m)[0])[0])[0]
if is_inexact(coerced) and not isinstance(coerced, Expression):
return self._evalf_(n, m, theta, phi, parent=parent(coerced))
elif n in ZZ and m in ZZ and n > -1:
if abs(m) > n:
return ZZ(0)
return meval("spherical_harmonic({},{},{},{})".format(
ZZ(n), ZZ(m), maxima(theta), maxima(phi)))
return
开发者ID:acrlakshman,项目名称:sage,代码行数:29,代码来源:special.py
示例2: _eval_
def _eval_(self, *args):
"""
Returns a string which represents this function evaluated at
*args* in Maxima.
EXAMPLES::
sage: from sage.functions.special import MaximaFunction
sage: f = MaximaFunction("jacobi_sn")
sage: f(1,1)
tanh(1)
sage: f._eval_(1,1)
tanh(1)
Here arccoth doesn't have 1 in its domain, so we just hold the expression:
sage: elliptic_e(arccoth(1), x^2*e)
elliptic_e(arccoth(1), x^2*e)
"""
_init()
try:
s = maxima(self._maxima_init_evaled_(*args))
except TypeError:
return None
if self.name() in repr(s):
return None
else:
return s.sage()
开发者ID:pombredanne,项目名称:sage-1,代码行数:29,代码来源:special.py
示例3: _evalf_
def _evalf_(self, *args, **kwds):
"""
Returns a numerical approximation of this function using
Maxima. Currently, this is limited to 53 bits of precision.
EXAMPLES::
sage: from sage.functions.special import MaximaFunction
sage: f = MaximaFunction("jacobi_sn")
sage: f(1/2,1/2)
jacobi_sn(1/2, 1/2)
sage: f(1/2,1/2).n()
0.470750473655657
TESTS::
sage: f(1/2,1/2).n(150)
Traceback (most recent call last):
...
NotImplementedError: jacobi_sn not implemented for precision > 53
"""
parent = kwds['parent']
if hasattr(parent, 'prec') and parent.prec() > 53:
raise NotImplementedError, "%s not implemented for precision > 53"%self.name()
_init()
return parent(maxima("%s, numer"%self._maxima_init_evaled_(*args)))
开发者ID:pombredanne,项目名称:sage-1,代码行数:26,代码来源:special.py
示例4: 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
示例5: meval
def meval(x):
"""
Returns ``x`` evaluated in Maxima, then returned to Sage.
This is used to evaluate several of these special functions.
TEST::
sage: from sage.functions.special import airy_ai
sage: airy_bi(1.0)
1.20742359495
"""
return maxima(x).sage()
开发者ID:pombredanne,项目名称:sage-1,代码行数:12,代码来源:special.py
示例6: meval
def meval(x):
"""
Return ``x`` evaluated in Maxima, then returned to Sage.
This is used to evaluate several of these special functions.
TEST::
sage: from sage.functions.special import spherical_bessel_J
sage: spherical_bessel_J(2.,3.) # rel tol 1e-10
0.2986374970757335
"""
return maxima(x).sage()
开发者ID:Babyll,项目名称:sage,代码行数:13,代码来源:special.py
示例7: _eval_
def _eval_(self, n, m, theta, phi, **kwargs):
r"""
TESTS::
sage: x, y = var('x y')
sage: spherical_harmonic(1, 2, x, y)
0
sage: spherical_harmonic(1, -2, x, y)
0
sage: spherical_harmonic(1/2, 2, x, y)
spherical_harmonic(1/2, 2, x, y)
sage: spherical_harmonic(3, 2, x, y)
15/4*sqrt(7/30)*cos(x)*e^(2*I*y)*sin(x)^2/sqrt(pi)
sage: spherical_harmonic(3, 2, 1, 2)
15/4*sqrt(7/30)*cos(1)*e^(4*I)*sin(1)^2/sqrt(pi)
sage: spherical_harmonic(3 + I, 2., 1, 2)
-0.351154337307488 - 0.415562233975369*I
"""
if n in ZZ and m in ZZ and n > -1:
if abs(m) > n:
return ZZ(0)
return meval("spherical_harmonic({},{},{},{})".format(
ZZ(n), ZZ(m), maxima(theta), maxima(phi)))
开发者ID:Babyll,项目名称:sage,代码行数:23,代码来源:special.py
示例8: _evalf_
def _evalf_(self, *args, **kwds):
"""
Returns a numerical approximation of this function using
Maxima. Currently, this is limited to 53 bits of precision.
EXAMPLES::
sage: from sage.functions.special import MaximaFunction
sage: f = MaximaFunction("jacobi_sn")
sage: f(1/2, 1/2)
jacobi_sn(1/2, 1/2)
sage: f(1/2, 1/2).n()
0.470750473655657
sage: f(1/2, 1/2).n(20)
0.47075
sage: f(1, I).n()
0.848379519751901 - 0.0742924572771414*I
TESTS::
sage: f(1/2, 1/2).n(150)
Traceback (most recent call last):
...
NotImplementedError: Maxima function jacobi_sn not implemented for Real Field with 150 bits of precision
sage: f._evalf_(1/2, 1/2, parent=int)
Traceback (most recent call last):
...
NotImplementedError: Maxima function jacobi_sn not implemented for <type 'int'>
sage: f._evalf_(1/2, 1/2, parent=complex)
(0.4707504736556572+0j)
sage: f._evalf_(1/2, 1/2, parent=RDF)
0.4707504736556572
sage: f._evalf_(1, I, parent=CDF) # abs tol 1e-16
0.8483795707591759 - 0.07429247342160791*I
sage: f._evalf_(1, I, parent=RR)
Traceback (most recent call last):
...
TypeError: unable to convert '0.848379570759176-0.0742924734216079*I' to a real number
"""
parent = kwds['parent']
# The result from maxima is a machine double, which corresponds
# to RDF (or CDF). Therefore, before converting, we check that
# we can actually coerce RDF into our parent.
if parent is not float and parent is not complex:
if not isinstance(parent, Parent) or not parent.has_coerce_map_from(RDF):
raise NotImplementedError("Maxima function %s not implemented for %r"%(self.name(), parent))
_init()
return parent(maxima("%s, numer"%self._maxima_init_evaled_(*args)))
开发者ID:Babyll,项目名称:sage,代码行数:48,代码来源:special.py
示例9: _eval_
def _eval_(self, *args):
"""
Try to evaluate this function at ``*args``, return ``None`` if
Maxima did not compute a numerical evaluation.
EXAMPLES::
sage: from sage.functions.special import MaximaFunction
sage: f = MaximaFunction("jacobi_sn")
sage: f(1,1)
tanh(1)
sage: f._eval_(1,1)
tanh(1)
Here arccoth doesn't have 1 in its domain, so we just hold the expression:
sage: elliptic_e(arccoth(1), x^2*e)
elliptic_e(arccoth(1), x^2*e)
Since Maxima works only with double precision, numerical
results are in ``RDF``, no matter what the input precision is::
sage: R = RealField(300)
sage: r = elliptic_eu(R(1/2), R(1/8)); r
0.4950737320232015
sage: parent(r)
Real Double Field
"""
_init()
try:
s = maxima(self._maxima_init_evaled_(*args))
except TypeError:
return None
if self.name() in s.__repr__(): # Avoid infinite recursion
return None
else:
return s.sage()
开发者ID:Findstat,项目名称:sage,代码行数:39,代码来源:special.py
示例10: solve
#.........这里部分代码省略.........
...
TypeError: The first argument to solve() should be a symbolic expression or a list of symbolic expressions, cannot handle <type 'bool'>
sage: solve([a, b], (1, a))
Traceback (most recent call last):
...
TypeError: 1 is not a valid variable.
sage: solve([x == 1], (1, a))
Traceback (most recent call last):
...
TypeError: (1, a) are not valid variables.
Test that the original version of a system in the French Sage book
now works (:trac:`14306`)::
sage: var('y,z')
(y, z)
sage: solve([x^2 * y * z == 18, x * y^3 * z == 24, x * y * z^4 == 6], x, y, z)
[[x == 3, y == 2, z == 1], [x == (1.337215067... - 2.685489874...*I), y == (-1.700434271... + 1.052864325...*I), z == (0.9324722294... - 0.3612416661...*I)], ...]
"""
from sage.symbolic.expression import is_Expression
if is_Expression(f): # f is a single expression
ans = f.solve(*args,**kwds)
return ans
if not isinstance(f, (list, tuple)):
raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
if len(f)==1:
# f is a list with a single element
if is_Expression(f[0]):
# if its a symbolic expression call solve method of this expression
return f[0].solve(*args,**kwds)
# otherwise complain
raise TypeError("The first argument to solve() should be a symbolic "
"expression or a list of symbolic expressions, "
"cannot handle %s"%repr(type(f[0])))
# f is a list of such expressions or equations
from sage.symbolic.ring import is_SymbolicVariable
if len(args)==0:
raise TypeError("Please input variables to solve for.")
if is_SymbolicVariable(args[0]):
variables = args
else:
variables = tuple(args[0])
for v in variables:
if not is_SymbolicVariable(v):
raise TypeError("%s is not a valid variable."%repr(v))
try:
f = [s for s in f if s is not True]
except TypeError:
raise ValueError("Unable to solve %s for %s"%(f, args))
if any(s is False for s in f):
return []
from sage.calculus.calculus import maxima
m = maxima(f)
try:
s = m.solve(variables)
except Exception: # if Maxima gave an error, try its to_poly_solve
try:
s = m.to_poly_solve(variables)
except TypeError as mess: # if that gives an error, raise an error.
if "Error executing code in Maxima" in str(mess):
raise ValueError("Sage is unable to determine whether the system %s can be solved for %s"%(f,args))
else:
raise
if len(s)==0: # if Maxima's solve gave no solutions, try its to_poly_solve
try:
s = m.to_poly_solve(variables)
except Exception: # if that gives an error, stick with no solutions
s = []
if len(s)==0: # if to_poly_solve gave no solutions, try use_grobner
try:
s = m.to_poly_solve(variables,'use_grobner=true')
except Exception: # if that gives an error, stick with no solutions
s = []
sol_list = string_to_list_of_solutions(repr(s))
# Relaxed form suggested by Mike Hansen (#8553):
if kwds.get('solution_dict', False):
if len(sol_list)==0: # fixes IndexError on empty solution list (#8553)
return []
if isinstance(sol_list[0], list):
sol_dict=[dict([[eq.left(),eq.right()] for eq in solution])
for solution in sol_list]
else:
sol_dict=[{eq.left():eq.right()} for eq in sol_list]
return sol_dict
else:
return sol_list
开发者ID:novoselt,项目名称:sage,代码行数:101,代码来源:relation.py
示例11: solve
#.........这里部分代码省略.........
[[s == 1, j == 0], [s == g/b, j == (b - g)*m/(b*g)]]
Inequalities can be also solved::
sage: solve(x^2>8,x)
[[x < -2*sqrt(2)], [x > 2*sqrt(2)]]
Use use_grobner if no solution is obtained from to_poly_solve::
sage: x,y=var('x y'); c1(x,y)=(x-5)^2+y^2-16; c2(x,y)=(y-3)^2+x^2-9
sage: solve([c1(x,y),c2(x,y)],[x,y])
[[x == -9/68*sqrt(55) + 135/68, y == -15/68*sqrt(5)*sqrt(11) + 123/68], [x == 9/68*sqrt(55) + 135/68, y == 15/68*sqrt(5)*sqrt(11) + 123/68]]
TESTS::
sage: solve([sin(x)==x,y^2==x],x,y)
[sin(x) == x, y^2 == x]
sage: solve(0==1,x)
Traceback (most recent call last):
...
TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.
Test if the empty list is returned, too, when (a list of)
dictionaries (is) are requested (#8553)::
sage: solve([0==1],x)
[]
sage: solve([0==1],x,solution_dict=True)
[]
sage: solve([x==1,x==-1],x)
[]
sage: solve([x==1,x==-1],x,solution_dict=True)
[]
sage: solve((x==1,x==-1),x,solution_dict=0)
[]
Relaxed form, suggested by Mike Hansen (#8553)::
sage: solve([x^2-1],x,solution_dict=-1)
[{x: -1}, {x: 1}]
sage: solve([x^2-1],x,solution_dict=1)
[{x: -1}, {x: 1}]
sage: solve((x==1,x==-1),x,solution_dict=-1)
[]
sage: solve((x==1,x==-1),x,solution_dict=1)
[]
This inequality holds for any real ``x`` (trac #8078)::
sage: solve(x^4+2>0,x)
[x < +Infinity]
"""
from sage.symbolic.expression import is_Expression
if is_Expression(f): # f is a single expression
ans = f.solve(*args,**kwds)
return ans
if not isinstance(f, (list, tuple)):
raise TypeError("The first argument must be a symbolic expression or a list of symbolic expressions.")
if len(f)==1 and is_Expression(f[0]):
# f is a list with a single expression
return f[0].solve(*args,**kwds)
# f is a list of such expressions or equations
from sage.symbolic.ring import is_SymbolicVariable
if len(args)==0:
raise TypeError, "Please input variables to solve for."
if is_SymbolicVariable(args[0]):
variables = args
else:
variables = tuple(args[0])
for v in variables:
if not is_SymbolicVariable(v):
raise TypeError, "%s is not a valid variable."%v
try:
f = [s for s in f if s is not True]
except TypeError:
raise ValueError, "Unable to solve %s for %s"%(f, args)
if any(s is False for s in f):
return []
from sage.calculus.calculus import maxima
m = maxima(f)
try:
s = m.solve(variables)
except: # if Maxima gave an error, try its to_poly_solve
try:
s = m.to_poly_solve(variables)
except TypeError, mess: # if that gives an error, raise an error.
if "Error executing code in Maxima" in str(mess):
raise ValueError, "Sage is unable to determine whether the system %s can be solved for %s"%(f,args)
else:
raise
开发者ID:jtmurphy89,项目名称:sagelib,代码行数:101,代码来源:relation.py
注:本文中的sage.calculus.calculus.maxima函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论