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


Python symengine.sympify函数代码示例

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


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

示例1: ParamPlot2D

    def ParamPlot2D(self, funcs, rng, color='blue', legend="", thickness=1):
        """
        Appends a parametric curve to the Graphics object. The parameters are as follows:

                - ``funcs``: the tupleof functions to be plotted,
                - ``rng``: a triple of the form `(t, a, b)`, where `t` is the `funcs`'s independents variable, over the range `[a, b]`,
                - ``color``: the color of the current curve,
                - ``legend``: the text for the legend of the current crve.
        """
        if self.PlotType == '':
            self.PlotType = '2D'
        elif self.PlotType != '2D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_0 = funcs[0]
            f_1 = funcs[1]
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_0 = lambdify(rng[0], funcs[0], "numpy")
            f_1 = lambdify(rng[0], funcs[1], "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_0 = fast_callable(funcs[0], vars=[rng[0]])
            f_1 = fast_callable(funcs[1], vars=[rng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_f0 = sympify(funcs[0])
            t_f1 = sympify(funcs[1])
            f_0 = lambdify((xrng[0], yrng[0]), t_f0, "numpy")
            f_1 = lambdify((xrng[0], yrng[0]), t_f1, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted.")

        # if self.X == []:
        stp_lngt = float(rng[2] - rng[1]) / self.NumPoints
        line_points = [rng[1] + i *
                       stp_lngt for i in range(self.NumPoints + 1)]
        TempX = [f_0(t) for t in line_points]
        self.X.append(TempX)
        if self.xmin is None:
            self.xmin = min(TempX)
            self.xmax = max(TempX)
        else:
            self.xmin = min(min(TempX), self.xmin)
            self.xmax = max(max(TempX), self.xmax)
        TempY = [f_1(t) for t in line_points]
        if self.ymin is None:
            self.ymin = min(TempY)
            self.ymax = max(TempY)
        else:
            self.ymin = min(min(TempY), self.ymin)
            self.ymax = max(max(TempY), self.ymax)
        self.Y.append(TempY)
        self.color.append(color)
        self.legend.append(legend)
        self.thickness.append(thickness)
        self.PlotCount += 1
开发者ID:mghasemi,项目名称:pyProximation,代码行数:60,代码来源:graphics.py

示例2: test_conv1b

def test_conv1b():
    x = sympy.Symbol("x")
    assert sympify(x) == Symbol("x")
    assert sympify(x) != Symbol("y")
    x = sympy.Symbol("y")
    assert sympify(x) != Symbol("x")
    assert sympify(x) == Symbol("y")
开发者ID:Upabjojr,项目名称:symengine,代码行数:7,代码来源:test_sympy_conv.py

示例3: test_conv2b

def test_conv2b():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    z = sympy.Symbol("z")
    e = x*y
    assert sympify(e) == Symbol("x")*Symbol("y")
    e = x*y*z
    assert sympify(e) == Symbol("x")*Symbol("y")*Symbol("z")
开发者ID:Upabjojr,项目名称:symengine,代码行数:8,代码来源:test_sympy_conv.py

示例4: test_conv3b

def test_conv3b():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    z = sympy.Symbol("z")
    e = x+y
    assert sympify(e) == Symbol("x")+Symbol("y")
    e = x+y+z
    assert sympify(e) == Symbol("x")+Symbol("y")+Symbol("z")
开发者ID:Upabjojr,项目名称:symengine,代码行数:8,代码来源:test_sympy_conv.py

示例5: test_conv4b

def test_conv4b():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    z = sympy.Symbol("z")
    e = x**y
    assert sympify(e) == Symbol("x")**Symbol("y")
    e = (x+y)**z
    assert sympify(e) == (Symbol("x")+Symbol("y"))**Symbol("z")
开发者ID:Upabjojr,项目名称:symengine,代码行数:8,代码来源:test_sympy_conv.py

示例6: test_conv6b

def test_conv6b():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    assert sympify(x/3) == Symbol("x") / 3
    assert sympify(3*x) == 3*Symbol("x")
    assert sympify(3+x) == 3+Symbol("x")
    assert sympify(3-x) == 3-Symbol("x")
    assert sympify(x/y) == Symbol("x") / Symbol("y")
开发者ID:Upabjojr,项目名称:symengine,代码行数:8,代码来源:test_sympy_conv.py

示例7: test_conv9b

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:Upabjojr,项目名称:symengine,代码行数:8,代码来源:test_sympy_conv.py

示例8: test_exp

def test_exp():
    x = Symbol("x")
    e1 = sympy.exp(sympy.Symbol("x"))
    e2 = exp(x)
    assert sympify(e1) == e2
    assert e1 == e2._sympy_()

    e1 = sympy.exp(sympy.Symbol("x")).diff(sympy.Symbol("x"))
    e2 = exp(x).diff(x)
    assert sympify(e1) == e2
    assert e1 == e2._sympy_()
开发者ID:Upabjojr,项目名称:symengine,代码行数:11,代码来源:test_sympy_conv.py

示例9: test_conv10b

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:Upabjojr,项目名称:symengine,代码行数:14,代码来源:test_sympy_conv.py

示例10: test_conv11

def test_conv11():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    x1 = Symbol("x")
    y1 = Symbol("y")
    e1 = sympy.Subs(sympy.Derivative(sympy.Function("f")(x, y), x), [x, y], [y, y])

    e2 = Subs(Derivative(function_symbol("f", x1, y1), [x1]), [x1, y1], [y1, y1])
    e3 = Subs(Derivative(function_symbol("f", x1, y1), [x1]), [y1, x1], [x1, y1])

    assert sympify(e1) == e2
    assert sympify(e1) != e3

    assert e2._sympy_() == e1
    assert e3._sympy_() != e1
开发者ID:Upabjojr,项目名称:symengine,代码行数:15,代码来源:test_sympy_conv.py

示例11: test_log

def test_log():
    x = Symbol("x")
    x1 = sympy.Symbol("x")

    assert log(x) == log(x1)
    assert log(x)._sympy_() == sympy.log(x1)
    assert sympify(sympy.log(x1)) == log(x)

    y = Symbol("y")
    y1 = sympy.Symbol("y")

    assert log(x, y) == log(x, y1)
    assert log(x1, y) == log(x1, y1)
    assert log(x, y)._sympy_() == sympy.log(x1, y1)
    assert sympify(sympy.log(x1, y1)) == log(x, y)
开发者ID:cbehan,项目名称:symengine.py,代码行数:15,代码来源:test_sympy_conv.py

示例12: test_abs

def test_abs():
    x = Symbol("x")
    e1 = abs(sympy.Symbol("x"))
    e2 = abs(x)
    assert sympify(e1) == e2
    assert e1 == e2._sympy_()

    e1 = abs(2*sympy.Symbol("x"))
    e2 = 2*abs(x)
    assert sympify(e1) == e2
    assert e1 == e2._sympy_()

    y = Symbol("y")
    e1 = abs(sympy.Symbol("y")*sympy.Symbol("x"))
    e2 = abs(y*x)
    assert sympify(e1) == e2
    assert e1 == e2._sympy_()
开发者ID:Upabjojr,项目名称:symengine,代码行数:17,代码来源:test_sympy_conv.py

示例13: wrap_symbol_symengine

def wrap_symbol_symengine(obj):
    from symengine import Symbol, sympify
    from sympy import Symbol as Symbol_sympy
    if isinstance(obj, Symbol):
        return obj
    elif isinstance(obj, Symbol_sympy):
        return sympify(obj)
    else:
        return Symbol(obj)
开发者ID:pycalphad,项目名称:pycalphad,代码行数:9,代码来源:utils.py

示例14: _build_constraint_functions

def _build_constraint_functions(variables, constraints, include_hess=False, parameters=None, cse=True):
    if parameters is None:
        parameters = []
    else:
        parameters = [wrap_symbol_symengine(p) for p in parameters]
    variables = tuple(variables)
    wrt = variables
    parameters = tuple(parameters)
    constraint__func, jacobian_func, hessian_func = None, None, None
    inp = sympify(variables + parameters)
    graph = sympify(constraints)
    constraint_func = lambdify(inp, [graph], backend='llvm', cse=cse)
    grad_graphs = list(list(c.diff(w) for w in wrt) for c in graph)
    jacobian_func = lambdify(inp, grad_graphs, backend='llvm', cse=cse)
    if include_hess:
        hess_graphs = list(list(list(g.diff(w) for w in wrt) for g in c) for c in grad_graphs)
        hessian_func = lambdify(inp, hess_graphs, backend='llvm', cse=cse)
    return ConstraintFunctions(cons_func=constraint_func, cons_jac=jacobian_func, cons_hess=hessian_func)
开发者ID:pycalphad,项目名称:pycalphad,代码行数:18,代码来源:constraints.py

示例15: test_conv12b

def test_conv12b():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    assert sympify(sympy.sinh(x/3)) == sinh(Symbol("x") / 3)
    assert sympify(sympy.cosh(x/3)) == cosh(Symbol("x") / 3)
    assert sympify(sympy.tanh(x/3)) == tanh(Symbol("x") / 3)
    assert sympify(sympy.coth(x/3)) == coth(Symbol("x") / 3)
    assert sympify(sympy.asinh(x/3)) == asinh(Symbol("x") / 3)
    assert sympify(sympy.acosh(x/3)) == acosh(Symbol("x") / 3)
    assert sympify(sympy.atanh(x/3)) == atanh(Symbol("x") / 3)
    assert sympify(sympy.acoth(x/3)) == acoth(Symbol("x") / 3)
开发者ID:cbehan,项目名称:symengine.py,代码行数:11,代码来源:test_sympy_conv.py


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