首页 > 解决方案 > 在保持参数常数/具有固定参数的同时,如何在 sympy 中象征性地进行偏导数?

问题描述

我试图以方程 6.1 中第 2 页上的形式获得偏导数。该等式中下标的含义是具有对其求导的变量所依赖的参数之一保持不变。Sympy 中的 Derivative() 函数中是否有任何参数允许这样做?

到目前为止,这是我的代码:

from sympy import*
init_printing(use_unicode=True)
#Create the variables
s = symbols('s') #x, y, and t
z = symbols('z') #vertical coordinate

#Create the functions that depend on those variables
zeta = Function('zeta')(s,z)
A = Function('A')(s,zeta)

#Here we actually take the derivative
expr = Derivative(A,z)
expr = expr.doit()
#This gives a basic partial derivative, but does not give a partial derivative with one of the parameters held constant

是否有某种类型的 kwargs 可以传递给允许这样做的 Derivative 函数?

标签: pythonsympyderivative

解决方案


没有直接的方法来表示 sympy 中的“第 n 个参数”的导数,但您可以使用虚拟变量和子变量。就像是:

In [24]: x, y, z = symbols('x, y, z')

In [25]: A = Function('A')

In [26]: f = Function('f')

In [27]: A(x, z).diff(x).subs(z, f(x, y))
Out[27]: 
⎛∂          ⎞│         
⎜──(A(x, z))⎟│         
⎝∂x         ⎠│z=f(x, y)

推荐阅读