```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Alternative to matrix inverse?
Date: Wed, 22 Feb 2012 03:09:11 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 21
Message-ID: <ji1m8n\$di6\$1@newscl01ah.mathworks.com>
References: <jhvcv1\$j70\$1@newscl01ah.mathworks.com> <ji0bpa\$m1k\$1@newscl01ah.mathworks.com> <ji0ehf\$28d\$1@newscl01ah.mathworks.com> <ji19ng\$7jm\$1@newscl01ah.mathworks.com> <ji1c6a\$eng\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1329880151 13894 172.30.248.38 (22 Feb 2012 03:09:11 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 22 Feb 2012 03:09:11 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:758450

"Jean-Philippe" wrote in message <ji1c6a\$eng\$1@newscl01ah.mathworks.com>...
> Thank you for your suggestion on how to multiply repeatedly P as a 9 bands matrix. But, I am not sure how I can do this exactly.
- - - - - - - - - -
You can multiply M by the k-th level diagonal of P above its main diagonal this way:

M2 = [zeros(N,k),bsxfun(@times,M(:,1:N-k),diag(P,k).')];

or for diagonals below the main diagonal, indicated by negative k, this way:

M2 = [bsxfun(@times,M(:,1-k:N),diag(P,k).'),zeros(N,-k)];

(You could use this single line for either kind of k:

M2 = [zeros(N,k),bsxfun(@times,M(:,max(1,1-k):min(N-k,N)),...
diag(P,k).'),zeros(N,-k)];

but it would probably be a little slower in action.)  It would then be necessary to add all nine of these for the nine values of k for various diagonals in P.  The net effect of this would be the equivalent of the ordinary matrix multiplication M*P but with far fewer operations.

Note: It would probably be best to precompute the quantities diag(P,k).' and zeros(N,k) or zeros(N,-k) so that they would not have to be repeatedly computed for each iteration step.

Roger Stafford
```