Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'How to stop NDSolve after a rule is met x times' topicStudent Support Forum > General > Archives > "How to stop NDSolve after a rule is met x times"

Help | Reply To Topic
Author Comment/Response
james
05/30/09 4:44pm

I am trying to stop integrating the equations of motion of a simple pendulum after the bob has crossed the vertical a certain number of times. This is the code I have so far. "k" counts the number of times the bob crosses the vertical.

EOM = x''[t] + 9.8 Sin[x[t]];
x1ic = Pi/2;
x1pic = 0;
k = {0};
NDSolve[{EOM == 0, x[0] == x1ic, x'[0] == x1pic}, {x}, {t, 0, 10}, Method -> {EventLocator, "Event" -> {x[t],First[k] - 5}, EventAction :> {k == k++; Print[k],Throw[t1 = t; xt1 = x[t]; xpt1 = x'[t];,StopIntegration"]}}]

URL: ,
Help | Reply To Topic