📜  Python| sympy.Derivative() 方法

📅  最后修改于: 2022-05-13 01:54:39.709000             🧑  作者: Mango

Python| sympy.Derivative() 方法

借助sympy.Derivative()方法,我们可以创建 SymPy 表达式的未求值导数。它与diff()方法具有相同的语法。要评估未评估的导数,请使用doit()方法。

示例 #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