當前位置: 首頁>>代碼示例>>Python>>正文


Python sympy.Derivative方法代碼示例

本文整理匯總了Python中sympy.Derivative方法的典型用法代碼示例。如果您正苦於以下問題:Python sympy.Derivative方法的具體用法?Python sympy.Derivative怎麽用?Python sympy.Derivative使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sympy的用法示例。


在下文中一共展示了sympy.Derivative方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_oprint

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def test_oprint():
    s = io.StringIO()
    with contextlib.redirect_stdout(s):
        oprint(
            'int', 1,
            'dictionary', dict(a=1, b=2),
            'set', {1},
            'tuple', (1, 2),
            'list', [1, 2, 3],
            'str', 'a quote: "',
            'deriv', Derivative(Symbol('x'), Symbol('x'), evaluate=False),
        )

    if has_ordered_dictionaries:
        assert s.getvalue() == textwrap.dedent("""\
            int        = 1
            dictionary = {a: 1, b: 2}
            set        = {1}
            tuple      = (1, 2)
            list       = [1, 2, 3]
            str        = a quote: "
            deriv      = D{x}x
            """) 
開發者ID:pygae,項目名稱:galgebra,代碼行數:25,代碼來源:test_printer.py

示例2: variables

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def variables(self):
        """
        Returns the variables with which the function in the specified
        arbitrary expression is evaluated

        Examples
        ========

        >>> from sympsi.operator import DifferentialOperator
        >>> from sympy import Symbol, Function, Derivative
        >>> x = Symbol('x')
        >>> f = Function('f')
        >>> d = DifferentialOperator(1/x*Derivative(f(x), x), f(x))
        >>> d.variables
        (x,)
        >>> y = Symbol('y')
        >>> d = DifferentialOperator(Derivative(f(x, y), x) +
        ...                          Derivative(f(x, y), y), f(x, y))
        >>> d.variables
        (x, y)
        """

        return self.args[-1].args 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:25,代碼來源:operator.py

示例3: function

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def function(self):
        """
        Returns the function which is to be replaced with the Wavefunction

        Examples
        ========

        >>> from sympsi.operator import DifferentialOperator
        >>> from sympy import Function, Symbol, Derivative
        >>> x = Symbol('x')
        >>> f = Function('f')
        >>> d = DifferentialOperator(Derivative(f(x), x), f(x))
        >>> d.function
        f(x)
        >>> y = Symbol('y')
        >>> d = DifferentialOperator(Derivative(f(x, y), x) +
        ...                          Derivative(f(x, y), y), f(x, y))
        >>> d.function
        f(x, y)
        """

        return self.args[-1] 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:24,代碼來源:operator.py

示例4: expr

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def expr(self):
        """
        Returns the arbitary expression which is to have the Wavefunction
        substituted into it

        Examples
        ========

        >>> from sympsi.operator import DifferentialOperator
        >>> from sympy import Function, Symbol, Derivative
        >>> x = Symbol('x')
        >>> f = Function('f')
        >>> d = DifferentialOperator(Derivative(f(x), x), f(x))
        >>> d.expr
        Derivative(f(x), x)
        >>> y = Symbol('y')
        >>> d = DifferentialOperator(Derivative(f(x, y), x) +
        ...                          Derivative(f(x, y), y), f(x, y))
        >>> d.expr
        Derivative(f(x, y), x) + Derivative(f(x, y), y)
        """

        return self.args[0] 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:25,代碼來源:operator.py

示例5: __new__

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def __new__(cls, expr, *dims, **kwargs):
        if type(expr) == sympy.Derivative:
            raise ValueError("Cannot nest sympy.Derivative with devito.Derivative")
        if not isinstance(expr, Differentiable):
            raise ValueError("`expr` must be a Differentiable object")

        new_dims, orders, fd_o, var_count = cls._process_kwargs(expr, *dims, **kwargs)

        # Construct the actual Derivative object
        obj = Differentiable.__new__(cls, expr, *var_count)
        obj._dims = tuple(OrderedDict.fromkeys(new_dims))

        skip = kwargs.get('preprocessed', False) or obj.ndims == 1

        obj._fd_order = fd_o if skip else DimensionTuple(*fd_o, getters=obj._dims)
        obj._deriv_order = orders if skip else DimensionTuple(*orders, getters=obj._dims)
        obj._side = kwargs.get("side")
        obj._transpose = kwargs.get("transpose", direct)
        obj._subs = as_tuple(kwargs.get("subs"))
        obj._x0 = kwargs.get('x0', None)
        return obj 
