# Initial value producing an error in a dynamic display

I have

DynamicModule[{f, surf},
f[x_, y_] = x^2 y + 3 x y^4;
surf = Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, PlotRange -> 3,
PlotStyle -> Opacity[0.6],
ClippingStyle -> None];
Manipulate[
Show[
surf,
ParametricPlot3D[{Sin[2 t], Cos[t], f[Sin[2 t], Cos[t]]}, {t, 0,
final},
PlotStyle -> {Thick, Blue}]
], {{final, 0.1}, 0, 2 Pi}
]
]


which produces this image

However, when I move the slider to zero, I get this image.

How do I prevent this from happening?

• I only get it if final is allowed to become 0, then you get a host of messages along with ParametricPlot3D returning unevaluated. But, changing the range to {{final, 0.1}, 0.1, 2 Pi} works just fine for me. – rcollyer Jul 20 '15 at 17:53
• Works fine for me (v. 10.1, Mac OS X) except at final -> 0. Thus change the range to {0.001, 2 Pi} or the plot {t, -0.001, final}. – David G. Stork Jul 20 '15 at 18:10
• There are some great and wonderful fixes here, but I am also wondering why it happens. – David Jul 20 '15 at 23:30
• Doesn't the error message make clear what the problem is? (Try ParametricPlot3D[{t, t, t}, {t, 0, 0}] if the FEfinal$$1819 is confusing you; or execute FEfinal$$1819 or whatever the current varialble is. Note that FEfinal1819 is the actual variable instance created by the Front End for you variable final.) I've always felt this was a wrong decision by Wolfram, and instead of an unevaluated command, one should get an empty plot. Your use-case, which I've encountered many times, illustrates why. – Michael E2 Jul 21 '15 at 0:22
• @MichaelE2. Thanks for a nice clear explanation. I tried both of your suggestions and it made things clear. – David Jul 21 '15 at 1:33

Replace

ParametricPlot3D[{Sin[2 t], Cos[t], f[Sin[2 t], Cos[t]]}, {t, 0, final},
PlotStyle -> {Thick, Blue}]


with

If[final > 0,
ParametricPlot3D[{Sin[2 t], Cos[t], f[Sin[2 t], Cos[t]]}, {t, 0, final},
PlotStyle -> {Thick, Blue}],
{}]]


### Edit

Full code with image at final = 0

DynamicModule[{f, surf},
f[x_, y_] = x^2 y + 3 x y^4;
surf = Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2},
PlotRange -> 3,
PlotStyle -> Opacity[0.6],
ClippingStyle -> None];
Manipulate[
Show[
surf,
If[final > 0,
ParametricPlot3D[{Sin[2 t], Cos[t], f[Sin[2 t], Cos[t]]}, {t, 0, final},
PlotStyle -> {Thick, Blue}],
{}]],
{final, 0, 2 Pi, Appearance -> "Labeled"}]]


Another fix, besides excluding the offending value from the range is to suppress the error:

 Quiet@Check[
ParametricPlot3D[{Sin[2 t], Cos[t], f[Sin[2 t], Cos[t]]}, {t, 0,
final}, PlotStyle -> {Thick, Blue}], {}]


Edit: the full working code:

 DynamicModule[{f, surf}, f[x_, y_] = x^2 y + 3 x y^4;
surf = Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}, PlotRange -> 3,
PlotStyle -> Opacity[0.6], ClippingStyle -> None];
Manipulate[
Show[surf,
Quiet@Check[
ParametricPlot3D[{Sin[2 t], Cos[t], f[Sin[2 t], Cos[t]]},
{t, 0,final}, PlotStyle -> {Thick, Blue}], {}]],
{{final, 0.1}, 0, 2 Pi}]]


• Sorry for (the now retracted) down vote. Without full code, didn't test and misread your original version. – m_goldberg Jul 20 '15 at 21:19

You can add $MachineEpsilon to the lower bound of the final range. {{final, 0.1}, 0 +$MachineEpsilon, 2 Pi}


This will allow final to go as close to zero as possible, from above, without equalling zero; the supremum of final > 0`.

Hope this helps.

• Nice idea. Thanks. – David Jul 23 '15 at 0:20