This part is just my context of the problem, you can safely ignore it if you are not interested.

Why do I want to plot the contour of Abs[f[x,y]]==0 or f[x,y]*Conjugate[f[x,y]]==0 if they are the same of f[x,y]==0?

Because it would help a lot when f[x,y] is a complex function(x and y are real variables but f[x,y] maybe complex). For any function f[x,y], it can be written in the form r[x,y]*Exp[I θ[x,y]] where r[x,y] and θ[x,y] are real function. So for f[x,y]==0 what we really means is r[x,y]==0, and instead of contour plotting f[x,y]==0 I should put r[x,y]==0. However, sometimes it would be difficult to get r[x,y] given the function f[x,y], but fortunately we can just plot the contour of f[x,y]*Conjugate[f[x,y]]==0 or Abs[f[x,y]]==0 since which is mathematically equivalent to r[x,y]==0.

I know it can be separate into the form r[k,K0]*Exp[I θ[k,K0]], but it's difficult to find what r and θ is. Since I want to plot the contour of r[k,K0]==0, instead I can plot the contour of Abs[f[k,K0]]==0, but I encountered the same problem as the simple example above.

ContourPlot[Abs[f[k, K0]] == 0, {K0, -2 π/a0, 2 π/a0}, {k, 0, 4}]

However if we plot the real and imaginary part, we can get the correct contour(the diamond shape) but also introduced other artificial contours(horizontal lines) come from Cos[θ[x,y]]==0 or Sin[θ[x,y]]==0.

1 Answer
1

The reason for the difficulties that ContourPlot is having can be attributed to the fact that you are looking for a contour right at the boundary of the function's range, i.e., $0$ for a function whose range is $f(x,y)\ge 0$. Since there is no loss of visual accuracy in moving this contour slightly into the allowed range of values, I would do it this way:

ContourPlot[f[x, y]*f[x, y] == 0.000001, {x, 0, 4 Pi}, {y, 0, 4 Pi}]

and similarly for the other examples.

Edit

Unfortunately, this still doesn't work when the maximal function values vary steeply across the plot region, as is the case in the example

if we plot the Abs. Then the absolute contour value of, say, 0.01 is perhaps OK in part of the plot where the function itself varies only between 0 and 1, but it won't be large enough relative to the typical function values in regions where the maxima reach values of 100 or more.

In this case one could try to replace the constant contour value (0.01) by something that varies in the direction in which the range increases most rapidly. However, I don't have any good way of doing this in an automated way, so it would require manual tuning.

So here is a manual approach where I slice the contour plot into 9 different regions where the contours can then be identified in a hopefully more accurate way because the function doesn't vary too rapidly in each slice:

I'm thinking that if the bad behave part is the steeply change of the maximals, we may re-scale the function in the second example to make the maximals well behave, and than use the the same trick f[x, y]*f[x, y] == 0.000001 as you did in the first example.
–
xslittlegrassSep 20 '13 at 17:50

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.