【发布时间】:2019-09-18 19:22:50
【问题描述】:
当谈到sympy 时,我非常喜欢,而且我不知道如何以格式良好的方式生成输出。现在我已经计算了我的潜在函数的 Hessian 矩阵:
V = 1/2*kOH*(r1)**2 +1/2*kOH*(r2)**2 +1/2*kHH*(r3)**2
三个谐振子项的一般形式为:
1/2*k*r**2.
所有变量都是正数和实数。
对我来说问题是,当我打印我的矩阵时,条目尚未解决,仅以功能方式显示。我希望在已经执行偏导数之后将条目放在表单中,而不仅仅是显示矩阵中每个点需要执行的推导。
def Hessian():
'''
sympy calc of hessian Matrix H for IR normal modes analysis
from a potential V.
Must be multiplicable with 9x9 matrix (somehow) in
the equation: F = M**(-1/2) * H * M**(-1/2)
Here, F is the mass weighted Hessian, whose Eigenvalues
contain the frequencies of the normal modes of water.
M comes from the multiplication of the 3N-Dimensional
mass-vector m with a 3N-dimensional identity matrix:
M = m*I, I.shape = 3*N, 3*N, N = number of atoms in water.
'''
kOH, kHH, r1, r2, r3 = sy.symbols('kOH kHH r1 r2 r3', real=True, positive=True)
V = sy.Function('V')(1/2*kOH*(r1)**2 +1/2*kOH*(r2)**2 +1/2*kHH*(r3)**2)
f = sy.hessian(V,[r1, r2, r3])
sy.pprint(f)
Hessian()
附加:这并不是事物计算方面的真正一部分,因此也不是问题的一部分,但如果有人知道他们在科学方面的知识:你能告诉我(3 ,3) 潜在依赖于三个距离的 Hessian 矩阵应该乘以 (9,9) 质量矩阵?如果您有兴趣,函数的注释包含科学背景。
【问题讨论】:
标签: python sympy hessian-matrix