Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Bogey
Date: Sat, 25 Oct 2008 18:30:06 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 32
Message-ID: <gdvoje$gnn$1@fred.mathworks.com>
References: <gdvjlp$kij$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1224959406 17143 172.30.248.38 (25 Oct 2008 18:30:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 25 Oct 2008 18:30:06 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:497224

"b b" <bogey4@gmail.com> wrote in message <gdvjlp$kij$1@fred.mathworks.com>...
> Hi, 
> 
> I'm trying to avoid using loops when multiplying matrices together iteratively and was wondering if anyone has a trick to do this quickly and without loops.  My algebra skills are somewhat lacking, so hopefully this is straightforward!
> 
> X = [1 2; 5 4];
> Y = [1 2 1 ;2 4 1];
> ksi = [1 2 ;2 3];
> 
> Here's the equation that I'm attempting to solve:
>     \sum_{n=1}^N\sum_{i=1}^M \xi_{ni}X_nY_i
> where a Xn would be a column (e.g. [1;5]) and a Yi would be a row (e.g. [1 2 1]).  We should end up with a 2x3 matrix.
> 
> Here's the code I'm currently using:
> 
> tot = zeros(2,3);
> for n = 1:2,
>   for i = 1:2,
>     tot = tot+ X(:,n)*Y(i,:);
>   end;
> end;
> 
> Does anyone have a suggestion how to do this without these loops? These matrices are quite big in the actual program, and this section takes a long time to run.
> 
> Thanks!
> 
> Bruce
------
 tot = sum(X,2)*sum(Y,1);

Roger Stafford