[Scilab-users] {EXT} need a more efficient and faster code: suggestions welcome
Wozai
wozai at protonmail.ch
Thu Feb 1 10:15:01 CET 2018
Hi,
On a Intel(R) Core(TM) i3-3220T CPU @ 2.80GHz (Linux), the following code
needs ~8s and
it doesn't allocate that much memory.
n=20000;
r=23;
radius = r*grand(n,1,'def').^(1/3);
phi = 2*%pi*grand(n,1, 'def');
costheta = 1 - 2*grand(n,1, 'def');
radsintheta = radius.*sin(acos(costheta));
X = [radsintheta.*cos(phi),radsintheta.*sin(phi), radius.*costheta];
ONE=ones(n,1);
NAN=[%nan,%nan,%nan];
SUM=[1;1;1];
MinDist=zeros(1,n);
for i=1:n;
XX = X;
XX(i,:) = NAN;
DIFF = XX - ONE*X(i,:);
MinDist(i) = sqrt(min((DIFF.*DIFF)*SUM));
end;
Cheers,
wozai
--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
More information about the users
mailing list