Volume 9, Issue 2
Tricks of the Trade
In and Out
Download This Issue
In and Out
Q: One can use LinearSolve to solve a system of linear equations. However, I work with very large matrices having only five nonzero diagonals. Are there efficient methods for dealing with such matrices?
A: Daniel Lichtblau (firstname.lastname@example.org) answers: If you require only machine arithmetic, this can be done effectively using the built-in sparse linear solver in Version 5. Here is an example.
Create a diagonally-dominant random sparse -diagonal matrix using SparseArray.
With and , we obtain a sparse array with nonzero elements.
Use Normal to obtain the ordinary array corresponding to a sparse array object.
Produce a pentadiagonal sparse matrix of dimension 2000.
Solve for a random right-hand side.
Compare with the time required for an ordinary (nonsparse) matrix.
Check that the solutions agree using (for matrices, gives the maximum singular value of ).
About Mathematica | Download Mathematica Player
Copyright © 2004 Wolfram Media, Inc. All rights reserved.