Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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):

enter image description here

Tips, anybody?

share|improve this question
2  
Array[{{-2, -1}, {-2, -1}} + {#1 - 1, #2 - 1} &, {4, 4}] –  andre Jun 15 at 17:20

3 Answers 3

up vote 3 down vote accepted

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

enter image description here

share|improve this answer
    
Thanks, your second solution is exactly what I needed. Would you accept my acceptance? –  eldo Jun 15 at 18:18
    
@eldo Thank :) I will glady accept it :P –  Kuba Jun 15 at 18:55
n = 2;
Table[{{-n, -n + 1} + i, {-n, -n + 1} + j}, {i, 0, 2 n - 1}, {j, 0, 
  2 n - 1}]
share|improve this answer
    
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 at 18:30
    
@eldo I have changed it. I think it is working now fro any n. –  Algohi Jun 15 at 18:40
    
yes, now it works :) –  eldo Jun 15 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

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.