MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Magic Matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32516] Re: [mg32507] Magic Matrices
  • From: Mianlai Zhou <lailai at nikhef.nl>
  • Date: Fri, 25 Jan 2002 02:57:45 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi, for the odd integer order of magic matrices, I know the solution, and 
it can be expressed in Mathematica as the follows:

MagicOdd[n_Integer?OddQ] := 
    Module[{a = 1, i = 1, j = 2, r = Table[0, {n}, {n}]}, 
      Do[r = ReplacePart[r, a++, {i, j}]; {i, j} = 
          If[r[[Sequence @@ #]] == 0, #, Mod[{i + 1, j}, n, 1]] & @ 
            Mod[{i - 1, j + 1}, n, 1], {n^2}]; r];

Hope it helps.

Good luck!

Mianlai Zhou
Theory Group, NIKHEF
Amsterdam, the Netherlands

On Thu, 24 Jan 2002, Flip Flippy wrote:

> Hi All,
> 
> does anyone know of code for Mathematica to produce magic matrices?
> 
> For example Magic[n] would produce an nxn matrix where all of the 
> row, column and diagonal sums are equal.
> 
> As an example:
> 
> Magic[3] would produce as output:
> 
> {{8,1,6},{3,5,7},{4,9,2}}.
> 
> 
> Thank you for any inputs, Flip
> 
> 
> 



  • Prev by Date: RE: Change of Variables
  • Next by Date: Re: memoizing functions
  • Previous by thread: Re: Magic Matrices
  • Next by thread: Re: Magic Matrices