powered by
Create a magic square.
magic(n)
Returns an n-by-n matrix constructed from the integers 1 through \(N^2\) with equal row and column sums.
n
1
numeric scalar specifying dimensions for the result
P. Roebuck proebuck1701@gmail.com
The value of the characteristic sum for a magic square of order n is \(sum(1:n^2)/n\). The order n must be a scalar greater than or equal to 3; otherwise, the result will be either a nonmagic square, or else the degenerate magic squares 1 and [].
ones, zeros
ones
zeros
magic(3)
Run the code above in your browser using DataLab