本文整理汇总了Python中sympy.core.C.im方法的典型用法代码示例。如果您正苦于以下问题:Python C.im方法的具体用法?Python C.im怎么用?Python C.im使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.C
的用法示例。
在下文中一共展示了C.im方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: real_root
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import im [as 别名]
def real_root(arg, n=None):
"""Return the real nth-root of arg if possible. If n is omitted then
all instances of (-n)**(1/odd) will be changed to -n**(1/odd); this
will only create a real root of a principle root -- the presence of
other factors may cause the result to not be real.
Examples
========
>>> from sympy import root, real_root, Rational
>>> from sympy.abc import x, n
>>> real_root(-8, 3)
-2
>>> root(-8, 3)
2*(-1)**(1/3)
>>> real_root(_)
-2
If one creates a non-principle root and applies real_root, the
result will not be real (so use with caution):
>>> root(-8, 3, 2)
-2*(-1)**(2/3)
>>> real_root(_)
-2*(-1)**(2/3)
See Also
========
sympy.polys.rootoftools.RootOf
sympy.core.power.integer_nthroot
root, sqrt
"""
if n is not None:
try:
n = as_int(n)
arg = sympify(arg)
if arg.is_positive or arg.is_negative:
rv = root(arg, n)
else:
raise ValueError
except ValueError:
return root(arg, n)*C.Piecewise(
(S.One, ~C.Equality(C.im(arg), 0)),
(C.Pow(S.NegativeOne, S.One/n)**(2*C.floor(n/2)), C.And(
C.Equality(n % 2, 1),
arg < 0)),
(S.One, True))
else:
rv = sympify(arg)
n1pow = Transform(lambda x: -(-x.base)**x.exp,
lambda x:
x.is_Pow and
x.base.is_negative and
x.exp.is_Rational and
x.exp.p == 1 and x.exp.q % 2)
return rv.xreplace(n1pow)
示例2: _roots_trivial
# 需要导入模块: from sympy.core import C [as 别名]
# 或者: from sympy.core.C import im [as 别名]
def _roots_trivial(cls, poly, radicals):
"""Compute roots in linear, quadratic and binomial cases. """
if poly.degree() == 1:
return roots_linear(poly)
if not radicals:
return None
free = len(poly.free_symbols)
sort = isinstance(poly, PurePoly) and free or free > 1
if poly.degree() == 2:
roots = roots_quadratic(poly, sort=sort)
elif poly.length() == 2 and poly.TC():
roots = roots_binomial(poly, sort=sort)
else:
return None
# put roots in same order as RootOf instances
if not sort:
key = [r.n(2) for r in roots]
key = [(1 if not r.is_real else 0, C.re(r), C.im(r))
for r in key]
_, roots = zip(*sorted(zip(key, roots)))
return roots