[Scilab-users] {EXT} need a more efficient and faster code: suggestions welcome

Rafael Guerra jrafaelbguerra at hotmail.com
Wed Jan 31 23:31:14 CET 2018


Hi Heinz,

Find herein a vectorised memory hog solution for Scilab 6, which is fast (~30 s for 20K points on Win7 laptop):

// START OF CODE (Scilab 6)
Clear
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];
tic;
X2 = sum(X.*X, 'c');
X3 = X2.*.ones(n,1)';
X3 = X3 + X3';
D = abs(X3 - 2*(X*X'))';
D(1:n+1:$) = [];  // remove diagonal 0's
D = matrix(D,n-1,n); // reshape D to (n-1) x n size
MinDist1 = sqrt(min(D,'r'));
t1=toc();
disp(t1)
jj=-0.05:0.1:3.05;
H1 = histc(jj,MinDist1);
disp([0.05+jj(1:$-1)' H1']);
// END OF CODE

Regards,
Rafael



More information about the users mailing list