# How to Find a Weighing Matrix of Size n?

Weighting matrices appear in the statistical design of experiments (Weighting Matrices and Statistical Design of Experiments.

A weighting matrix is a generalization of Hadamard matrices, e.g.,

HadamardMatrix[8]



but can have zeroes as entries in addition to -1 and +1--and they exist for square matrices that are not 4*(positive integer).

Beyond a random search which is trivial and not a great method, does anyone know how to compute a Weighing matrix of size (general positive integer)?

• n.b., this won't scale: With[{size = 4}, Select[Tuples[Tuples[{-1, 0, 1}, size], size], Block[{diagQ = Transpose[#] . #, diagonals}, diagonals = Diagonal[diagQ]; DiagonalMatrixQ[diagQ] && AllTrue[diagonals, # == First[diagonals] &] ] &] ] Feb 16 at 16:03

Here is a straightforward approach for small (less than $$4$$) n and w:
ClearAll[a, A]; A = Table[a[i, j], {i, 4}, {j, 4}];

{{a[1, 1] -> -1, a[1, 2] -> -1, a[1, 3] -> 0, a[1, 4] -> 0, a[2, 1] -> -1, a[2, 2] -> 1, a[2, 3] -> 0, a[2, 4] -> 0, a[3, 1] -> 0, a[3, 2] -> 0, a[3, 3] -> -1, a[3, 4] -> 1, a[4, 1] -> 0, a[4, 2] -> 0, a[4, 3] -> -1, a[4, 4] -> -1}}
For many n and k a weighting matrix does not exist and the above code derives it. For example, FindInstance[ A . Transpose[A] == 5*IdentityMatrix[4] && Flatten[A] >= -1 && Flatten[A] <= 1, Flatten[A], Integers] results in {}.