Skip to content

magic

special-matrix · scripts/special-matrix/magic.m

: M = magic (n)

Return the n-by-n magic square: each of the integers 1 to n^2 occurs once and all row sums, column sums and the two main diagonal sums are equal.

The result has class single for single input, the input’s class for integer input and double otherwise.