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


Python Basic.sympify方法代码示例

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


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

示例1: sample2d

# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import sympify [as 别名]
def sample2d(f, x_args):
    """
    Samples a 2d function f over specified intervals and returns two
    arrays (X, Y) suitable for plotting with matlab (matplotlib)
    syntax. See examples\mplot2d.py.

    f is a function of one variable, such as x**2.
    x_args is an interval given in the form (var, min, max, n)
    """
    try:
        f = Basic.sympify(f)
    except:
        raise ValueError("f could not be interpretted as a SymPy function")
    try:
        x, x_min, x_max, x_n = x_args
    except:
        raise ValueError("x_args must be a tuple of the form (var, min, max, n)")

    x_l = float(x_max - x_min)
    x_d = x_l/float(x_n)
    X = arange(float(x_min), float(x_max)+x_d, x_d)

    Y = empty(len(X))
    for i in range(len(X)):
        try:
            Y[i] = float(f.subs(x, X[i]))
        except:
            Y[i] = None
    return X, Y
开发者ID:certik,项目名称:sympy-oldcore,代码行数:31,代码来源:sample.py

示例2: set_v_max

# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import sympify [as 别名]
 def set_v_max(self, v_max):
     if v_max is None:
         self._v_max = None
         return
     try:
         self._v_max = Basic.sympify(v_max)
         float(self._v_max.evalf())
     except:
         raise ValueError("v_max could not be interpreted as a number.")
开发者ID:certik,项目名称:sympy-oldcore,代码行数:11,代码来源:plot_interval.py

示例3: set_v_min

# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import sympify [as 别名]
 def set_v_min(self, v_min):
     if v_min is None:
         self._v_min = None
         return
     try:
         self._v_min = Basic.sympify(v_min)
         float(self._v_min.evalf())
     except:
         raise ValueError("v_min could not be interpreted as a number.")
开发者ID:certik,项目名称:sympy-oldcore,代码行数:11,代码来源:plot_interval.py

示例4: sample3d

# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import sympify [as 别名]
def sample3d(f, x_args, y_args):
    """
    Samples a 3d function f over specified intervals and returns three
    2d arrays (X, Y, Z) suitable for plotting with matlab (matplotlib)
    syntax. See examples\mplot3d.py.

    f is a function of two variables, such as x**2 + y**2.
    x_args and y_args are intervals given in the form (var, min, max, n)
    """
    x, x_min, x_max, x_n = None, None, None, None
    y, y_min, y_max, y_n = None, None, None, None
    try:
        f = Basic.sympify(f)
    except:
        raise ValueError("f could not be interpretted as a SymPy function")
    try:
        x, x_min, x_max, x_n = x_args
        y, y_min, y_max, y_n = y_args
    except:
        raise ValueError("x_args and y_args must be tuples of the form (var, min, max, intervals)")

    x_l = float(x_max - x_min)
    x_d = x_l/float(x_n)
    x_a = arange(float(x_min), float(x_max)+x_d, x_d)

    y_l = float(y_max - y_min)
    y_d = y_l/float(y_n)
    y_a = arange(float(y_min), float(y_max)+y_d, y_d)

    def meshgrid(x, y):
        """
        Taken from matplotlib.mlab.meshgrid.
        """
        x = array(x)
        y = array(y)
        numRows, numCols = len(y), len(x)
        x.shape = 1, numCols
        X = repeat(x, numRows, 0)

        y.shape = numRows, 1
        Y = repeat(y, numCols, 1)
        return X, Y

    X, Y = meshgrid(x_a, y_a)

    Z = ndarray((len(X), len(X[0])))
    for j in range(len(X)):
        for k in range(len(X[0])):
            try:
                Z[j][k] = float( f.subs(x, X[j][k]).subs(y, Y[j][k]) )
            except:
                Z[j][k] = 0
    return X, Y, Z
开发者ID:certik,项目名称:sympy-oldcore,代码行数:55,代码来源:sample.py

示例5: lambdastr

# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import sympify [as 别名]
def lambdastr(*args):
    """
    >>> from sympy import symbols
    >>> x,y,z = symbols('xyz')
    >>> lambdastr(x**2, [x])
    'lambda x: (x**2)'
    >>> lambdastr([z,y,x], [x,y,z])
    'lambda x,y,z: (z,y,x)'
    """
    assert len(args) == 2

    if isinstance(args[0], str) and isinstance(args[1], str):
        exprs, vargs = args

    elif isinstance(args[1], (list, tuple)):
        vargs = args[1]

        for v in vargs:
            assert isinstance(v, Symbol)

        if isinstance(args[0], (list, tuple)):
            exprs = list(args[0])
        else: exprs = [args[0]]

        for e in xrange(len(exprs)):
            exprs[e] = Basic.sympify(exprs[e])
            for a in exprs[e].atoms(type=Symbol):
                assert a in vargs

        vargs = ','.join(str(v) for v in vargs)
        exprs = ','.join(str(e) for e in exprs)

    else: raise ValueError("Lambdification requires arguments "
                           "of the form expr(s), vars. Examples: "
                           "(x**2, [x]) or ([x**2, 1/y], [x,y]).")

    return "lambda %s: (%s)" % (vargs, exprs)
开发者ID:certik,项目名称:sympy-oldcore,代码行数:39,代码来源:lambdify.py

示例6: mathml

# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import sympify [as 别名]
def mathml(expr):
    """Returns the MathML representation of expr"""
    s = MathMLPrinter()
    return s.doprint(Basic.sympify(expr))
开发者ID:certik,项目名称:sympy-oldcore,代码行数:6,代码来源:mathml.py


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