I am new to Mathematica. I am tasked with using NDSolve to numerically solve ~10^6 non-linear, coupled ODEs. However, I am only able to solve up to 100 on my computer. My professor says I should be able to do at least 1000. I'm guessing my code is not efficient, but I'm not sure what else to do. Any ideas? I have attached my code:
latSize = 20;
μ = 3;
Do[Do[
Subscript[kx, i, j] = i;
Subscript[ky, i, j] = j;
Subscript[x0, i, j] =
Re[1/2*Sqrt[1 - ((2*μ - (i^2 + j^2))/(2*(i^2 + j^2)))^2] E^(-I*
ArcTan[j/i])];
Subscript[y0, i,
j] = -1*Im[
1/2*Sqrt[1 - ((2*μ - (i^2 + j^2))/(2*(i^2 + j^2)))^2] E^(-I*
ArcTan[j/i])];
Subscript[z0, i, j] = 1/2*((2*μ - (i^2 + j^2))/(2*(i^2 + j^2)));
, {j, 1, latSize, 1}]
, {i, 1, latSize, 1}]
(* Set up delta *)
G = 5;
SuperPlus[Δ1] = -G*
Sum[Sum[Subscript[kx, i, j]*Subscript[x, i, j][t] +
Subscript[ky, i, j]*Subscript[y, i, j][t], {j, 1, latSize,
1}], {i, 1, latSize, 1}];
SuperMinus[Δ1] = -G*
Sum[Sum[Subscript[kx, i, j]*Subscript[x, i, j][t] -
Subscript[ky, i, j]*Subscript[y, i, j][t], {j, 1, latSize,
1}], {i, 1, latSize, 1}];
SuperPlus[Δ2] =
G*Sum[Sum[
Subscript[ky, i, j]*Subscript[x, i, j][t] -
Subscript[kx, i, j]*Subscript[y, i, j][t], {j, 1, latSize,
1}], {i, 1, latSize, 1}];
SuperMinus[Δ2] = -G*
Sum[Sum[Subscript[ky, i, j]*Subscript[x, i, j][t] +
Subscript[kx, i, j]*Subscript[y, i, j][t], {j, 1, latSize,
1}], {i, 1, latSize, 1}];
(* Set up B *)
Do[Do[
Subscript[B1, i, j] =
2*Subscript[kx, i,
j] (SuperPlus[Δ1] +
SuperMinus[Δ1]) +
2*Subscript[ky, i,
j] (SuperMinus[Δ2] - SuperPlus[Δ2]);
Subscript[B2, i, j] =
2*Subscript[kx, i,
j] (SuperPlus[Δ2] +
SuperMinus[Δ2]) +
2*Subscript[ky, i,
j] (SuperPlus[Δ1] - SuperMinus[Δ1]);
Subscript[B3, i, j] = Subscript[kx, i, j]^2 + Subscript[ky, i, j]^2;
, {j, 1, latSize, 1}], {i, 1, latSize, 1}];
(* Set up DE *)
Do[Do[
Subscript[x, i, j]'[t] ==
Subscript[B2, i, j]*Subscript[z, i, j][t] -
Subscript[B3, i, j]*Subscript[y, i, j][t];
Subscript[y, i, j]'[t] ==
Subscript[B3, i, j]*Subscript[x, i, j][t] -
Subscript[B1, i, j]*Subscript[z, i, j][t];
Subscript[z, i, j]'[t] ==
Subscript[B1, i, j]*Subscript[y, i, j][t] -
Subscript[B2, i, j]*Subscript[x, i, j][t];
, {j, 1, 2, 1}], {i, 1, latSize, 1}];
s = NDSolve[
Flatten[Table[{Subscript[x, i, j]'[t] ==
Subscript[B2, i, j]*Subscript[z, i, j][t] -
Subscript[B3, i, j]*Subscript[y, i, j][t],
Subscript[y, i, j]'[t] ==
Subscript[B3, i, j]*Subscript[x, i, j][t] -
Subscript[B1, i, j]*Subscript[z, i, j][t],
Subscript[z, i, j]'[t] ==
Subscript[B1, i, j]*Subscript[y, i, j][t] -
Subscript[B2, i, j]*Subscript[x, i, j][t],
Subscript[x, i, j][0] == Subscript[x0, i, j],
Subscript[y, i, j][0] == Subscript[y0, i, j],
Subscript[z, i, j][0] == Subscript[z0, i, j]}, {i, 1,
latSize}, {j, 1, latSize}]],
Flatten[Table[{Subscript[x, i, j], Subscript[y, i, j], Subscript[z,
i, j]}, {i, 1, latSize}, {j, 1, latSize}]], {t, 0, 1},
Method -> {"EquationSimplification" -> Solve}];
In vector form the equation would be: $\frac{d \vec{r_i}}{dt} = \vec{B_i}\times \vec{r_i}$ Where $\vec{B_i} = \vec{B_i}(\vec{r_1},\vec{r_2},...)$
So if we define $\vec{B} = (B1,B2,B3)$, where the subscript i has been omitted. The B components are of the form: $B_1 = 2*k_x(\Delta1^+ + \Delta1^-) + 2*k_y(\Delta2^- - \Delta2^+)$ Where the deltas have the form: $\Delta1^+ = -G*\sum_{i} k_x*x+k_y*y$

Doloop is redundant. Then, related: https://mathematica.stackexchange.com/q/131411/1871 . I think the best solution is to rewrite the system in vector form, but it's tedious to figure out the vector form of the system from your code. Do you already have the vector form of the system at hand? Or at least the system expressed with traditional math notation? – xzczd Jun 01 '17 at 02:29