WOLFRAM NOTEBOOK

Compute Christoffel symbols using Mathematica

copyright@沈正
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或其它包,但作为初学广义相对论或张量计算的一个练习还是挺好的

In[]:=
(*clear all assignment*)Clear[coordnt,metric,inversemetric,Chrstf]
In[]:=
n=4
Out[]=
4
In[]:=
(*define coordinates as coordntycoodnt*)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+
2M
r
,0,0,0,0,
1
1-
2M
r
,0,0,{0,0,
2
r
,0},{0,0,0,
2
r
2
Sin[θ]
}
In[]:=
inversemetric=Simplify[Inverse[metric]]
Out[]=
r
2M-r
,0,0,0,0,1-
2M
r
,0,0,0,0,
1
2
r
,0,0,0,0,
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=
0
-
M
2Mr-
2
r
0
0
-
M
2Mr-
2
r
0
0
0
0
0
0
0
0
0
0
0
M(-2M+r)
3
r
0
0
0
0
M
2Mr-
2
r
0
0
0
0
2M-r
0
0
0
0
(2M-r)
2
Sin[θ]
0
0
0
0
0
0
1
r
0
0
1
r
0
0
0
0
0
-Cos[θ]Sin[θ]
0
0
0
0
0
0
0
1
r
0
0
0
Cot[θ]
0
1
r
Cot[θ]
0
Contracted Christoffel Symbols

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)

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

xAct is Better at least for abstract symbolic calculation it is
In[]:=
<<xAct`xTensor`
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.