当前位置: 首页>>代码示例>>Python>>正文


Python C.im方法代码示例

本文整理汇总了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)
开发者ID:artcompiler,项目名称:artcompiler.github.com,代码行数:61,代码来源:miscellaneous.py

示例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
开发者ID:MCGallaspy,项目名称:sympy,代码行数:24,代码来源:rootoftools.py


注:本文中的sympy.core.C.im方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。