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


Python sympy.I属性代码示例

本文整理汇总了Python中sympy.I属性的典型用法代码示例。如果您正苦于以下问题:Python sympy.I属性的具体用法?Python sympy.I怎么用?Python sympy.I使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在sympy的用法示例。


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

示例1: sympy_to_grim

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def sympy_to_grim(expr, **kwargs):
    import sympy
    assert isinstance(expr, sympy.Expr)
    if expr.is_Integer:
        return Expr(int(expr))
    if expr.is_Symbol:
        return Expr(symbol_name=expr.name)
    if expr is sympy.pi:
        return Pi
    if expr is sympy.E:
        return ConstE
    if expr is sympy.I:
        return ConstI
    if expr.is_Add:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        return Add(*args)
    if expr.is_Mul:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        return Mul(*args)
    if expr.is_Pow:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        b, e = args
        return Pow(b, e)
    raise NotImplementedError("converting %s to Grim", type(expr)) 
开发者ID:fredrik-johansson,项目名称:fungrim,代码行数:26,代码来源:sympy_interface.py

示例2: test_conv10

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def test_conv10():
    A = DenseMatrix(1, 4, [Integer(1), Integer(2), Integer(3), Integer(4)])
    assert (A._sympy_() == sympy.Matrix(1, 4,
                                        [sympy.Integer(1), sympy.Integer(2),
                                         sympy.Integer(3), sympy.Integer(4)]))

    B = DenseMatrix(4, 1, [Symbol("x"), Symbol("y"), Symbol("z"), Symbol("t")])
    assert (B._sympy_() == sympy.Matrix(4, 1,
                                        [sympy.Symbol("x"), sympy.Symbol("y"),
                                         sympy.Symbol("z"), sympy.Symbol("t")])
            )

    C = DenseMatrix(2, 2,
                    [Integer(5), Symbol("x"),
                     function_symbol("f", Symbol("x")), 1 + I])

    assert (C._sympy_() ==
            sympy.Matrix([[5, sympy.Symbol("x")],
                          [sympy.Function("f")(sympy.Symbol("x")),
                           1 + sympy.I]])) 
开发者ID:symengine,项目名称:symengine.py,代码行数:22,代码来源:test_sympy_conv.py

示例3: test_conv10b

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def test_conv10b():
    A = sympy.Matrix([[sympy.Symbol("x"), sympy.Symbol("y")],
                     [sympy.Symbol("z"), sympy.Symbol("t")]])
    assert sympify(A) == DenseMatrix(2, 2, [Symbol("x"), Symbol("y"),
                                            Symbol("z"), Symbol("t")])

    B = sympy.Matrix([[1, 2], [3, 4]])
    assert sympify(B) == DenseMatrix(2, 2, [Integer(1), Integer(2), Integer(3),
                                            Integer(4)])

    C = sympy.Matrix([[7, sympy.Symbol("y")],
                     [sympy.Function("g")(sympy.Symbol("z")), 3 + 2*sympy.I]])
    assert sympify(C) == DenseMatrix(2, 2, [Integer(7), Symbol("y"),
                                            function_symbol("g",
                                                            Symbol("z")),
                                            3 + 2*I]) 
开发者ID:symengine,项目名称:symengine.py,代码行数:18,代码来源:test_sympy_conv.py

示例4: test_value_of

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def test_value_of():
    assert not bool(cirq.ParamResolver())

    r = cirq.ParamResolver({'a': 0.5, 'b': 0.1, 'c': 1 + 1j})
    assert bool(r)

    assert r.value_of('x') == sympy.Symbol('x')
    assert r.value_of('a') == 0.5
    assert r.value_of(sympy.Symbol('a')) == 0.5
    assert r.value_of(0.5) == 0.5
    assert r.value_of(sympy.Symbol('b')) == 0.1
    assert r.value_of(0.3) == 0.3
    assert r.value_of(sympy.Symbol('a') * 3) == 1.5
    assert r.value_of(sympy.Symbol('b') / 0.1 - sympy.Symbol('a')) == 0.5

    assert r.value_of(sympy.pi) == np.pi
    assert r.value_of(2 * sympy.pi) == 2 * np.pi
    assert r.value_of('c') == 1 + 1j
    assert r.value_of(sympy.I * sympy.pi) == np.pi * 1j 
