I'm using Flatten
to contract a rank 4 tensor and a matrix (rank 2 tensor) inside NDSolve
and there seems to be error. Here is my code
g = 1;
tbar = 30;
n = 4;
d0 = IdentityMatrix[n];
d = Table[If[i == j - 1, Sqrt[j], 0], {i, 0, n - 1}, {j, 0, n - 1}];
h = N[Outer[Times, Transpose[d].d, d0] +
Outer[Times, d0, Transpose[d].d] + g*
Outer[Times, d + Transpose[d],
d + Transpose[d]]];
c0 = Table[If[i == 1 && j == 1, 1, 0], {i, 0, n - 1}, {j, 0, n - 1}];
sol = NDSolve[{c'[t] == -I*
Flatten[h, {{1}, {3}, {2, 4}}].Flatten[c[t], {1, 2}],
c[0] == c0}, c, {t, 0, tbar}];
I get the error
what am I doing wrong?
Flatten[c[t], {1, 2}]
is wrong There is nothing to Flatten here. That is what the error is saying basically. Why do you want to Flattenc[t]
for? $\endgroup$Flatten[c[t], {1, 2}]
to be?c[t]
is not a list. If you just typeFlatten[c[t], {1, 2}]
on its own, you will see the error. $\endgroup$