# Covariant derivative of a vector [duplicate]

I have a code that gives me the Christoffel symbols of a metric. How do I take the covariant derivative of a vector?

It does not necessarily have to build upon my code, but this is what I have used so far that gives me the affine connactions:

n = 4
coord = {T, R, \[Theta], \[Phi]}

metric = {{-1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, R^2, 0}, {0, 0, 0, R^2 Sin[\[Theta]]^2}}

inversemetric = Simplify[Inverse[metric]]

affine := affine = Simplify[Table[(1/2)*Sum[(inversemetric[[i, s]])*
(D[metric[[s, j]], coord[[k]] ] +
D[metric[[s, k]], coord[[j]] ] -
D[metric[[j, k]], coord[[s]] ]), {s, 1, n}],
{i, 1, n}, {j, 1, n}, {k, 1, n}] ]

listaffine :=
Table[If[UnsameQ[affine[[i, j, k]],
0], {ToString[\[CapitalGamma][i, j, k]], affine[[i, j, k]]}] , {i,
1, n}, {j, 1, n}, {k, 1, j}]

TableForm[Partition[DeleteCases[Flatten[listaffine], Null], 2],
TableSpacing -> {2, 2}]

`
• If you're going to be doing a lot of this sort of thing, you might want to look into the xAct package, and in particular the xCoba sub-package included with it. Jul 12, 2021 at 17:12
• As a corollary to that, to the best of my knowledge this is not something that Mathematica can do "natively". You would have to either write your own code or use an add-on package, such as xAct. Jul 12, 2021 at 17:15
• Jul 14, 2021 at 0:26