开发者ID:quantumlib,项目名称:Cirq,代码行数:21,代码来源:resolver_test.py

示例5: grim_to_sympy

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def grim_to_sympy(expr, **kwargs):
    import sympy
    assert isinstance(expr, Expr)
    if expr.is_integer():
        return sympy.sympify(int(expr))
    if expr.is_symbol():
        if expr == Pi:
            return sympy.pi
        if expr == ConstI:
            return sympy.I
        if expr == ConstE:
            return sympy.E
        return sympy.Symbol(str(expr))
    head = expr.head()
    args = [grim_to_sympy(x, **kwargs) for x in expr.args()]
    if head in (Pos, Parentheses, Brackets, Braces, AngleBrackets, Logic):
        x, = args
        return x
    if expr.head() == Add:
        return sympy.Add(*args)
    if expr.head() == Mul:
        return sympy.Mul(*args)
    if expr.head() == Neg:
        x, = args
        return -x
    if expr.head() == Sub:
        a, b = args
        return a - b
    if expr.head() == Div:
        p, q = args
        return p / q
    if expr.head() == Pow:
        b, e = args
        return b ** e
    if expr.head() == Sqrt:
        x, = args
        return sympy.sqrt(x)
    raise NotImplementedError("converting %s to SymPy", expr.head()) 
开发者ID:fredrik-johansson,项目名称:fungrim,代码行数:40,代码来源:sympy_interface.py

示例6: test_fcode_complex

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def test_fcode_complex():
    assert fcode(I) == "      cmplx(0,1)"
    x = symbols('x')
    assert fcode(4*I) == "      cmplx(0,4)"
    assert fcode(3 + 4*I) == "      cmplx(3,4)"
    assert fcode(3 + 4*I + x) == "      cmplx(3,4) + x"
    assert fcode(I*x) == "      cmplx(0,1)*x"
    assert fcode(3 + 4*I - x) == "      cmplx(3,4) - x"
    x = symbols('x', imaginary=True)
    assert fcode(5*x) == "      5*x"
    assert fcode(I*x) == "      cmplx(0,1)*x"
    assert fcode(3 + x) == "      x + 3" 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:14,代码来源:test_fcode.py

示例7: EM_Waves_in_Geom_Calculus_Complex

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def EM_Waves_in_Geom_Calculus_Complex():
    #Print_Function()
    X = (t,x,y,z) = symbols('t x y z',real=True)
    g = '1 # # 0,# 1 # 0,# # 1 0,0 0 0 -1'
    coords = (xE,xB,xk,t) = symbols('x_E x_B x_k t',real=True)
    (EBkst,eE,eB,ek,et) = Ga.build('e_E e_B e_k e_t',g=g,coords=coords)

    i = EBkst.i

    E,B,k,w = symbols('E B k omega',real=True)

    F = E*eE*et+i*B*eB*et
    K = k*ek+w*et
    X = xE*eE+xB*eB+xk*ek+t*et
    KX = (K|X).scalar()
    F = F*exp(I*KX)

    g = EBkst.g

    print('g =', g)
    print('X =', X)
    print('K =', K)
    print('K|X =', KX)
    print('F =', F)

    gradF = EBkst.grad*F

    gradF = gradF.simplify()

    (gradF).Fmt(3,'grad*F = 0')

    gradF = gradF.subs({g[0,1]:0,g[0,2]:0,g[1,2]:0})

    KX = KX.subs({g[0,1]:0,g[0,2]:0,g[1,2]:0})

    print(r'%\mbox{Substituting }e_{E}\cdot e_{B} = e_{E}\cdot e_{k} = e_{B}\cdot e_{k} = 0')

    (gradF / (I*exp(I*KX))).Fmt(3,r'%\lp\bm{\nabla}F\rp/\lp ie^{iK\cdot X}\rp = 0')

    return 
开发者ID:pygae,项目名称:galgebra,代码行数:42,代码来源:linear_EM_waves.py

