https://www.jianshu.com/p/027e3cece2f6
定义变量x
,y
:
from sympy import * x, y = symbols('x, y')
定义函数\(z=x^2+y^2+xy+2\):
z = x**2 + y**2 + x*y + 2 z.subs({x: 1, y: 2}) // 9
diff
函数用来求偏导:
dx = diff(z, x) // 2*x + y dx.subs({x: 1, y: 2}) // 4 dy = diff(z, y) // x + 2*y dy.subs({x: 1, y: 2}) // 5