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

Python symengine.sympify函数代码示例

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

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



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


示例16: test_tuples_lists

def test_tuples_lists():
    x = sympy.Symbol("x")
    y = sympy.Symbol("y")
    z = sympy.Symbol("z")
    l = [x, y, z, x*y, z**y]
    t = (x, y, z, x*y, z**y)
    x = Symbol("x")
    y = Symbol("y")
    z = Symbol("z")
    l2 = [x, y, z, x*y, z**y]
    t2 = (x, y, z, x*y, z**y)
    assert sympify(l) == l2
    assert sympify(t) == t2
    assert sympify(l) != t2
    assert sympify(t) != l2

    assert l == l2
    assert t == t2
    assert l != t2
    assert t != l2
开发者ID:Upabjojr,项目名称:symengine,代码行数:20,代码来源:test_sympy_conv.py


示例17: build_functions

def build_functions(sympy_graph, variables, parameters=None, wrt=None, include_obj=True, include_grad=False, include_hess=False, cse=True):
    if wrt is None:
        wrt = sympify(tuple(variables))
    if parameters is None:
        parameters = []
    else:
        parameters = [wrap_symbol_symengine(p) for p in parameters]
    variables = tuple(variables)
    parameters = tuple(parameters)
    func, grad, hess = None, None, None
    inp = sympify(variables + parameters)
    graph = sympify(sympy_graph)
    # TODO: did not replace zoo with oo
    if include_obj:
        func = lambdify(inp, [graph], backend='llvm', cse=cse)
    if include_grad or include_hess:
        grad_graphs = list(graph.diff(w) for w in wrt)
        if include_grad:
            grad = lambdify(inp, grad_graphs, backend='llvm', cse=cse)
        if include_hess:
            hess_graphs = list(list(g.diff(w) for w in wrt) for g in grad_graphs)
            hess = lambdify(inp, hess_graphs, backend='llvm', cse=cse)
    return BuildFunctionsResult(func=func, grad=grad, hess=hess)
开发者ID:pycalphad,项目名称:pycalphad,代码行数:23,代码来源:sympydiff_utils.py


示例18: Plot3D

    def Plot3D(self, func, xrng, yrng):
        """
        Sets a surface to the Graphics object. The parameters are as follows:

                - ``func``: the function to be plotted,
                - ``xrng``: a triple of the form `(x, a, b)`, where `x` is the first `func`s independents variable, over the range `[a, b]`,
                - ``yrng``: a triple of the form `(y, c, d)`, where `x` is the second `func`'s	independents variable, over the range `[c, d]`.
        """
        import numpy as np
        if self.PlotType == '':
            self.PlotType = '3D'
        elif self.PlotType != '3D':
            raise Exception("Cannot combine 2d and 3d plots")

        if self.Env == 'numeric':
            f_ = func
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_ = lambdify((xrng[0], yrng[0]), func, "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_ = fast_callable(func, vars=[xrng[0], yrng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_func = sympify(func)
            f_ = lambdify((xrng[0], yrng[0]), t_func, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted.")
        # self.f_ = f_
        x_stp_lngt = float(xrng[2] - xrng[1]) / self.NumPoints
        y_stp_lngt = float(yrng[2] - yrng[1]) / self.NumPoints
        if self.X == []:
            self.X = [xrng[1] + i *
                      x_stp_lngt for i in range(self.NumPoints + 1)]
            self.xmin = xrng[1]
            self.xmax = xrng[2]
            self.Y = [yrng[1] + i *
                      y_stp_lngt for i in range(self.NumPoints + 1)]
            self.ymin = yrng[1]
            self.ymax = yrng[2]
        X = np.array(self.X)
        Y = np.array(self.Y)
        self.X, self.Y = np.meshgrid(X, Y)
        self.Z = f_(self.X, self.Y)
        self.intX, self.intY = np.mgrid[xrng[1]:xrng[
            2]:x_stp_lngt, yrng[1]:yrng[2]:y_stp_lngt]
        self.intZ = f_(self.intX, self.intY)
开发者ID:mghasemi,项目名称:pyProximation,代码行数:49,代码来源:graphics.py


示例19: Plot2D

    def Plot2D(self, func, xrng, color='blue', legend="", thickness=1):
        """
        Appends a curve to the Graphics object. The parameters are as follows:

                - `func`: the function to be plotted,
                - `xrng`: a triple of the form `(x, a, b)`, where `x` is the `func`'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_ = func
        elif self.Env == 'sympy':
            from sympy import lambdify
            f_ = lambdify(xrng[0], func, "numpy")
        elif self.Env == 'sage':
            from sage.all import fast_callable
            f_ = fast_callable(func, vars=[xrng[0]])
        elif self.Env == 'symengine':
            from symengine import sympify
            from sympy import lambdify
            t_func = sympify(func)
            f_ = lambdify(xrng[0], t_func, "numpy")
        else:
            raise Exception(
                "The function type is not recognized. Only 'numeric', 'sympy' and 'sage' are accepted.")

        # if self.X == []:
        stp_lngt = float(xrng[2] - xrng[1]) / self.NumPoints
        self.X.append(
            [xrng[1] + i * stp_lngt for i in range(self.NumPoints + 1)])
        self.xmin = xrng[1]
        self.xmax = xrng[2]
        TempY = [f_(x) for x in self.X[-1]]
        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,代码行数:49,代码来源:graphics.py


示例20: test_conv8b

def test_conv8b():
    e1 = sympy.Function("f")(sympy.Symbol("x"))
    e2 = sympy.Function("g")(sympy.Symbol("x"), sympy.Symbol("y"))
    assert sympify(e1) == function_symbol("f", Symbol("x"))
    assert sympify(e2) != function_symbol("f", Symbol("x"))
    assert sympify(e2) == function_symbol("g", Symbol("x"), Symbol("y"))

    e3 = sympy.Function("q")(sympy.Symbol("t"))
    assert sympify(e3) == function_symbol("q", Symbol("t"))
    assert sympify(e3) != function_symbol("f", Symbol("t"))
    assert sympify(e3) != function_symbol("q", Symbol("t"), Symbol("t"))
开发者ID:Upabjojr,项目名称:symengine,代码行数:11,代码来源:test_sympy_conv.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python symengine_wrapper.DenseMatrix类代码示例发布时间:2022-05-27
下一篇:
Python symbols.icon函数代码示例发布时间: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