本文整理汇总了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
""")
示例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
示例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]
示例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]
示例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
示例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)
示例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
示例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'
示例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
#-------------------------------------------------------------------------
示例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)
示例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)
示例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
示例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
示例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)
示例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)