0
$\begingroup$

I am written a code in which there is large no.of matrix are multiplying I want to reduce it time. Ux[1,1]=F[1,1] and Ux[1,2]=F[1,1].F[1,2] similarly Ux[1,3]=F[1,1].F[1,2].F[1,3]. I have to do it over 20 j values.

 Ax[j_] := Part[RandomReal[{0, 2 \[Pi]}, 20], j];
 Bx[j_] := Part[RandomReal[{0, 2 \[Pi]}, 20], j];
 Cx[j_] := Part[RandomReal[{0, 2 \[Pi]}, 20], j];
 Dx[j_] := Part[RandomReal[{0, 2 \[Pi]}, 20], j];
 X[j_] := Flatten[{Ax[j], Bx[j]}];
 Y[j_] := Flatten[{Cx[j], Dx[j]}];
 n = 100; nr = 4; g = 1;
 \[Theta]1 = N@\[Pi]/4; \[Theta]2 = N@\[Pi]/2; rmax = 
  N[2 \[Pi]]; T = 1; w0 = 10;
 With[{Kx1 = 05}, 
 fxy[{\[Theta]_, r_}] := {Mod[\[Theta] + r - Kx1 Sin[\[Theta]], 
2 \[Pi]], Mod[r - Kx1 Sin[\[Theta]], 2 \[Pi]]}]
 KY[j_] := 
 Transpose[
Catenate[
 Table[Join[NestList[fxy, X[j], n], NestList[fxy, Y[j], n]], {i, 1,
   nr}]]];
TYx[j_] := MapThread[{#1, #2} &, KY[j]];
XX1[j_] := MapThread[(Sqrt[(10 #2)] Cos[#1]) &, KY[j]];
KX[j_, ix_] := Quiet[Part[KY[j], ix]];
SZ = {{2, 0, 0}, {0, 0, 0}, {0, 0, -2}};
SX = {{0, Sqrt[2], 0}, {Sqrt[2], 0, Sqrt[2]}, {0, Sqrt[2], 0}};
H[j_] := MapThread[1/2 w0 SZ + g Sqrt[10 #2] Cos[#1] SX &, 
KY[j]];
HF[j_, ix_] := Quiet[Part[H[j], ix]];
F[j_, ix_] := MatrixExp[-I HF[j, ix]];
Ux[b_, c_] := 
 Table[Apply[Dot, Table[F[j, ix], {ix, 1, c}]], {j, 1, b}];
psi0 = {{1}, {0}, {0}};
psit[b_, c_] := Ux[b, c][[b]].psi0;
SZ = {{2, 0, 0}, {0, 0, 0}, {0, 0, -2}};
SX = {{0, Sqrt[2], 0}, {Sqrt[2], 0, Sqrt[2]}, {0, Sqrt[2], 0}};
Sxz[b_, c_] := ConjugateTranspose[psit[b, c]].SZ.psit[b, c];
SXX[b_, c_] := ConjugateTranspose[psit[b, c]].SX.psit[b, c];

data11c = Total[Table[Table[Sxz[b, c], {c, 1, 100}], {b, 1, 20}]]/20
$\endgroup$
5
  • 1
    $\begingroup$ ˋDot@@listOfMatricesˋ. $\endgroup$ Feb 7, 2022 at 6:35
  • $\begingroup$ Where I have to use it ? For Ux you are saying b is for different initial condition of ix is over which I have to multiply the matrices. $\endgroup$
    – user68207
    Feb 7, 2022 at 6:45
  • $\begingroup$ I have not tried to understand your code (and I won't try). All I am saying is that you could form the list (e.g., by using Table) of matrices that you want to multiply and then Apply Dot to it. $\endgroup$ Feb 7, 2022 at 7:43
  • 1
    $\begingroup$ Btw., how is Ax[j_] := Part[RandomReal[{0, 2 \[Pi]}, 20], j]; supposed to make sense? The random number will be regenated each time you call Ax. $\endgroup$ Feb 7, 2022 at 7:45
  • $\begingroup$ You could try to utilize ParallelTable instead of Table . $\endgroup$
    – rowsi
    Feb 7, 2022 at 7:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.