赞
踩
diff(func,x,n)
其中,func是要求导的函数,x是要对其求导的变量,n是可选的,表示求n阶导数,默认为1阶导数。
注意,在用diff进行求导之前,需要用symbols函数定义变量
- from sympy import diff
- from sympy import symbols
- def func(x):
- return x**4
- x = symbols("x")
- print(diff(func(x),x))
- from sympy import diff
- from sympy import symbols
- def func(x):
- return x**4
- x = symbols("x")
- print(diff(func(x),x,2))
- from sympy import diff
- from sympy import symbols
- def func(x,y):
- return x**4+y**3
- x,y = symbols("x,y")
- print(diff(func(x,y),x))
- from sympy import diff
- from sympy import symbols
- def func(x,y):
- return x**4
- x = symbols("x")
- print(diff(func(x),x).subs(x,2)) # 表示将x = 2,带入导函数4*x**3中
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。