MathGroup Archive 2013

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

Search the Archive

NDSolve is not deterministic in its solutions??

  • To: mathgroup at
  • Subject: [mg129321] NDSolve is not deterministic in its solutions??
  • From: JBB <barandiaran.juan at>
  • Date: Wed, 2 Jan 2013 21:15:47 -0500 (EST)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

I have a NDSolve in Mathematica 8 .0.1 in which I want to extract (with Sow) the maximums and minimums and also stop the integration when the maxima of the oscillation is under a threshold.
Both conditions require \[Alpha]'[t]==0.

The issue I find is that if I execute the same line of code several times, sometimes it records the last maxima and sometimes it doesn't.

Is there a way to avoid this non deterministic behaviour in NDSolve?
I solved it checking later if the last maxima is in the list and if it is not, adding it in another line of code, but this doesn't look a "nice" solution.

Here is the code: 

Module[{interp, tmaxTemp, surf},
 surf = 0.162;
 Label[repeatChangingSurface]; (*If NDSolve has errors returns here \
and tries again with a slightly different surface *)
 tmaxTemp = 
  1000;(* Define a long enough time of integration to ensure \
convergence *)
 interp = 
  FlattenAt[ (*Eliminate unneccesary nestings in the list result *)
     NDSolve[{1.1089 \[Alpha]''[t] + 1.2936 Sin[\[Alpha][t]] + 
          (0.33 Sin[\[Alpha][t]] + (
            0.33^2 Cos[\[Alpha][t]] Sin[\[Alpha][t]])/Sqrt[
            1 - 0.33^2 Sin[\[Alpha][t]]^2]) *
          UnitStep[Sin[\[Alpha][t] + Pi*UnitStep[-\[Alpha]'[t]]]] == 
        0, \[Alpha][0] == -Pi/3, \[Alpha]'[0] == 0}, \[Alpha], {t, 0, 
      Method -> {"EventLocator", 
        "Event" -> {\[Alpha]'[t], \[Alpha]'[t]}, 
        "EventCondition" -> {True, (Abs[\[Alpha][t]] < 0.01)}, 
        "EventAction" :> {Sow[{t, \[Alpha][t], surf}], 
          Throw[tmaxTemp = t, "StopIntegration"]}}]], {{1}, {2}}];
 If[tmaxTemp == interp[[1]][[1]][[2]][[1]][[1]][[2]],(* 
  If tmaxTemp is the same as the last value of the interp function, 
  the NDSolve has finished succesfully*)
  surf = surf*1.0001; 
  Goto[repeatChangingSurface];] (* Else there was an error in NDSolve \
and we try with a sligthly different surface *)

Notice that if you repeat the execution several times the list of maxima changes.

Sometimes you get this result:
{{\[Alpha] -> \!\(\*
RowBox[{"InterpolatingFunction", "[", 
RowBox[{"0.`", ",", "7.578028259624528`"}], "}"}], "}"}], ",", "\<\"<>\"\>"}],
Editable->False]\)}, {{1.97478, 0.283895, 0.162}, {3.84739, -0.0799267, 
   0.162}, {5.71299, 0.0225631, 0.162}, {7.57803, -0.00637085, 0.162}}}

and sometime this other:

  • Prev by Date: Sorry for the empty message. Here is the problem with DiscreteMarkovProcess...
  • Next by Date: Re: PolynomialQuotient slow
  • Previous by thread: Sorry for the empty message. Here is the problem with DiscreteMarkovProcess...
  • Next by thread: Re: PolynomialQuotient slow