python - 在保持参数常数/具有固定参数的同时,如何在 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 函数?
解决方案
没有直接的方法来表示 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)
推荐阅读
- apache-spark - Pyspark EMR 中步骤的 Cloudformation 模板
- javascript - 尝试导入错误:“addToCart”未从“../actions/cartActions”导出。使用 Redux
- r - r fread:如何阅读没有分隔符的 txt
- powerbi - 用户退出时如何处理 PowerBI 工作区和 OneDrive 文件同步?
- kubernetes - 使用 OpenShift 时必须使用 RedHat 操作系统吗?
- angular - 如何将 Angular Material Stepper 的 matStepperNext 按钮显示为启用/禁用?
- php - 尝试访问 PhpSpreadsheet 中 null 类型值的数组偏移量
- go - 如何使这个 golang for-select 代码工作?
- c# - iOS中是否有等效于xamarin.android DispatchTouchEvent()
- python - 如何使用 python 更改 VBA 模块的名称