I have a time dependent matrix $M(t)$ of $L^n \times L^n$ size and want to write differential equations like D[M[i,j][t],t] = H[i,j][t]
Here is my code:
L=3; n=3;
Rho[t_] = Table[M[i,j][t], {i,L^n}, {j,L^n}]; //Timing(*Rho2[t]//MatrixForm*)
(* {0.00100,Null} *)
Hop[t_, i_] =
Transpose[
Table[If[i == j, 1, Cos[t]], {i, {1}}, {j, L}]]
. Table[If[i == j, 1, Sin[t]], {i, {2}}, {j, L}]
I1[i_Integer] := I1[i]=IdentityMatrix[L^(i-1)];
I2[i_Integer] := I2[i]=IdentityMatrix[L^(n-i)];
H[t_] = Sum[FixedPoint[ArrayFlatten, I1[i] \[TensorProduct] Hop[t,i]
\[TensorProduct]I2[i]],{i,n}];
Rho1[t_] =
Table[
D[Rho[t],t][[i,j]] == H[t][[i,j]],
{i,L^n}, {j,L^n}]; // Timing(*Rho1[t]//MatrixForm*)
(* {0.33500,Null} *)
I can make it faster by using the Parallel
command:
Rho2[t_] =
ParallelTable[
D[Rho[t],t][[i,j]] == H[t][[i,j]],
{i,L^n}, {j,L^n}]; // Timing(*Rho1[t]//MatrixForm*)
(* {0.08100,Null} *)
Is there any other way by using Map
or Transpose
to make it more efficient?
Rho1[t_]
you should be able to simply useMap[D[#, t] &, Rho[t]]
. On my machine usingTable
gives a timing of 0.277257, while usingMap
gives a timing of 0.001321. Is this the operation you are trying to speed up? Maybe I misunderstood the question. $\endgroup$Table
in yourRho1[t_] = ...
.D
isListable
so you can just writeRho1[t_] = D[Rho[t], t]
. $\endgroup$Listable
nature ofD[…]
. Your solution reads better. $\endgroup$D[M[i,j][t],t]=H[i,j][t]
. @leibs Map make it good but still not that efficient because I need to create set of diff. equations. $\endgroup$Rho2
a matrix shape or a 1-dimension list with all equations is ok? $\endgroup$