# Create symmetric array of function values

I have function B[i,j] where i,j are integers. Then I create array:

b = Array[B, {3,3}]


now I set values of B[i,j] for some i,j:

B[1, 1] = -2.98675
B[1, 2] =  -4.99337
B[1, 3] = -2.13606
B[2, 2] = -1.0732
B[2, 3] = -2.63553
B[3, 3] = -1.446


now in array b values B[3,2], B[3,1] and B[2,1] have no value, but I would like to have array b symmetric (B[2,1]==B[1,2]). I cannot find the easy way how to tell Mathematica to make array b symmetric. This problem is easy to solve manualy, but for function C[i,j,k] in array c = Array[C,{3,3,3}], symmetric array would be appreatiated. I want to sum over these arrays.

You can yse simple construct with Do:

Do[B[i, j] = B[j, i], {i, 3}, {j, 3}]


In case of Array[S,{3,3,3}] this probably should be changed to:

Do[S[i, j, k] = S[j, i, k], {i, 3}, {j, 3}, {k, 3}]

• It is quite tricky with the iterators i,j. But Do[B[i, j] = B[j, i], {j, 3}, {i, 3}] worked for me. Commented Oct 16, 2019 at 15:23
• I checked with Array[B,{3,3}] // MatrixForm both variants of iterators and there is no difference. Anyway, thank you for accepting.
– Alx
Commented Oct 16, 2019 at 15:27
• And for Array[S,{3,3,3}] only Do[Cv[i, j, k] = Cv[j, i, k] = Cv[k, i, j], {k, 3}, {j, 3}, {i, 3}] works for me. Commented Oct 21, 2019 at 13:13

You can use SymmetrizedArray:

Normal @ SymmetrizedArray[
{
{1,1}->-2.98675,
{1,2}->-4.99337,
{1,3}->-2.13606,
{2,2}->-1.0732,
{2,3}->-2.63553,
{3,3}->-1.446
},
{3,3},
Symmetric[{1,2}]
]


{{-2.98675, -4.99337, -2.13606}, {-4.99337, -1.0732, -2.63553}, {-2.13606, -2.63553, -1.446}}