I have a bit of trouble with Mathematica and it's plotting stuff. I tried to plot Jacobi amplitude function:

JacobiAmplitude[Sqrt[0.1]*x, 10], {x, 0, 50}]

but the result leaves gaps where the roots of the function should be (particularly for this function around x = 3, 6, 10, ...). I've done a bit of googling and found that either Exclusions set to None or raising PlotPoints should help. Well, it didn't. I even tried to set MaxRecursion to 8, PlotPoints to one million, waited several hours for the plot and it didn't change. Funny thing is, that when I added Mesh -> None, I've found out, that mathematica added plot points even at the gaps, but it didn't join them with lines! This is something like bug, or how should I deal with that? Any help'd be appreciated.

P.S.: I'm using Mathematica 9.0


There's a small but nontrivial complex part to the value being plotted that arises from using MachinePrecision numbers for plotting. Use arbitrary precision numbers by setting the WorkingPrecision to a suitable value.

Plot[JacobiAmplitude[Sqrt[0.1]*x, 10], {x, 0, 50}, WorkingPrecision -> 10]

Mathematica graphics

Or, Szbolcs' points out, one can apply Chop orRe to your function, which will be faster, if you are certain your function is real-valued.

  • $\begingroup$ Or use Chop or use Re (knowing that it's real anyway). With WorkingPrecision, the tradeoff is just performance, so WorkingPrecision is probably the best (except for logarithmic plots, where it's broken). $\endgroup$ – Szabolcs Sep 5 '14 at 17:06
  • $\begingroup$ @Szabolcs Thanks! I did use Chop at first, but I like to check it with arbitrary precision. If the imaginary part persists with arbitrary precision, then I like to look into things further. (I don't know much about JacobiAmplitude, so I was cautious.) $\endgroup$ – Michael E2 Sep 5 '14 at 17:08
          Line[Sort @@  Cases[Plot[JacobiAmplitude[Sqrt[0.1]*x, 10], {x, 0, 50}, Mesh -> All],
                              GraphicsComplex[a_, ___] :> a]]}, 
 AspectRatio -> 1/GoldenRatio, Axes -> True]

Mathematica graphics

  • $\begingroup$ Szabolcs: Thank you for the explanation why does this occur...really weird bug, now I'll be aware of that and it's cause. $\endgroup$ – user16320 Sep 5 '14 at 17:08
  • $\begingroup$ belisarius: now while this is definitely working, I have no clue why...thank you very much, could you explain that code to me please? :) $\endgroup$ – user16320 Sep 5 '14 at 17:09
  • 1
    $\begingroup$ @user16320 We are just joining the mesh points that Plot[] misses to recognize as joined $\endgroup$ – Dr. belisarius Sep 5 '14 at 17:13
  • 3
    $\begingroup$ @user16320 There's no bug here really. The computation uses complex numbers (often necessary even if the result is strictly real), and due to roundoff errors the imaginary part comes out as tiny but non-zero. If you set WorkingPrecision, this still happens. However, in this case Mathematica also does precision tracking (a rather unique feature of the system) and it is able to automatically realize that the imaginary part is closer to zero than the numerical errors (and thus discardable). $\endgroup$ – Szabolcs Sep 5 '14 at 17:35
  • $\begingroup$ @Szabolcs I didn't want to mean it's a bug. And yes, you're right. $\endgroup$ – Dr. belisarius Sep 5 '14 at 17:37

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.