When working with large sparse linear systems you often want to look at their non-zero structure, however Maple's existing tools are all designed for dense matrices. I wrote a little tool to produce images like this in reasonable time. You can download the code here, and the rest of this post is a quick tutorial on how to use the included command. Maple 11 is required.

First, read in the code using the read command as shown below. You will need a matrix to plot. Assuming you have assigned the matrix to the variable "A", the following commands will show you an image of its structure.

> read "matimg.mpl":
> img := MatrixImage(A);
> ImageTools:-View(img);

By default it creates an image with maximum dimension 500, scaling the matrix accordingly. It will not create an image larger than the matrix, and the image is always scaled 1:1. If you would like a higher resolution image, specify its maximum dimension as a second argument. You should use ImageTools:-View to view the images and ImageTools:-Write to write them to graphics files. For example, we make an image with max(height,width) < 2000 and save it to a JPEG file, enter the following commands.

> img := MatrixImage(A,2000);
> ImageTools:-Write("imageA.jpg", img);

All you TTY junkies out there rejoice! ImageTools:-View can be used from Maple's command line interface. Advanced users should note that gamma correction is applied to emphasize the structure of matrices that are downsampled. You can turn that off with the optional argument gamma=false. You can use the ImageTools:-Gamma command to apply your own level of gamma correction. Finally, you can invert the color scheme and make zero black with the optional argument invert=true. As for matrices, you can get some from the University of Florida Sparse Matrix Collection. The code above includes an updated version of the MatrixMarket import command, so you should download matrices in that format. For example, the image above is dwt_2680. Given a minute or two, you can produce publication quality plots of very large matrices. I hope someone will find this code useful.


Please Wait...