開發者ID:devitocodes,項目名稱:devito,代碼行數:23,代碼來源:derivative.py

示例6: __call__

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def __call__(self, x0=None, fd_order=None, side=None):
        if self.ndims == 1:
            _fd_order = fd_order or self._fd_order
            _side = side or self._side
            new_x0 = {self.dims[0]: x0} if x0 is not None else self.x0
            return self._new_from_self(fd_order=_fd_order, side=_side, x0=new_x0)

        if side is not None:
            raise TypeError("Side only supported for first order single"
                            "Dimension derivative such as `.dxl` or .dx(side=left)")
        # Cross derivative
        _x0 = self._x0 or {}
        _fd_order = dict(self.fd_order._getters)
        try:
            _fd_order.update(**(fd_order or {}))
            _fd_order = tuple(_fd_order.values())
            _fd_order = DimensionTuple(*_fd_order, getters=self.dims)
            _x0.update(x0)
        except AttributeError:
            raise TypeError("Multi-dimensional Derivative, input expected as a dict")

        return self._new_from_self(fd_order=_fd_order, x0=_x0) 
開發者ID:devitocodes,項目名稱:devito,代碼行數:24,代碼來源:derivative.py

示例7: find_functions

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def find_functions(expr):
    f_lst = []
    for f in list(expr.atoms(Function)):
        if str(f) not in GaPrinter.function_names:
            f_lst.append(f)
    f_lst += list(expr.atoms(Derivative))
    return f_lst 
開發者ID:pygae,項目名稱:galgebra,代碼行數:9,代碼來源:printer.py

示例8: __init__

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def __init__(self, base=None, fct=None, deriv=None, on=True, debug=False):
        if on:
            OS = 'unix'
            if 'win' in sys.platform and 'darwin' not in sys.platform:
                OS = 'win'

            if base is None:
                Eprint.base = Eprint.ColorCode[Eprint.defaults[(OS, 'base')]]
            else:
                Eprint.base = Eprint.ColorCode[base]
            if fct is None:
                Eprint.fct = Eprint.ColorCode[Eprint.defaults[(OS, 'fct')]]
            else:
                Eprint.fct = Eprint.ColorCode[fct]
            if deriv is None:
                Eprint.deriv = Eprint.ColorCode[Eprint.defaults[(OS, 'deriv')]]
            else:
                Eprint.deriv = Eprint.ColorCode[deriv]
            Eprint.normal = '\033[0m'

            if debug:
                print('Enhanced Printing is on:')
                print('Base/Blade color is ' + Eprint.InvColorCode[Eprint.base])
                print('Function color is ' + Eprint.InvColorCode[Eprint.fct])
                print('Derivative color is ' + Eprint.InvColorCode[Eprint.deriv] + '\n')

            Eprint.base = '\033[' + Eprint.base + 'm'
            Eprint.fct = '\033[' + Eprint.fct + 'm'
            Eprint.deriv = '\033[' + Eprint.deriv + 'm' 
開發者ID:pygae,項目名稱:galgebra,代碼行數:31,代碼來源:printer.py

示例9: _eval_derivative

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def _eval_derivative(self, symbol):
        new_expr = Derivative(self.expr, symbol)
        return DifferentialOperator(new_expr, self.args[-1])

    #-------------------------------------------------------------------------
    # Printing
    #------------------------------------------------------------------------- 
開發者ID:sympsi,項目名稱:sympsi,代碼行數:9,代碼來源:operator.py

示例10: diff

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def diff(self, *symbols, **assumptions):
        """
        Like ``sympy.diff``, but return a ``devito.Derivative`` instead of a
        ``sympy.Derivative``.
        """
        from devito.finite_differences.derivative import Derivative
        return Derivative(self, *symbols, **assumptions) 
