Not all problems have a solution. But sometimes, they do, IF you are willing to relax some conditions. A classical magic square of order n is a permutation of the numbers 1:n^2, such that the sum of all rows and all columns, as well as the two diagonal sums, will all yield the same value. Clearly, at least something must be relaxed here for a result to exist.
Your question is to solve for the unknown variables a,b,c,d,e,f, such that the matrix
A = [1 a b ; c 2 d ; e f 3];
is a magic square. Does such a matrix exist for integer variables a,b,c,d,e,f? What if you allowed the variables to be negative? Walter claims out that no such matrix exists unless the variables can be negative. But does ANY matrix exist at all?
The sum of your main diagonal elements is 6. So we would need it to be true that:
sum(A,1) = [6 6 6]
sum(A,2) = [6;6;6]
AND don't forget the anti-diagonal sum.
b + 2 + e = 6
As such, you should notice that we are left with 7 linear equations, in 6 unknowns. That is usually a bad thing, suggesting the problem might indeed be unsolvable in general. At best, if a solution does exist, a purely integer solution might be unlikely. At least, we can try...
syms a b c d e f
A = [1 a b ; c 2 d ; e f 3]
[ 1, a, b]
[ c, 2, d]
[ e, f, 3]
Time to turn this problem into a linear algebra problem.
We want to solve for the vector X = [a;b;c;d;e;f], such that M*X==rhs.
Linear algebra teaches us that a solution to such a problem exists if the right hand side vector is representable as a linear combination of the column space of the matrix M. First, what is the rank of M?
As long as these two rank computations return the same number, then a solution does exist. However, since the rank of M is only 5, then infinitely many solutions will exist. Even so, we might get lucky.
X = pinv(M)*rhs
Plug it back into the matrix A.
Asol = subs(A,[a,b,c,d,e,f],X.')
[ 1, 3, 2]
[ 3, 2, 1]
[ 2, 1, 3]
I think you will agree that this matrix is indeed a magic square, in the sense that it is entirely integer, that each row and each column, as well as the anti-diagonals all sum to 6.
Indeed, this is a magic square, subject to only one flaw - that the elements are not all distinct integers from the set 1:n^2. Is it possible to find a variation that allows all elements at least distinct integers? Even better, is it possible to find a solution that has all elements distinct and positive integers? The set of all solutions to the linear system posed can be written as
X = pinv(M)*rhs;
Xt = X + t*null(M)
3 - t
t + 2
t + 3
1 - t
2 - t
t + 1
You can easily convince yourself that as long as t is any integer, then this will yield a solution, but that as well, for ANY non-zero value of t, at least some of those elements will either be the same, or some of them will be negative. So the fully general solution is given by At. Thus any integer value for t will result in a new magic sqaure with the given diagonal.
At = subs(A,[a,b,c,d,e,f],(X + t*null(M)).')
[ 1, 3 - t, t + 2]
[ t + 3, 2, 1 - t]
[ 2 - t, t + 1, 3]
The two simplest magic squares with distinct elements, and a diagonal of [1 2 3] are:
[ 1, 0, 5]
[ 6, 2, -2]
[ -1, 4, 3]
[ 1, 6, -1]
[ 0, 2, 4]
[ 5, -2, 3]
As one might expect, the two are actually the same matrices, just transposed. And, yes, there are negative numbers in the matrix.
So a solution does exist in positive numbers, IF you are willing to accept that the elements need not be distinct. If that is a problem, then negative numbers will be forced upon you. A nice thing is the methodology shown in this answer is extensible to matrices of a higher order, at least in theory.