There are 4 variables in this multiple sum, therefore it may take a long time. I have run this program for 12 hours, but no result untill now. I want to know how to speed up this code. Any help or suggestion will be highly appreciated!
the code is bellow:
data = Table[Exp[-((i + j - 100.)/10)^2] Exp[-((i - j)/10)^2], {i, 100}, {j, 100}];
data = Chop[data, 0.00001];
data = data/Sqrt[Sum[(data[[i, j]])^2, {i, 1, 100}, {j, 1, 100}]];
ListDensityPlot[data, InterpolationOrder -> 0, Mesh -> All,
PlotRange -> All, ColorFunction -> (Blend[{Hue[2/3], Hue[0]}, #] &)]
S1[i_, j_, k_, m_,
t_] := (data[[i, k]] data[[j, m]])^2 + (data[[j, k]] data[[i,
m]])^2 -
2 data[[i, k]] data[[j, m]] data[[j, k]] data[[i,
m]] Cos[(2 \[Pi]*(3*10^8)/(1584 - 5 + j*0.1 - 0.05) -
2 \[Pi]*(3*10^8)/(1584 - 5 + i*0.1 - 0.05)) t];
S2[t_] := 1/4*\!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(100\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(j = 1\), \(100\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(100\)]\(
\*UnderoverscriptBox[\(\[Sum]\), \(m = 1\), \(100\)]S1[i, j, k, m, t]\)\)\)\);
ListPlot[Table[S2[i], {i, -0.01, 0.01, 0.0001}], Joined -> True,
PlotRange -> All, Frame -> True]
SparseArray
andParallelSum
. $\endgroup$S1
andS2
, instead of putting them into functions, and I'd do it by breaking it into pieces. For example,data[[i, k]] data[[j, m]]
is identical todata[[j, k]] data[[i, m]]
up to a permutation of indices, so you only have to calculate it once. I'll try and get back to this later today, but that should give you a direction, at least. $\endgroup$data /= Norm@Flatten[data]
ordata /= Sqrt@Total[data^2, 2]
(this is not an answer, just some tips) $\endgroup$