OFFSET
1,2
COMMENTS
The MATLAB command is only supposed to be used when n >= 3. For n=2 it returns a non-magic square (none exist) with determinant -10.
[The MATLAB help page says: M = magic(n) returns an n-by-n matrix constructed from the integers 1 through n^2 with equal row and column sums. The order n must be a scalar greater than or equal to 3.]
From Robert Israel, Oct 27 2015: (Start)
For n >= 3, a(n) = 0 if and only if n is even.
a(n) is divisible by n^(n-2), because for odd n, magic(n) is the sum of an integer matrix of rank 2 and a matrix with entries divisible by n.
It appears that a(n) is divisible by n^(n-1). (End)
LINKS
Robert Israel, Table of n, a(n) for n = 1..210
MathWorks, MATLAB help file for magic.
EXAMPLE
n=3: magic(3) = [8 1 6 / 3 5 7 / 4 9 2 ], det(magic(3)) = 8*(5*2-7*9) - 1*(3*2-4*7) + 6*(3*9-4*5) = -360.
MAPLE
f:= proc(n)
if n::even then if n = 2 then return(-10) else return(0) fi fi;
LinearAlgebra:-Determinant(Matrix(n, n, (i, j) -> n*(i + (j - (n+3)/2) mod n) + (i + (2*j-2) mod n) + 1))
end proc:
seq(f(i), i=1..30); # Robert Israel, Oct 27 2015
MATHEMATICA
a[n_] := Which[n == 2, -10, EvenQ[n], 0, True, Det@Table[ n*Mod[i + (j - (n+3)/2), n] + Mod[i + (2j-2), n] + 1, {i, n}, {j, n}]];
Table[a[n], {n, 1, 20}] (* Jean-François Alcover, May 17 2023, after Robert Israel *)
PROG
(MATLAB) det(magic(n));
CROSSREFS
KEYWORD
sign
AUTHOR
Magnus Bjerkeng (bjerkeng(AT)stud.ntnu.no), May 17 2009
EXTENSIONS
Edited by N. J. A. Sloane, May 17 2009
Further edits by Robert Israel and N. J. A. Sloane, Oct 27 2015
STATUS
approved