• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python complexes.im函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sympy.functions.elementary.complexes.im函数的典型用法代码示例。如果您正苦于以下问题:Python im函数的具体用法?Python im怎么用?Python im使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了im函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _do_ellipse_intersection

    def _do_ellipse_intersection(self, o):
        """The intersection of two ellipses.

        Private helper method for `intersection`.

        """
        x = Dummy("x")
        y = Dummy("y")
        seq = self.equation(x, y)
        oeq = o.equation(x, y)
        result = solve([seq, oeq], [x, y])
        return [Point(*r) for r in result if im(r[0]).is_zero and im(r[1]).is_zero]
开发者ID:Narsil,项目名称:sympy,代码行数:12,代码来源:ellipse.py


示例2: eval

    def eval(cls, nu, z):
        if z.is_zero:
            if nu.is_zero:
                return S.Infinity
            elif re(nu).is_zero is False:
                return S.ComplexInfinity
            elif re(nu).is_zero:
                return S.NaN
        if z.is_imaginary:
            if im(z) is S.Infinity or im(z) is S.NegativeInfinity:
                return S.Zero

        if nu.is_integer:
            if nu.could_extract_minus_sign():
                return besselk(-nu, z)
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:15,代码来源:bessel.py


示例3: test_solve_trig

def test_solve_trig():
    from sympy.abc import n

    assert solveset_real(sin(x), x) == Union(
        imageset(Lambda(n, 2 * pi * n), S.Integers), imageset(Lambda(n, 2 * pi * n + pi), S.Integers)
    )

    assert solveset_real(sin(x) - 1, x) == imageset(Lambda(n, 2 * pi * n + pi / 2), S.Integers)

    assert solveset_real(cos(x), x) == Union(
        imageset(Lambda(n, 2 * pi * n - pi / 2), S.Integers), imageset(Lambda(n, 2 * pi * n + pi / 2), S.Integers)
    )

    assert solveset_real(sin(x) + cos(x), x) == Union(
        imageset(Lambda(n, 2 * n * pi - pi / 4), S.Integers), imageset(Lambda(n, 2 * n * pi + 3 * pi / 4), S.Integers)
    )

    assert solveset_real(sin(x) ** 2 + cos(x) ** 2, x) == S.EmptySet

    assert solveset_complex(cos(x) - S.Half, x) == Union(
        imageset(Lambda(n, 2 * n * pi + pi / 3), S.Integers), imageset(Lambda(n, 2 * n * pi - pi / 3), S.Integers)
    )

    y, a = symbols("y,a")
    assert solveset(sin(y + a) - sin(y), a, domain=S.Reals) == Union(
        imageset(Lambda(n, 2 * n * pi), S.Integers),
        imageset(Lambda(n, -I * (I * (2 * n * pi + arg(-exp(-2 * I * y))) + 2 * im(y))), S.Integers),
    )
开发者ID:pabloferz,项目名称:sympy,代码行数:28,代码来源:test_solveset.py


示例4: test_issue_9778

def test_issue_9778():
    assert solveset(x ** 3 + 1, x, S.Reals) == FiniteSet(-1)
    assert solveset(x ** (S(3) / 5) + 1, x, S.Reals) == S.EmptySet
    assert solveset(x ** 3 + y, x, S.Reals) == Intersection(
        Interval(-oo, oo),
        FiniteSet((-y) ** (S(1) / 3) * Piecewise((1, Ne(-im(y), 0)), ((-1) ** (S(2) / 3), -y < 0), (1, True))),
    )
开发者ID:pabloferz,项目名称:sympy,代码行数:7,代码来源:test_solveset.py


示例5: test_solve_sqrt_3

