# Issue with ContourPlot of a specific function

I plotted a perturbed quadratic function as follows:

b = 10; ContourPlot[
10 x^2 (1 + 75/100 Cos[70 x]/12) + Cos[(100  x)^2]/24 +
2 y^2 (1 + 75/100 Cos[70 y]/12) + Cos[(100 y)^2]/24 + 4 x y, {x, -b,
b}, {y, -b, b}, Contours -> 50]


Picking $b$, the value range of the plot, different from 10 gives a choppy plot, as expected. However if I pick $b=10$ I get a smooth function - the level curves look exactly like those of a quadratic function, which is not right. How can that be? Is this a bug?

• If you plot the difference between the perturbed and the unperturbed function it is about 3% at most. I suggest you cannot see this small difference in the plot.
– Hugh
Mar 17, 2018 at 15:06
• Thanks, that's what I thought at first. However, the differences are clearly visible if I plot in the range between -9 and 9, or between -11 and 11, or if plotted in Matlab.
– Pait
Mar 17, 2018 at 15:26

This may be an issue with aliasing and the number of points used for determining the plot. Here is one part of your plot examined in detail with lots of PlotPoints and two different ranges.

b = 10; ContourPlot[
10 x^2 (1 + 75/100 Cos[70 x]/12) + Cos[(100 x)^2]/24 +
2 y^2 (1 + 75/100 Cos[70 y]/12) + Cos[(100 y)^2]/24 + 4 x y, {x,
0.9, b}, {y, 0.9, b}, Contours -> 10, PlotPoints -> 200]


b = 9; ContourPlot[
10 x^2 (1 + 75/100 Cos[70 x]/12) + Cos[(100 x)^2]/24 +
2 y^2 (1 + 75/100 Cos[70 y]/12) + Cos[(100 y)^2]/24 + 4 x y, {x,
0.9, b}, {y, 0.9, b}, Contours -> 10, PlotPoints -> 200]


They look similar. Such a complicated contour is going to be difficult to resolve without lots of plot points.

• That must be it. It's strange that the plot works with ranges different from 10, and that even with many PlotPoints the case of range 10 continues to be problematic. Anyway, I have my answer, thanks!
– Pait
Mar 17, 2018 at 16:00

It would appear to be due to the default PlotPoints and/or MaxRecursion resulting in missing the detail. Increasing either or both will result in finer detail and slower plotting.

With[{b = 10},
expr = 10 x^2 (1 + 75/100 Cos[70 x]/12) + Cos[(100 x)^2]/24 +
2 y^2 (1 + 75/100 Cos[70 y]/12) + Cos[(100 y)^2]/24 + 4 x y //
FullSimplify;
Column[
ContourPlot[expr, {x, -b, b}, {y, -b, b},
Contours -> 50,
ImageSize -> Medium, #] & /@
{{PlotPoints ->
Automatic}, {PlotPoints -> 50}, {MaxRecursion -> 5}}]]


• Thanks! Isn't this odd? Anyway, I have my answer.
– Pait
Mar 17, 2018 at 16:02