From: "John D'Errico" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: overdetermenied system
Date: Tue, 13 Jan 2009 15:03:01 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 40
Message-ID: <gkiaf5$300$>
References: <gkhurv$nv1$> <gki4hq$1b9$> <gki6bu$6j$> <gki89q$85e$>
Reply-To: "John D'Errico" <>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1231858981 3072 (13 Jan 2009 15:03:01 GMT)
NNTP-Posting-Date: Tue, 13 Jan 2009 15:03:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: comp.soft-sys.matlab:511194

"Roger Stafford" <> wrote in message <gki89q$85e$>...
> "John D'Errico" <> wrote in message <gki6bu$6j$>...
> > Actually, if you build it as a sparse block diagonal
> > matrix, I think that backslash might survive the
> > ordeal. At the very least, you could do it in chunks,
> > with perhaps 512 blocks in each chunk. The matrix
> > problem MUST be done as a sparse one however.
> > 
> > John
>   Yes, I expect you are right, John.  It could be done that way.  I shouldn't make such generalized assertions.
>   I'm not so sure about its efficiency, though, as opposed to 512*384 individual 4x2 backslashes.  The single block diagonal backslash would have to be smart enough not to waste significant overhead time on all the implied zero "off-diagonals".  The solution to a single 4x2 problem should be very fast, especially if one writes it out as an explicit vectorized expression in terms of the four basic arithmetic operations without using matlab's backslash operator itself.
> Roger Stafford

If your matrix is sparse, then \ really is pretty smart.

blocks = rand(4,2,1000);
A = blktridiag(blocks,zeros(4,2,999),zeros(4,2,999));
rhs = rand(4000,1);

coef = zeros(2,1000);
for i = 1:1000
coef(:,i) = blocks(:,:,i)\rhs((1:4) + 4*(i-1));
Elapsed time is 0.105407 seconds.

tic,coef = A\rhs;toc
Elapsed time is 0.044134 seconds.

I will admit that the simple loop is pretty fast though,
especially if I add in the time to create the sparse
block diagonal matrix. blktridiag is not as efficient
as it should be here, since it fills in explicit zeros
into the upper and lower blocks.