# Mathematica and gaps in continuous plot

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]


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.

• 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). Sep 5, 2014 at 17:06
• @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.) Sep 5, 2014 at 17:08
Graphics[{Blue,
Line[Sort @@  Cases[Plot[JacobiAmplitude[Sqrt[0.1]*x, 10], {x, 0, 50}, Mesh -> All],
GraphicsComplex[a_, ___] :> a]]},
AspectRatio -> 1/GoldenRatio, Axes -> True]


• Szabolcs: Thank you for the explanation why does this occur...really weird bug, now I'll be aware of that and it's cause. Sep 5, 2014 at 17:08
• belisarius: now while this is definitely working, I have no clue why...thank you very much, could you explain that code to me please? :) Sep 5, 2014 at 17:09
• @user16320 We are just joining the mesh points that Plot[] misses to recognize as joined Sep 5, 2014 at 17:13
• @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). Sep 5, 2014 at 17:35
• @Szabolcs I didn't want to mean it's a bug. And yes, you're right. Sep 5, 2014 at 17:37