Matrix M[t] and and Hamiltonian of same order L^n x L^n.
L=3; n=3;tmax = 2;
Rho[t_] = Table[M[i,j][t], {i,L^n}, {j,L^n}]; //Timing
Rho0=ParallelTable[M[i,j][0],{i,L^n},{j,L^n}];
Hop[t_, i_] =
Transpose[
Table[If[i == j, 1, 1+Cos[t]], {i, {1}}, {j, L}]].Table[If[i == j, 1, 1+Sin[t]^2], {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}];
I have made a code for large no. of time dependent differential equations with initial values. I want to compile this for using NDSolve. Here is my code...
Rho1[t_] =
Table[
D[Rho[t],t][[i,j]] == H[t][[i,j]],
{i,L^n}, {j,L^n}]; // Timing
Fun[t_]= -I (#1.#2 - #2.#1)&[H[t],Rho[t]];
Eq0[i_,j_]:=If[i == 1 && j == 1,#==1.,#==0. ]&[Rho0[[i,j]]];
Eq0a=ParallelTable[Eq0[i,j],{i,L^n},{j,L^n}];
Eqsopwo[t_]=Join[Thread /@ Thread[D[Rho[t], t] == Fun[t]],Eq0a]//Flatten;
\[Rho]Termsop[t_]=Rho[t]//Flatten;
sol= NDSolve[Eqsopwo[t],Diagonal[Rho[t]],{t,0,tmax},DependentVariables->\[Rho]Termsop[t],MaxSteps->10^5,MaxStepFraction-> 1/50, Method-> {"EquationSimplification"->"Solve"}]//Chop;
Plot[Evaluate[{Re[Diagonal[Rho[t]]]}/.sol],{t,0,tmax},PlotRange->All]

NDSolvewill useCompileautomatically… – xzczd Jan 29 '14 at 08:47