The following is a question in regards to the matrix $A$ (originally the zero $4n \times 4n$ matrix) below:
In[288]:= For[j = 1, j <= 2 n, j++,
For[k = 1, k <= 2 n, k++,
A[[2 j - 1]][[2 k - 1]] = -2 I*H[[j]][[k]] - M[[k]][[j]] +
M[[j]][[k]];
A[[2 j - 1]][[2 k]] = 2*I*M[[j]][[k]];
A[[2 j]][[2 k - 1]] = -2*I*M[[k]][[j]];
A[[2 j]][[2 k]] = -2 I*H[[j]][[k]] + M[[k]][[j]] - M[[j]][[k]];
];
]; // AbsoluteTiming
Out[288]= {25.767, Null}
$H$ and $M$ are both matrices of size $2n \times 2n$ and $n = 640$.
I have tried using Table (code below) but it seems to run much slower than the above code.
In[291]:= A = Table[
p = Ceiling[j/2]; q = Ceiling[k/2];
If[OddQ[j] && OddQ[k], -2 I*H[[p]][[q]] - M[[q]][[p]] +
M[[p]][[q]], 0]
If[OddQ[j] && EvenQ[k], 2*I*M[[p]][[q]], 0]
If[EvenQ[j] && OddQ[k], -2*I*M[[q]][[p]], 0]
If[EvenQ[j] && EvenQ[k], -2 I*H[[p]][[q]] + M[[q]][[p]] -
M[[p]][[q]], 0]
, {j, 1, 4 n}, {k, 1, 4 n}]; // AbsoluteTiming
Out[291]= {52.4175, Null}
I was wondering what possible speed ups there are for the generation of $A$?