示例8: test_conv9

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def test_conv9():
    x = Symbol("x")
    y = Symbol("y")
    assert (I)._sympy_() == sympy.I
    assert (2*I+3)._sympy_() == 2*sympy.I+3
    assert (2*I/5+Integer(3)/5)._sympy_() == 2*sympy.I/5+sympy.S(3)/5
    assert (x*I+3)._sympy_() == sympy.Symbol("x")*sympy.I + 3
    assert (x+I*y)._sympy_() == sympy.Symbol("x") + sympy.I*sympy.Symbol("y") 
开发者ID:symengine,项目名称:symengine.py,代码行数:10,代码来源:test_sympy_conv.py

示例9: test_conv9b

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def test_conv9b():
    x = Symbol("x")
    y = Symbol("y")
    assert sympify(sympy.I) == I
    assert sympify(2*sympy.I+3) == 2*I+3
    assert sympify(2*sympy.I/5+sympy.S(3)/5) == 2*I/5+Integer(3)/5
    assert sympify(sympy.Symbol("x")*sympy.I + 3) == x*I+3
    assert sympify(sympy.Symbol("x") + sympy.I*sympy.Symbol("y")) == x+I*y 
开发者ID:symengine,项目名称:symengine.py,代码行数:10,代码来源:test_sympy_conv.py

示例10: test_mpc

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def test_mpc():
    if have_mpc:
        a = ComplexMPC('1', '2', 100)
        b = sympy.Float(1, 29) + sympy.Float(2, 29) * sympy.I
        assert sympify(b) == a
        assert b == a._sympy_() 
开发者ID:symengine,项目名称:symengine.py,代码行数:8,代码来源:test_sympy_conv.py

示例11: _eval_commutator_SigmaY

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def _eval_commutator_SigmaY(self, other, **hints):
        if self.name != other.name:
            return Integer(0)
        else:
            return 2 * I * SigmaZ(self.name) 
开发者ID:sympsi,项目名称:sympsi,代码行数:7,代码来源:pauli.py

示例12: _eval_commutator_SigmaZ

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def _eval_commutator_SigmaZ(self, other, **hints):
        if self.name != other.name:
            return Integer(0)
        else:
            return - 2 * I * SigmaY(self.name) 
开发者ID:sympsi,项目名称:sympsi,代码行数:7,代码来源:pauli.py

示例13: __mul__

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def __mul__(self, other):

        if isinstance(other, SigmaOpBase) and self.name != other.name:
            # Pauli matrices with different labels commute; sort by name
            if self.name < other.name:
                return Mul(self, other)
            else:
                return Mul(other, self)

        if isinstance(other, SigmaX) and self.name == other.name:
            return Integer(1)

        if isinstance(other, SigmaY) and self.name == other.name:
            return I * SigmaZ(self.name)

        if isinstance(other, SigmaZ) and self.name == other.name:
            return - I * SigmaY(self.name)

        if isinstance(other, SigmaMinus) and self.name == other.name:
            return (Integer(1)/2 + SigmaZ(self.name)/2)

        if isinstance(other, SigmaPlus) and self.name == other.name:
            return (Integer(1)/2 - SigmaZ(self.name)/2)

        if isinstance(other, Mul):
            args1 = tuple(arg for arg in other.args if arg.is_commutative)
            args2 = tuple(arg for arg in other.args if not arg.is_commutative)
            x = self
            for y in args2:
                x = x * y
            return Mul(*args1) * x

        return Mul(self, other) 
开发者ID:sympsi,项目名称:sympsi,代码行数:35,代码来源:pauli.py

示例14: _eval_commutator_SigmaX

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def _eval_commutator_SigmaX(self, other, **hints):
        if self.name != other.name:
            return Integer(0)
        else:
            return - 2 * I * SigmaZ(self.name) 
开发者ID:sympsi,项目名称:sympsi,代码行数:7,代码来源:pauli.py

示例15: _represent_default_basis

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import I [as 别名]
def _represent_default_basis(self, **options):
        format = options.get('format', 'sympy')
        if format == 'sympy':
            return Matrix([[0, -I], [I, 0]])
        else:
            raise NotImplementedError('Representation in format ' +
                                      format + ' not implemented.') 
开发者ID:sympsi,项目名称:sympsi,代码行数:9,代码来源:pauli.py


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