magic: MATLAB magic function

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/magic.R

Description

Create a magic square.

Usage

1
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)

P. Roebuck [email protected]

See Also

ones, zeros

Examples

1
magic(3)

Example output

Attaching package: 'matlab'

The following object is masked from 'package:stats':

    reshape

The following objects are masked from 'package:utils':

    find, fix

The following object is masked from 'package:base':

    sum

     [,1] [,2] [,3]
[1,]    8    1    6
[2,]    3    5    7
[3,]    4    9    2

matlab documentation built on May 30, 2017, 6:57 a.m.