Hi I am an undergraduate and new to Mathematica. For my research, I had to run the loop but unfortunately I got the errors listed below the code and I don’t know what they mean, let alone fix them. I tried running the loop manually by running each statement outside the loop and it worked, but with the loop it’s not running. I have attached a notebook containing the code that I’m struggling with. Can someone please help me understand what I’m doing wrong? Thank you.
test code.nb (22.4 KB)
Hi Avidaan,
There are some ; missing in the For loop. Better to use Table. Is this what you are looking for?
Module[{a = 0 , t0 = 0, tf = 10^(-9), dt = 2*10^(-10), m1val = {0, 1, 0}, m2val = {0, 0, 1}},
Table[
If[
EvenQ[a],
sol1 =
NDSolve[{m1'[t] == LL1[Subscript[H, sp][m1[t]]], m1[j] == m1val},
m1, {t, j, j + dt}, MaxSteps -> \[Infinity]];
Evaluate[m1[t] /. sol1][[1]];
m1val = Evaluate[m1[t] /. sol1][[1]] /. {t -> j + dt};
a++;
{sol1, m1val},
sol2 =
NDSolve[{m2'[t] == LL2[Subscript[H, sp][m2[t]]], m2[j] == m2val},
m2, {t, j, j + dt}, MaxSteps -> \[Infinity]];
Evaluate[m2[t] /. sol2][[1]];
m2val = Evaluate[m2[t] /. sol2][[1]] /. {t -> j + dt};
a++;
{sol2, m2val}
],
{j, t0, tf, dt}
]
]
Yes this is exactly what I needed. Thank you so much for your time and help!