I need to get a matrix $\{a(x_i-x_j)\}$, where $x_i$ form a partition of an interval, $a(x)$ is a given function. I use
In[67]:= a[x_?NumericQ] := N[Exp[-Abs[x]]];
x = Table[-10 + 0.02 (j - 1), {j, 1, 1001}];
A = Outer[a[#1 - #2] &, x, x]; // AbsoluteTiming
Out[69]= {2.99032, Null}
I think it spends too much time. A modification
In[209]:= B = Partition[Map[a, Flatten[Outer[#1 - #2 &, x, x]]], 1001]; // AbsoluteTiming
Out[209]= {2.88966, Null}
does not help too much as well. Can I do this faster?
Exp[-Abs[x - #]] & /@ x
is faster than 0.02 seconds on my machine. $\endgroup$DistanceMatrix[]
function might be useful here. $\endgroup$