# Algorithm to generate a certain matrix

I am looking for a convenient way to generate a matrix of the following symmetric form (numbers could also run from -3 to +3 or just from -1 to +1): Tips, anybody?

• Array[{{-2, -1}, {-2, -1}} + {#1 - 1, #2 - 1} &, {4, 4}] – andre314 Jun 15 '14 at 17:20

One way:

n = 2;
Table[{{i, i + 1}, {j, j + 1}}, {i, -n, n - 1}, {j, -n, n - 1}]


or another

n = 5
Partition[Tuples[Partition[Range[-n, n], 2, 1], 2], 2 n] // MatrixForm • Thanks, your second solution is exactly what I needed. Would you accept my acceptance? – eldo Jun 15 '14 at 18:18
• @eldo Thank :) I will glady accept it :P – Kuba Jun 15 '14 at 18:55
n = 2;
Table[{{-n, -n + 1} + i, {-n, -n + 1} + j}, {i, 0, 2 n - 1}, {j, 0,
2 n - 1}]

• thanks, very nice, but it doesn't hold (in my case) for n>2. Try it with n=5 and compare with Kuba's answer. – eldo Jun 15 '14 at 18:30
• @eldo I have changed it. I think it is working now fro any n. – Algohi Jun 15 '14 at 18:40
• yes, now it works :) – eldo Jun 15 '14 at 19:02
Table[{{-2, -1}, {-2, -1}} +
i*{{1, 1}, {0, 0}} +
j*{{0, 0}, {1, 1}},
{i, 0, 3}, {j, 0, 3}] //
MatrixForm 