Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Summation and its condition
Date: Tue, 17 Feb 2009 16:48:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <gnepo2$18e$1@fred.mathworks.com>
References: <gnbahb$4id$1@fred.mathworks.com> <gnchai$msh$1@fred.mathworks.com> <gnci4q$gsn$1@fred.mathworks.com> <gncjaa$50v$1@fred.mathworks.com> <gndod9$stt$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1234889282 1294 172.30.248.37 (17 Feb 2009 16:48:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Feb 2009 16:48:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:518892

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <gndod9$stt$1@fred.mathworks.com>...
> % Vectorize the inner loop :
> % It takes about 10s to compute the sum for N=10000!
> 
> clear
> 
> N=10000;
> 
> A=rand(N,1);
> B=rand(N,1);
> 
> tic
> s=0;
> for jpk=4:2*N-3
>     j=floor((jpk-3)/2):-1:max(jpk-N,1);
>     k=jpk-j;
>     AmnBmn = A(j+1).*A(k-1) - B(j+1).*B(k-1);
>     AjkBjk = A(j).*A(k) - B(j).*B(k);
>     s = s + sum(AjkBjk.*cumsum(AmnBmn));
> end
> toc
> fprintf('sum that can operate on big array=%g\n', s);
> 
> % Bruno

  Well done Bruno!  Both you and John have done well by Akihiro's problem.  This morning when I awoke I had an idea of how the computation could be speeded up, only to find that you had already thought of it and more.

Roger Stafford