In reply to Ian Wakeling.

Amazing. You'll have to explain why multiplying the matrix by itself 5 times (why 5?) mod 17 results in another magic square. Very cool.

Speaking of rotating matrices, check out this blog post: http://blogs.sas.com/content/iml/2013/10/18/rotating-matrices/

In SAS/IML 13.1 you can create heat maps to visualize matrices with the HEATMAPCONT and HEATMAPDISC subroutines. I need to think about how to animate the results.