開發者ID:devitocodes,項目名稱:devito,代碼行數:9,代碼來源:differentiable.py

示例11: _new_from_self

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def _new_from_self(self, **kwargs):
        _kwargs = {'deriv_order': self.deriv_order, 'fd_order': self.fd_order,
                   'side': self.side, 'transpose': self.transpose, 'subs': self._subs,
                   'x0': self.x0, 'preprocessed': True}
        expr = kwargs.pop('expr', self.expr)
        _kwargs.update(**kwargs)
        return Derivative(expr, *self.dims, **_kwargs) 
開發者ID:devitocodes,項目名稱:devito,代碼行數:9,代碼來源:derivative.py

示例12: _eval_fd

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def _eval_fd(self, expr):
        """
        Evaluate finite difference approximation of the Derivative.
        Evaluation is carried out via the following four steps:
        - 1: Evaluate derivatives within the expression. For example given
        `f.dx * g`, `f.dx` will be evaluated first.
        - 2: Evaluate the finite difference for the (new) expression.
        - 3: Evaluate remaining terms (as `g` may need to be evaluated
        at a different point).
        - 4: Apply substitutions.

        """
        # Step 1: Evaluate derivatives within expression
        expr = getattr(expr, '_eval_deriv', expr)

        # Step 2: Evaluate FD of the new expression
        if self.side is not None and self.deriv_order == 1:
            res = first_derivative(expr, self.dims[0], self.fd_order,
                                   side=self.side, matvec=self.transpose,
                                   x0=self.x0)
        elif len(self.dims) > 1:
            res = cross_derivative(expr, self.dims, self.fd_order, self.deriv_order,
                                   matvec=self.transpose, x0=self.x0)
        else:
            res = generic_derivative(expr, *self.dims, self.fd_order, self.deriv_order,
                                     matvec=self.transpose, x0=self.x0)

        # Step 3: Evaluate remaining part of expression
        res = res.evaluate

        # Step 4: Apply substitution
        for e in self._subs:
            res = res.xreplace(e)
        return res 
開發者ID:devitocodes,項目名稱:devito,代碼行數:36,代碼來源:derivative.py

示例13: ordered_symbols

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def ordered_symbols(self):
        """
        :return: list of all symbols in this model, topologically sorted so they
            can be evaluated in the correct order.

            Within each group of equal priority symbols, we sort by the order of
            the derivative.
        """
        key_func = lambda s: [isinstance(s, sympy.Derivative),
                           isinstance(s, sympy.Derivative) and s.derivative_count]
        symbols = []
        for symbol in toposort(self.connectivity_mapping):
            symbols.extend(sorted(symbol, key=key_func))

        return symbols 
開發者ID:tBuLi,項目名稱:symfit,代碼行數:17,代碼來源:models.py

示例14: _partial_diff

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def _partial_diff(var, *params):
    """
    Sympy does not handle repeated partial derivation correctly, e.g.
    D(D(y, a), a) = D(y, a, a) but D(D(y, a), b) = 0.
    Use this function instead to prevent evaluation to zero.
    """
    if isinstance(var, sympy.Derivative):
        return sympy.Derivative(var.expr, *(var.variables + params))
    else:
        return D(var, *params) 
開發者ID:tBuLi,項目名稱:symfit,代碼行數:12,代碼來源:models.py

示例15: _partial_subs

# 需要導入模塊: import sympy [as 別名]
# 或者: from sympy import Derivative [as 別名]
def _partial_subs(func, func2vars):
    """
    Partial-bug proof substitution. Works by making the substitutions on
    the expression inside the derivative first, and then rebuilding the
    derivative safely without evaluating it using `_partial_diff`.
    """
    if isinstance(func, sympy.Derivative):
        new_func = func.expr.xreplace(func2vars)
        new_variables = tuple(var.xreplace(func2vars)
                              for var in func.variables)
        return _partial_diff(new_func, *new_variables)
    else:
        return func.xreplace(func2vars) 
開發者ID:tBuLi,項目名稱:symfit,代碼行數:15,代碼來源:models.py


注:本文中的sympy.Derivative方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。