Special Arrays in MATLAB
A Magic Square
A magic square is a square that produces the same sum, when its elements are added row-wise, column-wise or diagonally.
The magic() function creates a magic square array.
It takes a singular argument that gives the size of the square. The argument must be a scalar greater than or equal to 3.
magic(4)
MATLAB will execute the above statement and return the following result:
ans =
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
No comments:
Post a Comment