How can I limit the time slider to the NDSolve solution range in a Manipulate box, so no extrapolation is used ? More specifically, here's a stripped down version of my Manipulate code which shows the problem :
X[t_] := {x[t], y[t], z[t]}
V[t_] := {x'[t], y'[t], z'[t]}
r[t_] := Norm[X[t]]
DipField[t_] := 3 ({0, 0, 1}.X[t]) X[t]/r[t]^5 - {0, 0, 1}/r[t]^3
Solution[v0_, theta_] := NDSolve[{
x''[t] == Sqrt[1 - v0^2] {1, 0, 0}.Cross[V[t], DipField[t]],
y''[t] == Sqrt[1 - v0^2] {0, 1, 0}.Cross[V[t], DipField[t]],
z''[t] == Sqrt[1 - v0^2] {0, 0, 1}.Cross[V[t], DipField[t]],
x[0] == 1, y[0] == 0, z[0] == 0, x'[0] == 0, y'[0] == v0 Sin[theta], z'[0] == v0 Cos[theta]
}, {x, y, z}, {t, 0, 1000},
Method -> Automatic, PrecisionGoal -> 7, MaxSteps -> 1000000,
StoppingTest -> (r[t] < 0.1)]
Tmax[v0_, theta_] := (x /. Solution[v0, theta])[[1]][[1]][[1]][[2]]
Trajectory[t_, v0_, theta_] := ParametricPlot3D[Evaluate[X[s] /. Solution[v0, theta]], {s, 0.001, t}]
Manipulate[
Show[
Trajectory[t, v0, theta Pi/180],
PlotRange -> {{-2, 2}, {-2, 2}, {-1, 1}},
SphericalRegion -> True
],
{{t, 150, Style["Time", 10]}, 0, 200, 0.1},
{{v0, 0.25, "Velocity"}, 0, 1, 0.01},
{{theta, 63.3, "Polar angle"}, 30, 150, 0.1},
ControlPlacement -> Bottom
]
Here's a preview of the problem :
Currently, the Manipulate shows a part that comes from extrapolation, that shouldn't be there. The time slider should be limited to
Tmax[v0, theta]
but whathever what I'm trying in the time slider doesn't work.
EDIT : I'll try to be clearer. I solve some diff. equs using NDSolve, for time "t" going from 0 up to 1000. There's a contraint : NDSolve should stop if r[t] < 0.1. My code is doing this fine and finds a solution valid for 0 < t < Tmax[v0, theta] (I defined "Tmax" as a function of initial conditions).
Then I draw the solution using Manipulate, for all "t". Currently, the Manipulate code above is using all "t" up to 1000, which it shouldn't. For some initial conditions "v0" and "theta", Manipulate shows some extrapolation. The time slider must go instead from 0 up to Tmax(v0, theta). This is what I don't know how to do right.
EDIT 2 : The "duplicate" indicated above doesn't help much. I don't even see how it is related. The code shown there is so much different and much more complicated, it is not obvious at all to see how it may be related.

StoppingTestis an unknown option. This might be the cause of your problem. – Sjoerd C. de Vries Mar 12 '16 at 19:48Stoppingtest? Why do you have it there? – Sjoerd C. de Vries Mar 12 '16 at 20:04WhenEvent. – Sjoerd C. de Vries Mar 12 '16 at 20:15"ExtrapolationHandler" -> {Indeterminate &, "WarningMessage" -> False}to NDSolve? (if you have a reasonably recent version of Mathematica) – Sjoerd C. de Vries Mar 12 '16 at 21:23Manipulate[If[t > Tmax[v0, theta], t = Tmax[v0, theta]]; Show[Trajectory[t, v0, theta Pi/180], PlotRange -> {{-2, 2}, {-2, 2}, {-1, 1}}, SphericalRegion -> True], {{t, 150, Style["Time", 10]}, 0, Tmax[v0, theta], 0.1}, {{v0, 0.25, "Velocity"}, 0, 1, 0.01}, {{theta, 63.3, "Polar angle"}, 30, 150, 0.1}, ControlPlacement -> Bottom]work for you? – Sjoerd C. de Vries Mar 12 '16 at 21:50