1
$\begingroup$

For example, compare the two commands below.

ContourPlot[
 Abs[(Exp[I p] - 1) (Exp[I q] - 1)] == 0, {p, 0, 2 Pi}, {q, 0, 2 Pi}]
ContourPlot[
 Abs[(Exp[I p] - 1) (Exp[I q] - 1)] == 10^-10, {p, 0, 2 Pi}, {q, 0, 
  2 Pi}]

Obvisouly, $|(e^{ip}-1)(e^{iq}-1)|=0$ is only possible on the square boundary $p,q=0,2\pi$, but on my computer, Mathematica produces two entirely different graphs below.

enter image description here

Mathematica cannot give the correct result for the first command, while it does if we change $0$ to $10^{-10}$. I think it has something to do with how Mathematica manages errors with complex numbers.

I need to work with something much more complicated than this complex function, but I really don't know how to proceed if I can't make Mathematica correctly do this basic one.

$\endgroup$
7
  • 1
    $\begingroup$ From help, under possible issues it says Contours f(x,y)==0 for functions where f(x,y)>=0 are always poorly detected: may be this is why? ref/ContourPlot $\endgroup$
    – Nasser
    Nov 4 '21 at 21:56
  • $\begingroup$ @yarchik Thank you! I think this is a similar topic. $\endgroup$
    – Apocalypse
    Nov 4 '21 at 22:00
  • $\begingroup$ @Nasser But it doesn't tell exactly why and how to solve. LOL. $\endgroup$
    – Apocalypse
    Nov 4 '21 at 22:01
  • $\begingroup$ well, it says right after that Giving a value in between allows for easy contouring: may be this is meant to to be how to solve it. This explains why giving some value above zero makes it show up? I guess the lesson for us today, is to avoid using Contours f(x,y)==0 for functions where f(x,y)>=0 $\endgroup$
    – Nasser
    Nov 4 '21 at 22:08
  • 3
    $\begingroup$ I don't know exactly what Mathematica does, but a common contour plotting method is to sample the function on a grid and draw contours between adjacent grid points whose values straddle the intended contour levels. If the region within the contour is so narrow that no grid point samples it, you get no contour. $\endgroup$
    – John Doty
    Nov 4 '21 at 22:34
3
$\begingroup$

For this critical case f[x,y]>=0 use RegionPlot as simple workaround:

RegionPlot[Abs[(Exp[I p] - 1) (Exp[I q] - 1)] <= .00001, {p, 0,2Pi}, {q, 0,2 Pi}]

enter image description here

$\endgroup$
3
  • $\begingroup$ @MichaelE2 Sorry I meant f[x,y]>=0. Yes it's quite similar, but my experience shows that RegionPlot evaluates more reliable in this case. $\endgroup$ Nov 5 '21 at 11:59
  • $\begingroup$ I see what you mean: that RegionPlot seems more reliable than ContourPlot when comparing f[x,y] to a small number, not that it handles the case when comparing to exactly zero. $\endgroup$
    – Michael E2
    Nov 5 '21 at 12:02
  • $\begingroup$ That’s a good method, thank you! $\endgroup$
    – Apocalypse
    Nov 5 '21 at 17:41

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