help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sparse matrix operations


From: Mike Miller
Subject: Re: sparse matrix operations
Date: Tue, 16 Nov 2004 13:23:08 -0600 (CST)

On Tue, 16 Nov 2004, E. Joshua Rigler wrote:

It would be useful to have operations for sparse matrices (multiply, add, etc.) that only bothered to do calculations to update those non-zero elements of a sparse matrix on the left-hand side of an equation.

For example, suppose I only want the diagonal of the product of two square matrices. As it stands right now in Octave (with octave-forge), C=A*B will result in a full C matrix, and may potentially use up more memory than I wish to allow. Since I only want the diagonal of C, I may as well only perform those operations that place a vector product at C(i,i), thereby saving CPU cycles and memory.

I have a simple .m file that does this, but of course it is very slow in the Octave interpreter since it must loop over each of the desired non-zero elements of C. I was hoping somebody out there might have something similar, but in a .oct format, or could show me a trick for doing this with standard Octave operators, before I go and try to reinvent this wheel.


For diagonal matrices, why not just do this:

C=diag(A).*diag(B);

Then C will be a column vector. To get the full matrix C (=A*B), just do this:

C=diag(diag(A).*diag(B));

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]