MathGroup Archive 2006

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

Search the Archive

Re: StoppingTest options (need help)


You can use EventLocator for localization of some event (in your case
coordinates {1,2,3}). Since EventLocator is trying to find this situation by
several methods and it have a lot of settings, I recommend you to have a
look at Advanced documentation for NDSolve.

First You can try this illustrative example i made for you (equation of the
second order) and you can follow basic ideas of this approach  without
reading documentation

from = 0;
to = 20;
eqn = {u''[x] + Sin[u[x]] == 0, u[0] == 1, u'[0] == 0};

sol = u /. NDSolve[eqn, u, {x, from, to}][[1]];

stoppingTime = to;
solStopped = u /. NDSolve[eqn, u, {x, 0, 20},
    Method -> {"EventLocator", "Event" :> u'[x], "EventAction" :>
Throw[stoppingTime = x,

Plot[sol[t], {t, from, to}, PlotStyle -> Hue[0.7], DisplayFunction ->
Plot[solStopped[t], {t, from, stoppingTime}, PlotStyle -> Hue[0.],
DisplayFunction -> Identity];
Show[%, %%, DisplayFunction -> $DisplayFunction];

As you can see, the integration of equation is finished when the derivative
is equal to zero - event u'[x] (analogically you cas put event "u[x]-const"
and integration is going until solution reach value "const", or you can use
however complicated expression..).

I hope, that it will help you.

Best regards,

Josef Otta

2006/12/25, Cham <martin465 at>:
> I'm using the NDSolve command to find a closed curve (it's a magnetic
> field line). It works, but I need to end the calculation at a specific point
> in space, so I don't get a curve with many turns.  I only want a single turn
> to draw a complete loop.  How can I use the StoppingTest options to tell
> Mathematica to find a single turn loop ?  The specific code is like this :
> NDSolve[
> {
> x'[t] == Bx[x[t], y[t], z[t]],
> y'[t] == By[x[t], y[t], z[t]],
> z'[t] == Bz[x[t], y[t], z[t]],
> x[0] == 0,
> y[0] == 1,
> z[0] == 0,
> }, {x, y, z}, {t, 0, 100}, StoppingTest -> ( ? ? ? )]
> Suppose I want the curve to stop at coordinates {x, y, z} = {1, 2, 3}, or
> better, I want it to be a complete loop with a single turn (stop when it's
> back at the initial coordinates).  How can I tell that to Mathematica ?

  • Prev by Date: Re: GraphPlot display anomaly
  • Next by Date: RE: programming problem about elements taken
  • Previous by thread: StoppingTest options (need help)
  • Next by thread: regularize a function (proof function)