There are some matrices such that the sum of columns, the sum of rows, and the sum of diagonals are the same value. Here is an example:
8 1 6
3 5 7
4 9 2
The sum of rows is 15, and so is sum of columns and the sum of diagonals.
In MATLAB, refer to Cleve Moler's book "Experiments with MATLAB". I can generate this kind of matrix using the magic
function, with an argument specifying the size of the matrix:
4-by-4:
>> magic(4)
ans =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
5-by-5:
>> magic(5)
ans =
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Is there a similar function in Mathematica? Or, maybe there's some way to build this kind of matrix?