Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose I have a matrix $$\begin{pmatrix} & 3 & 6\\ 5 & & 5\\ 4 & 7 & \end{pmatrix}$$

How can I find the three numbers on the main diagonal such that the sum of the numbers on every row and every column is equal (i.e. it's a magic square). Thank you.

share|cite|improve this question
There are many "matrix problems". Could you change the title to something more useful, such as "how to make a matrix a magic square" – akkkk Dec 22 '12 at 16:45
@palatok This is no magic square. Number 5 is not distinct... Magic square by definition is an arrangement of distinct numbers (i.e., each number is used once), usually integers, in a square grid, where the numbers in each row, and in each column, and the numbers in the main and secondary diagonals, all add up to the same number. – BugshotGG May 4 at 8:42
up vote 8 down vote accepted

Let's say we put in the numbers $a$, $b$, and $c$: $$\begin{pmatrix} a & 3 & 6\\ 5 & b & 5\\ 4 & 7 & c \end{pmatrix}$$ The sums of the rows are $a+9$, $b+10$, and $c+11$. The sums of the columns are the same (indeed, if that were not the case, it'd be impossible to make it into a magic square). Thus, we want the numbers $a$, $b$, and $c$ to satisfy $$a+9=b+10=c+11.$$ Such triples of numbers are precisely those of the form $a=x$, $b=x-1$, and $c=x-2$ for some number $x$. But we also want the diagonals to add up to the same value; thus, we want $$a+b+c=4+b+6$$ $$x+(x-1)+(x-2)=4+(x-1)+6$$ $$3x-3=x+9$$ $$x=6$$ Thus, the unique entries we can put in to make the matrix a magic square are $$\begin{pmatrix} \fbox{6} & 3 & 6\\ 5 & \fbox{5} & 5\\ 4 & 7 & \fbox{4} \end{pmatrix}$$

share|cite|improve this answer
He had the diagonals as one of the conditions, so you can see for $x$ and then have to check the last diagonal – Thomas Andrews Dec 22 '12 at 16:52
Well, the question only said "such that the sum of the numbers on every row and every column is equal", but now checking on Wikipedia I see that "magic square" also requires the diagonals to sum to the same value (which I was unaware of). I'll add to my answer. – Zev Chonoles Dec 22 '12 at 16:53
how to find the x? – palatok Dec 22 '12 at 16:55
sorry i forgot to tell about the diagonals. – palatok Dec 22 '12 at 16:56
@palatok: I've updated my answer. – Zev Chonoles Dec 22 '12 at 17:01

Your Answer


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.