Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: taking the exponential of only the nonzero elements of a sparse matrix
Date: Thu, 15 Jan 2009 17:37:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <gkns7u$2b3$1@fred.mathworks.com>
References: <gkmlm5$f7s$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1232041022 2403 172.30.248.35 (15 Jan 2009 17:37:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 15 Jan 2009 17:37:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:511828

"Akim " <aaa@bbb.ccc> wrote in message <gkmlm5$f7s$1@fred.mathworks.com>...
> Dear All,
> 
> Matlab help tells me that "Multiplication and division are performed on only the nonzero elements of sparse matrices." What about something similar for the exponential?
> 
> Specifically, given a sparse matrix A, I wish to obtain a sparse matrix B, such that
> 
> B(i,j)=exp(A(i,j)), for all nonzero A(i,j)
> B(i,j)=0, for all zero A(i,j)
> 
> I'm only interested in the exponents of the nonzeros, and calculating the exponents of a vast number of zeros slows things down a little bit.
> 
> Thank you for your help.

  Akim, in doing what you ask there is the risk of misinterpreting your results in B.  In those cases where A contained a legitimate zero for which the answer ought to be one, you would have zeros instead.  In those cases where A was minus infinity (-inf) the answer would also be zero.  There is no easy way afterwards of distinguishing between the two possibilities in B.

  I would think you would want all the zeros in A replaced by ones, which could be done rather efficiently without using 'exp' - either that or produce a B of smaller size with all the zeros eliminated as Nor Ki has done.  Of course the cost of the former is the loss of being sparse.  The notion of a sparse exponential result seems to me inherently self-contradictory unless we extend the notion of sparsity to encompass constants other than zero.

Roger Stafford