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


3 Answers 3


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

  • $\begingroup$ 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 $\endgroup$
    – MarcoB
    Commented Aug 13, 2023 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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