def test_solve_sqrt_3():
    R = Symbol("R")
    eq = sqrt(2) * R * sqrt(1 / (R + 1)) + (R + 1) * (sqrt(2) * sqrt(1 / (R + 1)) - 1)
    sol = solveset_complex(eq, R)

    assert sol == FiniteSet(
        *[
            S(5) / 3 + 4 * sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3,
            -sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
            + 40 * re(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
            + sqrt(30) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
            + S(5) / 3
            + I
            * (
                -sqrt(30) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
                - sqrt(10) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
                + 40 * im(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
            ),
        ]
    )

    # the number of real roots will depend on the value of m: for m=1 there are 4
    # and for m=-1 there are none.
    eq = -sqrt((m - q) ** 2 + (-m / (2 * q) + S(1) / 2) ** 2) + sqrt(
        (-m ** 2 / 2 - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
        + (m ** 2 / 2 - m - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
    )
    raises(NotImplementedError, lambda: solveset_real(eq, q))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:28,代码来源:test_solveset.py


示例6: __new__

    def __new__(cls, *args, **kwargs):
        evaluate = kwargs.get('evaluate', global_evaluate[0])

        if iterable(args[0]):
            if isinstance(args[0], Point) and not evaluate:
                return args[0]
            args = args[0]

        # unpack the arguments into a friendly Tuple
        # if we were already a Point, we're doing an excess
        # iteration, but we'll worry about efficiency later
        coords = Tuple(*args)
        if any(a.is_number and im(a) for a in coords):
            raise ValueError('Imaginary coordinates not permitted.')

        # Turn any Floats into rationals and simplify
        # any expressions before we instantiate
        if evaluate:
            coords = coords.xreplace(dict(
                [(f, simplify(nsimplify(f, rational=True)))
                for f in coords.atoms(Float)]))
        if len(coords) == 2:
            return Point2D(coords, **kwargs)
        if len(coords) == 3:
            return Point3D(coords, **kwargs)

        return GeometryEntity.__new__(cls, *coords)
开发者ID:peterstangl,项目名称:sympy,代码行数:27,代码来源:point.py


示例7: as_real_imag

    def as_real_imag(self):
        """Returns a tuple of the real part of the input Matrix
           and it's imaginary part.

           >>> from sympy import Matrix, I
           >>> A = Matrix([[1+2*I, 3], [4+7*I, 5]])
           >>> A.as_real_imag()
           (Matrix([
           [1, 3],
           [4, 5]]), Matrix([
           [2, 0],
           [7, 0]]))
           >>> from sympy.abc import x, y, z, w
           >>> B = Matrix([[x, y + x * I], [z + w * I, z]])
           >>> B.as_real_imag()
           (Matrix([
           [        re(x), re(y) - im(x)],
           [re(z) - im(w),         re(z)]]), Matrix([
           [        im(x), re(x) + im(y)],
           [re(w) + im(z),         im(z)]]))

        """
        from sympy.functions.elementary.complexes import re, im
        real_mat = self._new(self.rows, self.cols, lambda i, j: re(self[i, j]))
        im_mat = self._new(self.rows, self.cols, lambda i, j: im(self[i, j]))

        return (real_mat, im_mat)
开发者ID:chaffra,项目名称:sympy,代码行数:27,代码来源:dense.py


示例8: eval

    def eval(cls, arg, k=0):
        """
        Returns a simplified form or a value of DiracDelta depending on the
        argument passed by the DiracDelta object.

        The ``eval()`` method is automatically called when the ``DiracDelta`` class
        is about to be instantiated and it returns either some simplified instance
        or the unevaluated instance depending on the argument passed. In other words,
        ``eval()`` method is not needed to be called explicitly, it is being called
        and evaluated once the object is called.

        Examples
        ========

        >>> from sympy import DiracDelta, S, Subs
        >>> from sympy.abc import x

        >>> DiracDelta(x)
        DiracDelta(x)

        >>> DiracDelta(x,1)
        DiracDelta(x, 1)

        >>> DiracDelta(1)
        0

        >>> DiracDelta(5,1)
        0

        >>> DiracDelta(0)
        DiracDelta(0)

        >>> DiracDelta(-1)
        0

        >>> DiracDelta(S.NaN)
        nan

        >>> DiracDelta(x).eval(1)
        0

        >>> DiracDelta(x - 100).subs(x, 5)
        0

        >>> DiracDelta(x - 100).subs(x, 100)
        DiracDelta(0)

        """
        k = sympify(k)
        if not k.is_Integer or k.is_negative:
            raise ValueError("Error: the second argument of DiracDelta must be \
            a non-negative integer, %s given instead." % (k,))
        arg = sympify(arg)
        if arg is S.NaN:
            return S.NaN
        if arg.is_nonzero:
            return S.Zero
        if fuzzy_not(im(arg).is_zero):
            raise ValueError("Function defined only for Real Values. Complex part: %s  found in %s ." % (repr(im(arg)), repr(arg)) )
开发者ID:sixpearls,项目名称:sympy,代码行数:59,代码来源:delta_functions.py


示例9: as_real_imag

    def as_real_imag(self):
        real_matrices = [re(matrix) for matrix in self.blocks]
        real_matrices = Matrix(self.blockshape[0], self.blockshape[1], real_matrices)

        im_matrices = [im(matrix) for matrix in self.blocks]
        im_matrices = Matrix(self.blockshape[0], self.blockshape[1], im_matrices)

        return (real_matrices, im_matrices)
开发者ID:cklb,项目名称:sympy,代码行数:8,代码来源:blockmatrix.py


示例10: eval

 def eval(cls, arg):
     arg = sympify(arg)
     if arg is S.NaN:
         return S.NaN
     elif fuzzy_not(im(arg).is_zero):
         raise ValueError("Function defined only for Real Values. Complex part: %s  found in %s ." % (repr(im(arg)), repr(arg)) )
     elif arg.is_negative:
         return S.Zero
     elif arg.is_positive:
         return S.One
开发者ID:A-turing-machine,项目名称:sympy,代码行数:10,代码来源:delta_functions.py


示例11: _do_ellipse_intersection

    def _do_ellipse_intersection(self, o):
        """
        Find the intersection of two ellipses.
        """
        seq = self.equation()
        variables = self.equation().atoms(C.Symbol)
        if len(variables) > 2:
            return None
        x, y = variables
        oeq = o.equation(x=x, y=y)
        # until the following line works...
        # result = solve([seq, oeq], [x, y])
        # return [Point(*r) for r in result if im(r[0]).is_zero and im(r[1]).is_zero]
        # we do this:
        if self.center[0] == o.center[0] or self.center[1] == o.center[1]:
            result = solve_poly_system([seq, oeq], x, y)
            return [Point(*r) for r in result if im(r[0]).is_zero and im(r[1]).is_zero]

        raise NotImplementedError("Off-axis Ellipse intersection not supported.")
开发者ID:pyc111,项目名称:sympy,代码行数:19,代码来源:ellipse.py


示例12: real_root

def real_root(arg, n=None, evaluate=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 principal root -- the presence of
    other factors may cause the result to not be real.

    The parameter evaluate determines if the expression should be evaluated.
    If None, its value is taken from global_evaluate.

    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-principal 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
    """
    from sympy.functions.elementary.complexes import Abs, im, sign
    from sympy.functions.elementary.piecewise import Piecewise
    if n is not None:
        return Piecewise(
            (root(arg, n, evaluate=evaluate), Or(Eq(n, S.One), Eq(n, S.NegativeOne))),
            (Mul(sign(arg), root(Abs(arg), n, evaluate=evaluate), evaluate=evaluate),
            And(Eq(im(arg), S.Zero), Eq(Mod(n, 2), S.One))),
            (root(arg, n, evaluate=evaluate), True))
    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:asmeurer,项目名称:sympy,代码行数:54,代码来源:miscellaneous.py


示例13: as_real_imag

    def as_real_imag(self):
        """Returns tuple containing (real , imaginary) part of sparse matrix"""
        from sympy.functions.elementary.complexes import re, im
        real_smat = self.copy()
        im_smat = self.copy()

        for key, value in self._smat.items():
            real_smat._smat[key] = re(value)
            im_smat._smat[key] = im(value)

        return (real_smat, im_smat)
开发者ID:chaffra,项目名称:sympy,代码行数:11,代码来源:sparse.py


示例14: test_solve_sqrt_3

def test_solve_sqrt_3():
    R = Symbol("R")
    eq = sqrt(2) * R * sqrt(1 / (R + 1)) + (R + 1) * (sqrt(2) * sqrt(1 / (R + 1)) - 1)
    sol = solveset_complex(eq, R)

    assert sol == FiniteSet(
        *[
            S(5) / 3 + 4 * sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3,
            -sqrt(10) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
            + 40 * re(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
            + sqrt(30) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
            + S(5) / 3
            + I
            * (
                -sqrt(30) * cos(atan(3 * sqrt(111) / 251) / 3) / 3
                - sqrt(10) * sin(atan(3 * sqrt(111) / 251) / 3) / 3
                + 40 * im(1 / ((-S(1) / 2 - sqrt(3) * I / 2) * (S(251) / 27 + sqrt(111) * I / 9) ** (S(1) / 3))) / 9
            ),
        ]
    )

    # the number of real roots will depend on the value of m: for m=1 there are 4
    # and for m=-1 there are none.
    eq = -sqrt((m - q) ** 2 + (-m / (2 * q) + S(1) / 2) ** 2) + sqrt(
        (-m ** 2 / 2 - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
        + (m ** 2 / 2 - m - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) / 4 - S(1) / 4) ** 2
    )
    unsolved_object = ConditionSet(
        q,
        Eq(
            (
                -2 * sqrt(4 * q ** 2 * (m - q) ** 2 + (-m + q) ** 2)
                + sqrt(
                    (-2 * m ** 2 - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) - 1) ** 2
                    + (2 * m ** 2 - 4 * m - sqrt(4 * m ** 4 - 4 * m ** 2 + 8 * m + 1) - 1) ** 2
                )
                * Abs(q)
            )
            / Abs(q),
            0,
        ),
        S.Reals,
    )
    assert solveset_real(eq, q) == unsolved_object
开发者ID:pabloferz,项目名称:sympy,代码行数:44,代码来源:test_solveset.py


示例15: __new__

 def __new__(cls, *args, **kwargs):
     eval = kwargs.get('evaluate', global_evaluate[0])
     check = True
     if isinstance(args[0], Point):
         if not eval:
             return args[0]
         args = args[0].args
         check = False
     else:
         if iterable(args[0]):
             args = args[0]
         if len(args) != 2:
             raise ValueError(
                 "Only two dimensional points currently supported")
     coords = Tuple(*args)
     if check:
         if any(a.is_number and im(a) for a in coords):
             raise ValueError('Imaginary args not permitted.')
     if eval:
         coords = coords.xreplace(dict(
             [(f, simplify(nsimplify(f, rational=True)))
             for f in coords.atoms(Float)]))
     return GeometryEntity.__new__(cls, *coords)
开发者ID:B-Rich,项目名称:sympy,代码行数:23,代码来源:point.py


示例16: _cast_nocheck

 def _cast_nocheck(self, value):
     from sympy.functions import re, im
     return (
         super(ComplexType, self)._cast_nocheck(re(value)) +
         super(ComplexType, self)._cast_nocheck(im(value))*1j
     )
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:6,代码来源:ast.py


示例17: as_real_imag

 def as_real_imag(self):
     return (re(Matrix(self)), im(Matrix(self)))
开发者ID:bjodah,项目名称:sympy,代码行数:2,代码来源:funcmatrix.py


示例18: eval

    def eval(cls, variable, offset, exponent):
        """
        Returns a simplified form or a value of Singularity Function depending on the
        argument passed by the object.

        The ``eval()`` method is automatically called when the ``SingularityFunction`` class
        is about to be instantiated and it returns either some simplified instance
        or the unevaluated instance depending on the argument passed. In other words,
        ``eval()`` method is not needed to be called explicitly, it is being called
        and evaluated once the object is called.

        Examples
        ========
        >>> from sympy import SingularityFunction, Symbol, nan
        >>> from sympy.abc import x, a, n
        >>> SingularityFunction(x, a, n)
        SingularityFunction(x, a, n)
        >>> SingularityFunction(5, 3, 2)
        4
        >>> SingularityFunction(x, a, nan)
        nan
        >>> SingularityFunction(x, 3, 0).subs(x, 3)
        1
        >>> SingularityFunction(x, a, n).eval(3, 5, 1)
        0
        >>> SingularityFunction(x, a, n).eval(4, 1, 5)
        243
        >>> x = Symbol('x', positive = True)
        >>> a = Symbol('a', negative = True)
        >>> n = Symbol('n', nonnegative = True)
        >>> SingularityFunction(x, a, n)
        (-a + x)**n
        >>> x = Symbol('x', negative = True)
        >>> a = Symbol('a', positive = True)
        >>> SingularityFunction(x, a, n)
        0

        """

        x = sympify(variable)
        a = sympify(offset)
        n = sympify(exponent)
        shift = (x - a)

        if fuzzy_not(im(shift).is_zero):
            raise ValueError("Singularity Functions are defined only for Real Numbers.")
        if fuzzy_not(im(n).is_zero):
            raise ValueError("Singularity Functions are not defined for imaginary exponents.")
        if shift is S.NaN or n is S.NaN:
            return S.NaN
        if (n + 2).is_negative:
            raise ValueError("Singularity Functions are not defined for exponents less than -2.")
        if shift.is_negative:
            return S.Zero
        if n.is_nonnegative and shift.is_nonnegative:
            return (x - a)**n
        if n == -1 or n == -2:
            if shift.is_negative or shift.is_positive:
                return S.Zero
            if shift.is_zero:
                return S.Infinity
开发者ID:cmarqu,项目名称:sympy,代码行数:61,代码来源:singularity_functions.py


示例19: get_integer_part

def get_integer_part(expr, no, options, return_ints=False):
    """
    With no = 1, computes ceiling(expr)
    With no = -1, computes floor(expr)

    Note: this function either gives the exact result or signals failure.
    """
    from sympy.functions.elementary.complexes import re, im
    # The expression is likely less than 2^30 or so
    assumed_size = 30
    ire, iim, ire_acc, iim_acc = evalf(expr, assumed_size, options)

    # We now know the size, so we can calculate how much extra precision
    # (if any) is needed to get within the nearest integer
    if ire and iim:
        gap = max(fastlog(ire) - ire_acc, fastlog(iim) - iim_acc)
    elif ire:
        gap = fastlog(ire) - ire_acc
    elif iim:
        gap = fastlog(iim) - iim_acc
    else:
        # ... or maybe the expression was exactly zero
        return None, None, None, None

    margin = 10

    if gap >= -margin:
        ire, iim, ire_acc, iim_acc = \
            evalf(expr, margin + assumed_size + gap, options)

    # We can now easily find the nearest integer, but to find floor/ceil, we
    # must also calculate whether the difference to the nearest integer is
    # positive or negative (which may fail if very close).
    def calc_part(expr, nexpr):
        from sympy.core.add import Add
        nint = int(to_int(nexpr, rnd))
        n, c, p, b = nexpr
        is_int = (p == 0)
        if not is_int:
            # if there are subs and they all contain integer re/im parts
            # then we can (hopefully) safely substitute them into the
            # expression
            s = options.get('subs', False)
            if s:
                doit = True
                from sympy.core.compatibility import as_int
                for v in s.values():
                    try:
                        as_int(v)
                    except ValueError:
                        try:
                            [as_int(i) for i in v.as_real_imag()]
                            continue
                        except (ValueError, AttributeError):
                            doit = False
                            break
                if doit:
                    expr = expr.subs(s)

            expr = Add(expr, -nint, evaluate=False)
            x, _, x_acc, _ = evalf(expr, 10, options)
            try:
                check_target(expr, (x, None, x_acc, None), 3)
            except PrecisionExhausted:
                if not expr.equals(0):
                    raise PrecisionExhausted
                x = fzero
            nint += int(no*(mpf_cmp(x or fzero, fzero) == no))
        nint = from_int(nint)
        return nint, fastlog(nint) + 10

    re_, im_, re_acc, im_acc = None, None, None, None

    if ire:
        re_, re_acc = calc_part(re(expr, evaluate=False), ire)
    if iim:
        im_, im_acc = calc_part(im(expr, evaluate=False), iim)

    if return_ints:
        return int(to_int(re_ or fzero)), int(to_int(im_ or fzero))
    return re_, im_, re_acc, im_acc
开发者ID:arghdos,项目名称:sympy,代码行数:81,代码来源:evalf.py


示例20: test_sympy__functions__elementary__complexes__im

def test_sympy__functions__elementary__complexes__im():
    from sympy.functions.elementary.complexes import im
    assert _test_args(im(x))
开发者ID:101man,项目名称:sympy,代码行数:3,代码来源:test_args.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python complexes.re函数代码示例发布时间:2022-05-27
下一篇:
Python complexes.c函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap