Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

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"]}}]


  • Prev by Date: MatrixForm affects values instead of only printing ?????
  • Next by Date: problem
  • Previous by thread: MatrixForm affects values instead of only printing ?????
  • Next by thread: problem