Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

magic

MATLAB magic function


Description

Create a magic square.

Usage

magic(n)

Arguments

n

numeric scalar specifying dimensions for the result

Details

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 [].

Value

Returns an n-by-n matrix constructed from the integers 1 through N^2 with equal row and column sums.

Note

A magic square, scaled by its magic sum, is doubly stochastic.

Author(s)

See Also

Examples

magic(3)

matlab

MATLAB emulation package

v1.0.2
Artistic-2.0
Authors
P. Roebuck
Initial release
2014-06-19

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.