这里使用如下代码安装需要的包:
pip install -i https://mirrors.aliyun.com/pypi/simple/ sympy
import sympy as sp x, y, z = sp.symbols('x y z') fuc = z * sp.sin(2 * sp.pi * x + x * y / 5) # 原函数 fuc_x = sp.diff(fuc, x) fuc_y = sp.diff(fuc, y) fuc_z = sp.diff(fuc, z) print("对x求导 : ", fuc_x) print("对y求导 : ", fuc_y) print("对z求导 : ", fuc_z)
得到结果:
对x求导 : z*(y/5 + 2*pi)*cos(x*y/5 + 2*pi*x) 对y求导 : x*z*cos(x*y/5 + 2*pi*x)/5 对z求导 : sin(x*y/5 + 2*pi*x)
import sympy as sp x, y, z = sp.symbols('x y z') fuc = z * sp.sin(2 * sp.pi * x + x * y / 5) fuc_x = sp.diff(fuc, x) print("对x求导结果 : ", fuc_x) # 赋值 fun_x_value = float(fuc_x.evalf( subs={ x: 10, y: 5, z: 3})) print(fun_x_value)
结果得到:
对x求导 : z*(y/5 + 2*pi)*cos(x*y/5 + 2*pi*x) -18.333340296726984