MathGroup Archive 1997

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

Search the Archive

Re: StoppingTest does not work ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9807] Re: StoppingTest does not work ?
  • From: Robert Knapp <rknapp>
  • Date: Fri, 28 Nov 1997 05:35:19 -0500
  • Organization: Wolfram Research, Inc.
  • Sender: owner-wri-mathgroup at wolfram.com

Gilles BARBIER wrote:
> 
>      Anyone could tell me why :
> 
>      NDSolve[{y'[t]==1,y[0]==0},{y},{t,0,2},StoppingTest->(y[t]>1)]
> 
>      does not stop for t=1 (it does not stop at all, in fact).
>      Of course, my problem is more complicated, but in all case
>      stoppingTest seems to stop when it wants...
> 
>      Thanks for quick help, Please !!!
> 
>      Gilles.

The stopping test is not designed to stop the method at the exact point
at which the test becomes True.  This would slow down the method too
much.  Instead, the StoppingTest is evaluated at the end of each time
step of the core integrator.  

In this case, the times steps are very large since the ODE is so simple,
so the last time step jumps from t = 0.00178885 to t = 2., so the point
at which NDSolve sees that your condition is True is the end of the
integration!

One way you can get a little closer to the point at which the condition
occurs is to restrict the maximum step size.  (Reducing this too much
will degrade the global accuracy of the method), such as

In[38]:=
NDSolve[{y'[t]==1,y[0]==0},{y},{t,0,2},StoppingTest->(y[t]>1.),
  MaxStepSize->.01]

Out[38]=
{{y\[Rule]InterpolatingFunction[{{0.,1.00179}},"<>"]}}

Once you are this close, you could use FindRoot

In[39]:=
FindRoot[Evaluate[y[t] == 1. /. First[%]],{t,.999,1.001}]

Out[39]=
{t\[Rule]1.}

to get a better value.


  • Prev by Date: Re: Matrix Inversion Method ?
  • Next by Date: Re: Merging InterpolatingFunctions
  • Previous by thread: RE: Re[2]: StoppingTest does not work ?
  • Next by thread: Mathematica PrograMing Constructs Timing Comparison