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


Python complexes.re函数代码示例

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


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

示例1: eval

    def eval(cls, nu, z):
        if z.is_zero:
            if nu.is_zero:
                return S.One
            elif (nu.is_integer and nu.is_zero is False) or re(nu).is_positive:
                return S.Zero
            elif re(nu).is_negative and not (nu.is_integer is True):
                return S.ComplexInfinity
            elif nu.is_imaginary:
                return S.NaN
        if z is S.Infinity or (z is S.NegativeInfinity):
            return S.Zero

        if z.could_extract_minus_sign():
            return (z)**nu*(-z)**(-nu)*besselj(nu, -z)
        if nu.is_integer:
            if nu.could_extract_minus_sign():
                return S(-1)**(-nu)*besselj(-nu, z)
            newz = z.extract_multiplicatively(I)
            if newz:  # NOTE we don't want to change the function if z==0
                return I**(nu)*besseli(nu, newz)

        # branch handling:
        from sympy import unpolarify, exp
        if nu.is_integer:
            newz = unpolarify(z)
            if newz != z:
                return besselj(nu, newz)
        else:
            newz, n = z.extract_branch_factor()
            if n != 0:
                return exp(2*n*pi*nu*I)*besselj(nu, newz)
        nnu = unpolarify(nu)
        if nu != nnu:
            return besselj(nnu, z)
开发者ID:AdrianPotter,项目名称:sympy,代码行数:35,代码来源:bessel.py

示例2: eval

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

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

示例3: 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

示例4: 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

示例5: 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

示例6: _eval_rewrite_as_besseli

 def _eval_rewrite_as_besseli(self, z):
     ot = Rational(1, 3)
     tt = Rational(2, 3)
     a = Pow(z, Rational(3, 2))
     if re(z).is_positive:
         return ot * sqrt(z) * (besseli(-ot, tt * a) - besseli(ot, tt * a))
     else:
         return ot * (Pow(a, ot) * besseli(-ot, tt * a) - z * Pow(a, -ot) * besseli(ot, tt * a))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:8,代码来源:bessel.py

示例7: 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

示例8: _eval_evalf

 def _eval_evalf(self, prec):
     """ Careful! any evalf of polar numbers is flaky """
     from sympy import im, pi, re
     i = im(self.args[0])
     try:
         bad = (i <= -pi or i > pi)
     except TypeError:
         bad = True
     if bad:
         return self  # cannot evalf for this argument
     res = exp(self.args[0])._eval_evalf(prec)
     if i > 0 and im(res) < 0:
         # i ~ pi, but exp(I*i) evaluated to argument slightly bigger than pi
         return re(res)
     return res
开发者ID:cmarqu,项目名称:sympy,代码行数:15,代码来源:exponential.py

示例9: 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

示例10: eval

    def eval(cls, n, a, x):
        # For negative n the polynomials vanish
        # See http://functions.wolfram.com/Polynomials/GegenbauerC3/03/01/03/0012/
        if n.is_negative:
            return S.Zero

        # Some special values for fixed a
        if a == S.Half:
            return legendre(n, x)
        elif a == S.One:
            return chebyshevu(n, x)
        elif a == S.NegativeOne:
            return S.Zero

        if not n.is_Number:
            # Handle this before the general sign extraction rule
            if x == S.NegativeOne:
                if (re(a) > S.Half) == True:
                    return S.ComplexInfinity
                else:
                    # No sec function available yet
                    #return (cos(S.Pi*(a+n)) * sec(S.Pi*a) * gamma(2*a+n) /
                    #            (gamma(2*a) * gamma(n+1)))
                    return None

            # Symbolic result C^a_n(x)
            # C^a_n(-x)  --->  (-1)**n * C^a_n(x)
            if x.could_extract_minus_sign():
                return S.NegativeOne**n * gegenbauer(n, a, -x)
            # We can evaluate for some special values of x
            if x == S.Zero:
                return (2**n * sqrt(S.Pi) * gamma(a + S.Half*n) /
                        (gamma((1 - n)/2) * gamma(n + 1) * gamma(a)) )
            if x == S.One:
                return gamma(2*a + n) / (gamma(2*a) * gamma(n + 1))
            elif x == S.Infinity:
                if n.is_positive:
                    return RisingFactorial(a, n) * S.Infinity
        else:
            # n is a given fixed integer, evaluate into polynomial
            return gegenbauer_poly(n, a, x)
开发者ID:ChaliZhg,项目名称:sympy,代码行数:41,代码来源:polynomials.py

示例11: _check

 def _check(self, value):
     from sympy.functions import re, im
     super(ComplexType, self)._check(re(value))
     super(ComplexType, self)._check(im(value))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:4,代码来源:ast.py

示例12: _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

示例13: _eval_rewrite_as_besselj

 def _eval_rewrite_as_besselj(self, z):
     ot = Rational(1, 3)
     tt = Rational(2, 3)
     a = Pow(-z, Rational(3, 2))
     if re(z).is_negative:
         return ot * sqrt(-z) * (besselj(-ot, tt * a) + besselj(ot, tt * a))
开发者ID:LuckyStrikes1090,项目名称:sympy,代码行数:6,代码来源:bessel.py

示例14: _eval_Abs

 def _eval_Abs(self):   # Abs is never a polar number
     from sympy.functions.elementary.complexes import re
     return exp(re(self.args[0]))
开发者ID:cmarqu,项目名称:sympy,代码行数:3,代码来源:exponential.py

示例15: as_real_imag

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


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