MATLAB Answers

speeding up symmetric distance matrix computation

2 views (last 30 days)
gdgc on 7 Dec 2017
Edited: gdgc on 7 Dec 2017
Hi everyone,
I'm currently working on some discrete vortex algorithm, and the main time consuming part can be sumed up by these few lines :
% initilization
z=complex(rand(1,n),rand(1,n)); % vortices complex position
gam=rand(n,1); % circulation of vortices
% the part i'm trying to speed up
This involves the computation of a distance matrix, which is symmetric, so theoretically it should be possible to reduce the computation time of the z-z.' part.
I tried to use :
  • matlab dist and pdist builtin functions
  • custom (for i=1:n, for j=i+1:n) loops to avoid computing symmetric terms.
  • some mathworks file exchange functions, such as this one
Unfortunately, no one is faster than the brute force original one. Probably because it is using the full potential of vectorization. I precise that I don't need to compute it for thousands and thousands of points (5000 maximum), so I'm not limited or slowed down by huge memory transfer.
However I need to loop that process millions of time, and speeding it up a little would save me hours.
Any suggestion would be more than welcomed.


Sign in to comment.

Answers (0)


Translated by