Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I was looking at the wikipedia page for the "Magic Square":

http://en.wikipedia.org/wiki/Magic_square

and it gave this equation to generate the numbers for a given square:

n((i+j-1+(n/2)) mod n) + ((i+2j-2) mod n)+1 , where i and j are rows and columns

But it doesn't seem to generate the correct numbers for me. For example for a n=3 (3x3) magic square the first element should be 8, but if I put i=1, j=1, n=3 into equation I get 9.5.

What's the deal?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

There should be $\lfloor\frac{n}{2}\rfloor=\lfloor\frac{3}{2}\rfloor=1$, not $\frac{n}{2}$

http://en.wikipedia.org/wiki/Floor_and_ceiling_functions

share|improve this answer
    
ahh I thought that was just angle brackets and didn't realize it was the floor function! –  eggie5 Feb 10 '12 at 23:58
add comment

Also, Matlab has the function magic(N) which will generate a magic square of any size N greater than 0 but not equal to 2.

From Matlab help:

MAGIC Magic square. MAGIC(N) is an N-by-N matrix constructed from the integers 1 through N^2 with equal row, column, and diagonal sums. Produces valid magic squares for all N > 0 except N = 2.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.