Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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(n)-Y(n))^2)];

Thus, in MATLAB,

X=[0:N-1]; Y=[0:N-1];
for n=1:N
Zy(n) = sum(exp(-(X(n)-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.
 

zorro

Advanced Member level 4
Joined
Sep 6, 2001
Messages
1,131
Helped
357
Reputation
712
Reaction score
298
Trophy points
1,363
Location
Argentina
Activity points
8,907
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
 

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
Thanks, Z.

I could reduce the simulation time to half.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top