Stopping NDSolve after a condition is met x times
- To: mathgroup at smc.vnet.net
- Subject: [mg100297] Stopping NDSolve after a condition is met x times
- From: James <jborrell at umd.edu>
- Date: Sun, 31 May 2009 06:35:31 -0400 (EDT)
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"]}}]