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
. $\endgroup$grid
are 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. $\endgroup$Compile[]
can help us. $\endgroup$Nearest
for constructing the matrix here? Please write your comment in a piece of implementation. $\endgroup$