How to make a matrix of multivariable functions?

It might be a very basic question! Let say that I have an array of variables as the following

x = {{x11, x12, x13, x14}, {x21, x22, x23, x24}, {x31, x32, x33, x34}, {x41, x42, x43, x44}, {x51, x52, x53, x54}}.

I want to define a 5 by 5 symmetric matrix G so that each of its elements is an arbitrary function of all of the variables above, e.g.

G[1,3]=G13[x11,x12,x13,x14,x21,x22,x23,x24,x31,x32,x33,x34,x41,x42,x43,x44,x51,x52,x53,x54], and so on. What is the simplest way to do this?

x = {{x11, x12, x13, x14}, {x21, x22, x23, x24}, {x31, x32, x33,
x34}, {x41, x42, x43, x44}, {x51, x52, x53, x54}};
n = 2;
m = SparseArray[{i_, j_} /; j > i ->
Subscript[g, FromDigits[{i, j}]][Sequence @@ Flatten@x], {n, n}];
diagnal =
SparseArray[{i_, i_} ->
Subscript[g, FromDigits[{i, i}]][Sequence @@ Flatten@x], {n, n}];
m + Transpose[m] + diagnal
% // Normal // MatrixForm

• Thank you so much. Commented Nov 5, 2020 at 12:38

This would be one option

ClearAll["g*"];
g[M_List /; Length[Dimensions[M]] === 2]:=Array[{x,y}\[Function](Symbol[StringJoin[Flatten@{"g",ToString/@Sort[{x,y}]}]][##]&@@Flatten[M]),Dimensions[M]]


which for

x = {{x11, x12}, {x21, x22}};
g[x] // MatrixForm


results in

{
{g11[x11,x12,x21,x22,x31,x32,x41,x42],g12[x11,x12,x21,x22,x31,x32,x41,x42]},
{g12[x11,x12,x21,x22,x31,x32,x41,x42],g22[x11,x12,x21,x22,x31,x32,x41,x42]}
}


where I have considered a $$2\times2$$ matrix for a more compact output.

• Thank you so much, it works perfectly for a 2×2 matrix. To get a 5×5 one, I changed 2-->5 in the matrix dimensions, but it didn't work. What else should I change? Commented Nov 4, 2020 at 20:40
• g[Array[Subscript[a, Row[{#1, #2}]] &, {5, 5}]] works for me as expected...
– N0va
Commented Nov 4, 2020 at 21:29