Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'NDSolve imposing constraint' topicStudent Support Forum > General > "NDSolve imposing constraint"

Help | Reply To Topic
Author Comment/Response
Thomas Hocker
12/04/06 02:01am

Hello,

with

Reap[NDSolve[{x''[t] + x[
t] == 0, x[0] == 1, x'[0] == 0}, x, {t, 0,
2? - 0.1}, EvaluationMonitor :> Sow[{t, x[t]},
x'[t]]], n_ /; n < 0.001];

I can impose a constraint on the output of NDSolve. In this example, only the solution up to the condition x'[t]<0.001 is displayed. However, the ODE is evaluated over the whole time-range, i.e., for {t, 0, 2? - 0.1}.

Using "Catch" and "Throw", it should be possible to evaluate the ODE only up to the point where the condition holds and then abort. When I use

Catch[NDSolve[{x''[t] + x[t] == 0, x[0] == 1, x'[0] == 0}, x, {t, 0,
2? - 0.1}, EvaluationMonitor :> Throw[{t, x[t]}, x'[
t]]], n_ /; n > 0.001]

this produces the following error message:

Throw::nocatch: Uncaught Throw[{0., 1.}, 0.] returned to top level.

Does anyone know how to do it properly?

Thanks
Thomas

URL: ,
Help | Reply To Topic