Saturday, 14 September 2013

For no reason whatsoever: animated gifs of random matrices

Here are some animated gifs of random matrices done in Sage:




Here's a smaller 10 by 10 matrix (the above are 500 by 500) which probably needs to come with a health warning:



The code to do this using Sage is pretty easy (it makes use of the plot method on matrices):


import os

size = 500
nbrofmatrices = 100

for i in range(nbrofmatrices):
    print "Ploting matrix: %i of %s" % (i + 1, nbrofmatrices)
    A = random_matrix(RR,size)
    p = A.plot(cmap='hsv')
    p.save('./plots/%.3d.png' % i)

print "Converting plots to gif"
os.system("convert -loop 0 ./plots/*png %sanimatedmatricesofsize%s.gif" % (nbrofmatrices, size))

Each of the three above gifs were made using different colour maps: (ie changing the cmap option).

This creates 100 random 500 by 500 matrices and uses imagemagik (that's a link to a blog post I wrote about creating these) to create an animated gif.


No comments:

Post a Comment