Python sympy.Derivative()方法
在sympy.Derivative()方法的帮助下,我们可以创建一个SymPy表达式的未评估导数。它的语法与diff()方法相同。要评估一个未评估的导数,请使用doit()方法。
语法: Derivative(expression, reference variable)
参数:
expression – 一个SymPy表达式,其未评估的导数被找到。
参考变量 –找到导数所涉及的变量。
返回:返回给定表达式的未评价导数。
示例 #1:
# import sympy
from sympy import *
x, y = symbols('x y')
expr = x**2 + 2 * y + y**3
print("Expression : {} ".format(expr))
# Use sympy.Derivative() method
expr_diff = Derivative(expr, x)
print("Derivative of expression with respect to x : {}".format(expr_diff))
print("Value of the derivative : {} ".format(expr_diff.doit()))
输出:
Expression : x**2 + y**3 + 2*y
Derivative of expression with respect to x : Derivative(x**2 + y**3 + 2*y, x)
Value of the derivative : 2*x
示例 #2:
# import sympy
from sympy import *
x, y = symbols('x y')
expr = y**2 * x**2 + 2 * y*x + x**3 * y**3
print("Expression : {} ".format(expr))
# Use sympy.Derivative() method
expr_diff = Derivative(expr, x, y)
print("Derivative of expression with respect to x : {}".format(expr_diff))
print("Value of the derivative : {} ".format(expr_diff.doit()))
输出:
Expression : x**3*y**3 + x**2*y**2 + 2*x*y
Derivative of expression with respect to x : Derivative(x**3*y**3 + x**2*y**2 + 2*x*y, x, y)
Value of the derivative : 9*x**2*y**2 + 4*x*y + 2