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 09:16:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 43
Message-ID: <gndv8j$k9j$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-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1234862163 20787 172.30.248.35 (17 Feb 2009 09:16:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 17 Feb 2009 09:16:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1715507
Xref: news.mathworks.com comp.soft-sys.matlab:518772

"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

Dear All,

Thank you for your help and efforts to improve them! I'm glad to be able to see various examples you posted. Your examples seem to derive correct answers as far as I have checked by myself.
I had not thought the summation could be computed with such a short computation time... super!
And now, I need to solve the other 4 conditions,
1. j=k+2n, k~=n
2. j+k=2n, j<k
3. j=3k
4. j+k+n=m, j<k<n

I'll try to solve them referring to your help but also, of course, any advice is always welcome!

Thank you very much!

Akihiro