1

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.

Apocalypse
  • 379
  • 1
  • 7
  • 1
    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 – Nasser Nov 04 '21 at 21:56
  • @yarchik Thank you! I think this is a similar topic. – Apocalypse Nov 04 '21 at 22:00
  • @Nasser But it doesn't tell exactly why and how to solve. LOL. – Apocalypse Nov 04 '21 at 22:01
  • 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 – Nasser Nov 04 '21 at 22:08
  • @Nasser Yep, but that's not a panacea. Try this one ContourPlot[ Abs[(Exp[I p] - 1) (Exp[I q] - 1)] == 10^-6, {p, -1, 2 Pi}, {q, 0, 2 Pi}]. We set a nonzero value $10^{-6}$ and extend the plotting range of $p$ to $[-1, 2\pi]$, but this time it doesn't even show the $p=0$ vertical line... – Apocalypse Nov 04 '21 at 22:13
  • 3
    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. – John Doty Nov 04 '21 at 22:34
  • I like the problem in this Q, but it seems it would take some algorithm development to solve. That is, I don’t think there’s a built-in way that is robust enough. – Michael E2 Nov 05 '21 at 11:58

1 Answers1

3

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

Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55
  • @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. – Ulrich Neumann Nov 05 '21 at 11:59
  • 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. – Michael E2 Nov 05 '21 at 12:02
  • That’s a good method, thank you! – Apocalypse Nov 05 '21 at 17:41