2
$\begingroup$

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

enter image description here

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

enter image description here

How do I prevent this from happening?

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – rcollyer Jul 20 '15 at 17:53
  • 1
    $\begingroup$ 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}. $\endgroup$ – David G. Stork Jul 20 '15 at 18:10
  • $\begingroup$ There are some great and wonderful fixes here, but I am also wondering why it happens. $\endgroup$ – David Jul 20 '15 at 23:30
  • 1
    $\begingroup$ Doesn't the error message make clear what the problem is? (Try ParametricPlot3D[{t, t, t}, {t, 0, 0}] if the FE`final$$1819 is confusing you; or execute FE`final$$1819 or whatever the current varialble is. Note that FE`final$$1819 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. $\endgroup$ – Michael E2 Jul 21 '15 at 0:22
  • $\begingroup$ @MichaelE2. Thanks for a nice clear explanation. I tried both of your suggestions and it made things clear. $\endgroup$ – David Jul 21 '15 at 1:33
4
$\begingroup$

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"}]]

plot

$\endgroup$
3
$\begingroup$

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}]]

enter image description here

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

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.

$\endgroup$
  • $\begingroup$ Nice idea. Thanks. $\endgroup$ – David Jul 23 '15 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.