1
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Hugh Mar 17 '18 at 15:06
  • $\begingroup$ 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. $\endgroup$ – Pait Mar 17 '18 at 15:26
2
$\begingroup$

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]

Mathematica graphics

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]

Mathematica graphics

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

$\endgroup$
  • $\begingroup$ 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! $\endgroup$ – Pait Mar 17 '18 at 16:00
1
$\begingroup$

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}}]]

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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