# 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). Commented 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.) Commented 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. Commented 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? :) Commented Sep 5, 2014 at 17:09
• @user16320 We are just joining the mesh points that Plot[] misses to recognize as joined Commented 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). Commented Sep 5, 2014 at 17:35
• @Szabolcs I didn't want to mean it's a bug. And yes, you're right. Commented Sep 5, 2014 at 17:37

Nevertheless, plotting pendulum solutions shows discontinuities, change the example given in the helppages from over-the-top to oscillations yields a discontinuity before the first period ends (and then more)

\[Phi][t_] = With[{k = 1 - 10^-3}, 2 JacobiAmplitude[k t, k^-2]];

Plot[\[Phi][t], {t, 0, 36}, WorkingPrecision -> 50]


no help from WorkingPrecision, and the answers are real-valued.

• This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review Commented Aug 13, 2023 at 1:01