I wish to calculate a rather dense antisymmetric matrix quite fast based on a random distribution of points (and their radii) in the three dimensional space as follows:
ClearAll["Global`*"];
n = 12; size = n*n*n;
Print["The size of the matrix is = ", size];
grid = RandomReal[{-10, 10}, {size, 3}];
epsilon = 5.2; cl = 6.;
xgrid2 = Map[First, grid];
ygrid2 = Map[(#[[2]]) &, grid];
zgrid2 = Map[Last, grid];
rad[k_, l_] := EuclideanDistance[grid[[k]], grid[[l]]]
mat1 = ParallelTable[With[{radial = rad[i, j]},
If[radial <= epsilon, -((
56 Max[cl - radial,
0]^5 (cl + 5 radial) (xgrid2[[i]] - xgrid2[[j]]))/cl^8), 0]]
, {i, 1, size}, {j, 1, size}]; // AbsoluteTiming
AntisymmetricMatrixQ[mat1]
Unfortunately, although I used ParallelTable, it seems it requires a considerable time when the size of the matrix is high, e.g., when $n=25$ and the size would be $15625$!
So, I would be thankful if someone could provide a couple of comments in order to accelerate such a process.
rad[], you could employEuclideanDistance. – corey979 Sep 10 '16 at 15:35gridare points within a unit cube, so the maximal distance that can be achieved is $\sqrt{3}\approx 1.73$; why do you test whetherradial <= epsilon? It always will. – corey979 Sep 10 '16 at 15:48Compile[]can help us. – M.J.2 Sep 10 '16 at 15:52Nearestcan substantially speed it up; see the beginning of this. – corey979 Sep 10 '16 at 15:57Nearestfor constructing the matrix here? Please write your comment in a piece of implementation. – Faz Sep 10 '16 at 16:06Nearestdoes not make the code faster, or at least I cannot employ it efficiently. So my last remarks are: (1) get rid ofxgrid2,ygrid2,zgrid2; (2) replace(xgrid2[[i]] - xgrid2[[j]])withgrid[[i, 1]] - grid[[j, 1]]), and (3) compute theParallelTableonly for{j,i+1,size}, pad the rest with zeros and add to it a transposed and multiplied by $-1$ matrix. This should speed up the computation by a factor of two (the whole code forn=25run 6 mins, so it easily be reduced to 3 mins). – corey979 Sep 10 '16 at 16:55