Compute Christoffel symbols using Mathematica
Compute Christoffel symbols using Mathematica
copyright@沈正
contact kantopenhauer@whu.edu.cn
contact kantopenhauer@whu.edu.cn
This is not a quite practical topic since there have been ready-made packages like xAct or others that work very well with much better extensibility, nevertheless, it may serve as a good exercise for beginners in GR or tensor calculus
虽然实践意义不大,因为我们已经有了非常棒的xAct或其它包,但作为初学广义相对论或张量计算的一个练习还是挺好的
This is not a quite practical topic since there have been ready-made packages like xAct or others that work very well with much better extensibility, nevertheless, it may serve as a good exercise for beginners in GR or tensor calculus
虽然实践意义不大,因为我们已经有了非常棒的xAct或其它包,但作为初学广义相对论或张量计算的一个练习还是挺好的
虽然实践意义不大,因为我们已经有了非常棒的xAct或其它包,但作为初学广义相对论或张量计算的一个练习还是挺好的
In[]:=
(*clear all assignment清除变量赋值*)Clear[coordnt,metric,inversemetric,Chrstf]
In[]:=
n=4
Out[]=
4
In[]:=
(*define coordinates as coordnty;定义坐标coodnt*)coordnt = {t, r, θ,ϕ}
Out[]=
{t,r,θ,ϕ}
(*inputmetric*)
g
αβ
输入度归张量g
αβ
In[]:=
metric=
-1-2 M r | 0 | 0 | 0 |
0 | -1 1-2 M r | 0 | 0 |
0 | 0 | 2 r | 0 |
0 | 0 | 0 | 2 r 2 (Sin[θ]) |
Out[]=
-1+,0,0,0,0,,0,0,{0,0,,0},{0,0,0,}
2M
r
1
1-
2M
r
2
r
2
r
2
Sin[θ]
In[]:=
inversemetric=Simplify[Inverse[metric]]
Out[]=
,0,0,0,0,1-,0,0,0,0,,0,0,0,0,
r
2M-r
2M
r
1
2
r
2
Csc[θ]
2
r
In[]:=
(*computeChristoffelsymbol计算克氏符*)Chrstf:=Chrstf=Simplify[Table[(1/2)*Sum[inversemetric[[i,s]]*(D[metric[[s,j]],coordnt[[k]]]+D[metric[[s,k]],coordnt[[j]]]-D[metric[[j,k]],coordnt[[s]]]),{s,1,n}(*summovers*)],{i,1,n},{j,1,n},{k,1,n}]]
(*outputChristoffelsymbols*)(*αdenotesrowindexinthemajormatrix*)(*βdenotescolumnindexinthemajormatrix*)(*γdenotesrowindexinsubordinarymatrices*)
α
Γ
βγ
In[]:=
Chrstf//MatrixForm
Out[]//MatrixForm=
|
|
|
| ||||||||||||||||
|
|
|
| ||||||||||||||||
|
|
|
| ||||||||||||||||
|
|
|
|
Contracted Christoffel Symbols
using (22) to compute contracted Christoffel symbol
using (22) to compute contracted Christoffel symbol
In[]:=
CChrstf:=CChrstf=Simplify[Table[(1/2)*Sum[inversemetric[[i,s]]*(D[metric[[s,i]],coordnt[[j]]]+D[metric[[s,j]],coordnt[[i]]]-D[metric[[j,i]],coordnt[[s]]]),{i,1,n},{s,1,n}],{j,1,n}]]
(*thenumberoffreeindexreferstorowindexintheoutputmatrix*)
In[]:=
CChrstf//MatrixForm
Out[]//MatrixForm=
0 |
2 r |
Cot[θ] |
0 |
check contracted Christoffel symbol by (24)
check contracted Christoffel symbol by (24)
In[]:=
CheckCChrstf:=CheckCChrstf=Simplify[Table[(1/2)*Sum[inversemetric[[i,s]]*(D[metric[[s,i]],coordnt[[j]]]),{i,1,n},{s,1,n}],{j,1,n}]]
(*thenumberoffreeindexreferstorowindexintheoutputmatrix*)
In[]:=
CheckCChrstf//MatrixForm
Out[]//MatrixForm=
0 |
2 r |
Cot[θ] |
0 |
Easy to see CheckCChrstf is equal to CChrstf
Easy to see CheckCChrstf is equal to CChrstf
xAct is Better ?at least for abstract symbolic calculation it is
In[]:=
<<xAct`xTensor`