# Integrate over matrix elements

I wish to perform the integral $$\int \prod_{i,j}dM_{ij}\exp\left(-Tr(M^2)\right)$$ where we integrate over the matrix elements of $$M$$. I tried

Integrate[Exp[-Tr[matrix^2]],Product[Part[matrix,i,j],{matrix}]];


I know this is wrong and I get "The expression i cannot be used as a part specification.", but how should I write this instead?

• Do you mean the component-wise square of the matrix or the matrix product of M with itself? – Henrik Schumacher Nov 1 '18 at 18:09
• @HenrikSchumacher The matrix product. But what I try to understand is not the integrand, but how to express the $dM_{ij}$ with Mathematica – Marianne Moore Nov 1 '18 at 18:21

I'm assuming $$\prod_{i,j} dM_{i,j} = dM_{1,1} dM_{1,2}\ldots$$ so as to successively integrate over each element in your matrix.

Then

mat = {{a, b}, {c, d}}
Integrate[Exp[-Tr[MatrixPower[mat, 2]]], ##] & @@ Flatten@mat


-(1/8) π Erf[a] Erf[d] ExpIntegralEi[-2 b c]

• My matrix is a GUE (mat=RandomVariate[GaussianUnitaryMatrixDistribution[some rank]];) and it returns me the error 'Invalid integration variable or limit(s)' – Marianne Moore Nov 2 '18 at 0:01
• You could try starting with a symbolic matrix, then integrate, then replace the symbols with the appropriate numbers in the final output or implement integration bounds as in @Henrik's answer. Otherwise, since your matrix is made of numeric quantities, integrating with respect to a number doesn't really work. – That Gravity Guy Nov 2 '18 at 1:27

Just some shot into the dark because I am not sure whether I understood exactly want you want to compute:

n = 3;
M = Array[m, {n, n}];
With[{vars = Sequence @@ Transpose[{Flatten[M], ConstantArray[-∞, n^2], ConstantArray[∞, n^2]}]},
Integrate[Exp[-Tr[M\[Transpose].M]], vars]
]


π^(9/2)

Also notice that

With[{vars = Sequence @@ Transpose[{Flatten[M], ConstantArray[-∞, n^2], ConstantArray[∞, n^2]}]},
Integrate[Exp[-Tr[M.M]], vars]
]


will lead to an error message stating that integral won't converge.

• For arbitrary n, a wild guess would be (Pi)^(n^2/2) :-) – chris Nov 2 '18 at 0:09