Re: Stopping NDSolve after a condition is met x times

• To: mathgroup at smc.vnet.net
• Subject: [mg100332] Re: Stopping NDSolve after a condition is met x times
• From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
• Date: Mon, 1 Jun 2009 07:08:25 -0400 (EDT)
• References: <gvtmgr\$gg1\$1@smc.vnet.net>

```Hi,

beside the fact that you input miss several brackets,
you increment a list k={0} and later
k++ and you compare a list k == k++
with it's increment

No wonder that in not work.

But

EOM = x''[t] + 9.8 Sin[x[t]];
x1ic = Pi/2;
x1pic = 0;
k = 0;
sol = NDSolve[{EOM == 0, x[0] == x1ic, x'[0] == x1pic}, {x[t]}, {t, 0,
100}, Method -> {"EventLocator", "Event" -> x[t],
"EventAction" :> (k++;
If[k > 4, Throw[Null, "StopIntegration"]])}]

work fine.

Regards
Jens

James wrote:
> 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: Re: Reading Fortran Data file
• Next by Date: Re: problem
• Previous by thread: Re: Problems with V7
• Next by thread: Re: problem