Is there any way to convert a symmetric SymPy matrix to two-form ?
有没有办法将对称SymPy矩阵转换为双形式?
When I try to use
当我尝试使用时
sym.diffgeom.metric_to_Christoffel_1st(expr)
for the following matrix
对于以下矩阵
Matrix([[a**2/(cos(theta) - cosh(eta))**2, 0, 0],
[0, a**2/(cos(theta) - cosh(eta))**2, 0],
[0, 0, a**2*sinh(eta)**2/(cos(theta) - cosh(eta))**2]])
I get the error
我收到了错误
ValueError: The input expression is not a two-form.
The matrix expression is the metric for the transformation between Cartesian and Toroidal coordinates. I get the same error when I try to use the metric on the other sympy.diffgeom.metric_to_*
functions.
矩阵表达式是笛卡尔坐标和环形坐标之间转换的度量。当我尝试在其他sympy.diffgeom.metric_to_ *函数上使用度量时,我得到相同的错误。
1 个解决方案
#1
1
Supposing your metric matrix is stored in variable m, you can do:
假设您的度量矩阵存储在变量m中,您可以执行以下操作:
diff_forms = your_coord_system.base_oneforms()
metric_diff_form = sum([TensorProduct(di, dj)*m[i, j] for i, di in enumerate(diff_forms) for j, dj in enumerate(diff_forms)])
Beware that for one-forms, TensorProduct(dx, dy) = -TensorProduct(dy, dx), this means that if your matrix is not diagonal, element m[i, j] will be summed to element m[i, j] for i != j.
请注意,对于单一形式,TensorProduct(dx,dy)= -TensorProduct(dy,dx),这意味着如果您的矩阵不是对角线,则元素m [i,j]将被求和为元素m [i,j]对于我!= j。
If you have a symmetric matrix, and you wish to add the off-diagonal elements only once, then add a 1/2 term for i != j.
如果你有一个对称矩阵,并且你希望只添加一次非对角线元素,那么为i!= j添加一个1/2项。
#1
1
Supposing your metric matrix is stored in variable m, you can do:
假设您的度量矩阵存储在变量m中,您可以执行以下操作:
diff_forms = your_coord_system.base_oneforms()
metric_diff_form = sum([TensorProduct(di, dj)*m[i, j] for i, di in enumerate(diff_forms) for j, dj in enumerate(diff_forms)])
Beware that for one-forms, TensorProduct(dx, dy) = -TensorProduct(dy, dx), this means that if your matrix is not diagonal, element m[i, j] will be summed to element m[i, j] for i != j.
请注意,对于单一形式,TensorProduct(dx,dy)= -TensorProduct(dy,dx),这意味着如果您的矩阵不是对角线,则元素m [i,j]将被求和为元素m [i,j]对于我!= j。
If you have a symmetric matrix, and you wish to add the off-diagonal elements only once, then add a 1/2 term for i != j.
如果你有一个对称矩阵,并且你希望只添加一次非对角线元素,那么为i!= j添加一个1/2项。