6

Thanks to this excellent analysis of the Plot algorithm by Yaroslav Bulatov, I now understand the reason why Plot3D and ContourPlot fail to draw smoothly functions with breaks and discontinuities.

For example, in the following case ContourPlot fails to draw contour x^2 + y^2 = 1 at all:

ContourPlot[Abs[x^2 + y^2 - 1], {x, -1, 1}, {y, -1, 1}, Contours -> {0}]

It is because the algorithm does not go deeply into the region near x^2 + y^2 = 1. It "drops" this region on an initial stage and does not try to investigate it further. Increasing MaxRecursion does nothing in this sense. And even undocumented option Method -> {Refinement -> {ControlValue -> .01 \[Degree]}} does not help (but makes Plot3D a little bit smoother).

The above function is just a simple example. In real life I'm working with very complicated implicit functions that cannot be solved analytically.

Is there a way to get ContourPlot to go deeply into such regions near breaks and discontinuities?

Community
  • 1
  • 1
Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93
  • Well, I got adaptive Plot specifics from Stan Wagon's book, but it doesn't say much about adaptive 3D plotting. Your particular example seems special because the function never crosses 0 value, it just "touches" it, my guess that's the reason ContourPlot can't find it – Yaroslav Bulatov Feb 05 '11 at 19:30
  • Strongly related: "[Problem with ContourPlot](http://mathematica.stackexchange.com/q/23363/280)." – Alexey Popkov Apr 16 '13 at 08:38

1 Answers1

3

These are the standard Plots .

enter image description here

enter image description here

And the Contour at 10^-20

enter image description here

They are pretty clear for me.

Do you expect something more accurate?

Edit

If you want to use the Contours->{0} Option, you may use:

enter image description here

Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • The first `Plot3D` has jaggies on the bottom (I mean the plane `z=0`). That is non-smooth indeed. Thank you for pointing out a way to use `Contours->{.001}`. That is useful but `Mesh->All` is not suitable for my purposes. I need a smooth line without mesh. – Alexey Popkov Feb 05 '11 at 16:44
  • It is the best to combine all of your suggestions with `"ControlValue"`: `ContourPlot[Abs[x^2 + y^2 - 1], {x, -1, 1}, {y, -1, 1}, MaxRecursion -> 6, PlotPoints -> 100, Method -> {"Refinement" -> {"CellDecomposition" -> "Quad", "ControlValue" -> .01}}, Contours -> {.0001}, ContourShading -> False]`. The only bad thing is that it requires a hudge number of evaluations of the objective function. In my case that is extremely slow... – Alexey Popkov Feb 05 '11 at 16:44