Message Boards Message Boards

0
|
2256 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

[Solved] Unable to run loop correctly. Replace All error.

Posted 4 years ago

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.

Attachments:
2 Replies
Posted 4 years ago

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}   
  ]
 ]
POSTED BY: Rohit Namjoshi

Yes this is exactly what I needed. Thank you so much for your time and help!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract