Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #13022 > unrolled thread
| Started by | JBB <barandiaran.juan@gmail.com> |
|---|---|
| First post | 2013-01-03 02:14 +0000 |
| Last post | 2013-01-03 02:14 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
NDSolve is not deterministic in its solutions?? JBB <barandiaran.juan@gmail.com> - 2013-01-03 02:14 +0000
| From | JBB <barandiaran.juan@gmail.com> |
|---|---|
| Date | 2013-01-03 02:14 +0000 |
| Subject | NDSolve is not deterministic in its solutions?? |
| Message-ID | <kc2pht$md7$1@smc.vnet.net> |
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 *)
Reap[Quiet@
NDSolve[{1.1089 \[Alpha]''[t] + 1.2936 Sin[\[Alpha][t]] +
210*surf*
(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,
tmaxTemp},
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*)
interp,
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] -> \!\(\*
TagBox[
RowBox[{"InterpolatingFunction", "[",
RowBox[{
RowBox[{"{",
RowBox[{"{",
RowBox[{"0.`", ",", "7.578028259624528`"}], "}"}], "}"}], ",", "\<\"<>\"\>"}],
"]"}],
False,
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:
{{\[Alpha]->InterpolatingFunction[{{0.,7.57803}},<>]},{{1.97478,0.283895,0.162},{3.84739,-0.0799267,0.162},{5.71299,0.0225631,0.162}}}
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web