# Replacing For loop with multiple iterator with Table

I have written code for calculating cristofell symbol using for loop with 3 iterators for each coordinate

A = {
{1, 0, 0},
{0, r^2, 0},
{0, 0, 1}
} ;
Kor[n_] := \[Piecewise] {
{(r), n == 1},
{(\[Theta]), n == 2},
{(z), n == 3}
}
ChristoffelSymbol1[i_, j_, k_] :=
1/2 (-D[A[[i, j]], Korr[k]] + D[A[[j, k]], Korr[i]] +
D[A[[k, i]], Korr[j]])
For[i = 1, i < 4, i++,
For[j = 1, j < 4, j++,
For[k = 1, k < 4, k++,

Print[Subscript[\[CapitalGamma], i, j, k], " = ",
ChristoffelSymbol1[i, j, k]]

]
]
]


I was wandering if I could use Map/Table to do the same without changing the functions too much. As far as I could tell I need to make the Piecewise function return symbols for i, j, k when they are entered instead of number so I dont get an error when I do ChristoffelSymbol1[1,j,k] and (this I don't know how) somehow define what happens when I try to access the matrix A with A[[1,j]] for example , so it doesn't give me "expression j cannot be used as a part specification" and leave it in symbolic notation so it can be used when j iterators start.

• if you actually want to Print like that you would use Do. I dont see why you would have the part issue you are imagining -- try it. I wouldn't bother with that Piecewise by the way , just do Kor[1]=r;Kor[2]=theta;Kor[3]=z or do Kor={r,theta,z} and reference it as a list. Sep 28, 2017 at 18:22
• You can use for example Tuples and then Map function over the obtained list. However, it is unclear from your question what exactly you want to do? Sep 28, 2017 at 18:58
• I want a table of {Symbol,value} pairs outputted in 1 cell,but for the symbol to keep the formatting from print. Sep 28, 2017 at 19:26

\[CapitalGamma]ddd[i_, j_, k_] :=
1/2 (-D[A[[i, j]], Kor[[k]]] + D[A[[j, k]], Kor[[i]]] +
D[A[[k, i]], Kor[[j]]])

A = DiagonalMatrix[{1, r^2, 1}]
Kor = {r, \[Theta], z}

Table[{Subscript[\[CapitalGamma], i, j, k], \[CapitalGamma]ddd[i, j,
k]}, {i, 1, 3}, {j, 1, 3}, {k, 1, 3}] // TableForm


Got it

 A = {
{1, 0, 0},
{0, r^2, 0},
{0, 0, 1}
} ;  B = {
{1, 0, 0},
{0, 1/r^2, 0},
{0, 0, 1}
};
Kor[n_] := \[Piecewise] {
{(r), n == 1},
{(\[Theta]), n == 2},
{(z), n == 3}
}
ChristoffelSymbol1[i_, j_, k_] :=
1/2 (-D[A[[i, j]], Kor[k]] + D[A[[j, k]], Kor[i]] +
D[A[[k, i]], Kor[j]])
ChristoffelSymbol2[i_, j_, m_] :=
Sum[B[[k, m]] ChristoffelSymbol1[i, j, k], {k, 1, 3}]
TableForm[
Table[{Subscript[\[CapitalGamma], i, j, k],
ChristoffelSymbol1[i, j, k]}, {i, 1, 3}, {j, 1, 3}, {k, 1, 3}]]
TableForm[
Table[{Subscript[Superscript[\[CapitalGamma], m], i, j],
ChristoffelSymbol2[i, j, m]}, {i, 1, 3}, {j, 1, 3}, {m, 1, 3}]]


When i tried to replace For with Table i just copied the iterators,they were going from 1-4 in the loop and the marix is 3x3 so it bugged out :p