[email protected] writes:
>
> Reading a Matlab tutorial the very first
> example shows the magic(n) function
> that can generate a magic square (
> http://en.wikipedia.org/wiki/Magic_square )
> of any size. Is there such a function in PDL?
>
> On CPAN I found two modules:
>
> http://search.cpan.org/dist/Math-MagicSquare-Generator
> http://search.cpan.org/dist/Math-MagicSquare

I just installed Math::MagicSquare::Generator.  The output
is an array ref structure and the pdl constructor can
take that as input so:

 perldl> use Math::MagicSquare::Generator

 perldl> $ms = Math::MagicSquare::Generator->new(size=>5)

 perldl> p $ms
 Math::MagicSquare::Generator=ARRAY(0x1fe5cb8)
 perldl> p @$ms
 ARRAY(0x23ec4e8) ARRAY(0x1fe5a78) ARRAY(0x1fe5b20) ARRAY(0x1fe5bc8) 
ARRAY(0x23e9e18)
 perldl> $mpdl = pdl(@$ms)

 perldl> p $mpdl

 [
  [ 3 16  9 22 15]
  [20  8 21 14  2]
  [ 7 25 13  1 19]
  [24 12  5 18  6] 
  [11  4 17 10 23]
 ]    
 
Cheers,
Chris
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to