矩阵导数没有得到评估

Matrix derivative doesn't get evaluated

我正在尝试计算最一般的 3D 旋转矩阵的偏导数,如下所示:

phi, psi, theta = sympy.symbols("phi, psi, theta")
RMatrixPhi = sympy.Matrix([[cos(phi), sin(phi), 0],
                           [-sin(phi), cos(phi), 0],
                           [0,          0,       1]])
RMatrixPsi = sympy.Matrix([[cos(psi),  0, sin(psi)],
                           [0,         1,   0     ],
                           [-sin(psi), 0, cos(psi)]])
RMatrixTheta = sympy.Matrix([[1,    0,         0        ],
                             [0,  cos(theta), sin(theta)],
                             [0, -sin(theta), cos(theta)  ]])
RMatrix = RMatrixPhi * RMatrixPsi * RMatrixTheta
D = diff(RMatrix, phi)

但是,D 是一个 sympy.Derivative 对象,我无法对其求值, 它只是打印为 Derivative(Matrix(...))

我让它工作的唯一方法是写

sympy.Matrix([sympy.diff(r, phi) for r in RMatrix]).reshape(3,3)

但这看起来很难看。计算此类导数的正确方法是什么?

Matrix class 有一个名为 diff 方法 ,根据文档...

Docstring: Calculate the derivative of each element in the matrix.

所以使用

RMatrix.diff(phi)

执行逐元素推导。