How can we calculate double summation quickly in MATLAB

Status
Not open for further replies.

Riofunk7

Newbie level 4
Joined
Oct 6, 2009
Messages
6
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,326
Hello, Guys

I am looking for a fast double summation method for the following calculation.

X=[0:N-1]; Y=[0:N-1];
Z=ExEy[exp(-(X-Y)^2)];

Thus, in MATLAB,

X=[0:N-1]; Y=[0:N-1];
for n=1:N
Zy = sum(exp(-(X-Y))^2)) / N;
end
Z = sum(Zy) / N;

As shown above, firstly I tried "for loop" and "sum()" function in matlab. But for large number of sequence this method is too slow if the sample size N is large.

Are there anyone who know faster calculation for this problem?


Thank you in advance.
Rio.
 

Hi Rio,

Please try this:

X=[0:N-1]; Y=[0:N-1];
Xr = repmat(X,N,1);
Yr = repmat(Y),1,N);
Dr = (Xr-Yr);
Z = sum(sum(exp(-Dr.*Dr)))/(N*N);

Regards

Z
 
Thanks, Z.

I could reduce the simulation time to half.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…