15
$\begingroup$

Bug introduced in 8.0 or earlier and fixed in 11.0.


The line of code

Plot3D[1/y, {x, 0, 1}, {y, x + 1, x + 2}]

is returning several "Power::infy: Infinite expression 1/0. encountered." error messages, and then returning an empty plot. But the function does not diverge on the region to be plotted. Why is this? I am running Mathematica 10.2.0.0 on Mac OS X Yosemite version 10.10.5.

$\endgroup$
  • 5
    $\begingroup$ Can't comment on why it tries to evaluate y at 0, but here's a workaround. Instead of 1/y use Piecewise[{{0, y == 0}, {1/y, True}}]. $\endgroup$ – march Oct 15 '15 at 16:21
  • $\begingroup$ @march That does it! $\endgroup$ – tparker Oct 15 '15 at 16:27
  • 6
    $\begingroup$ I can reproduce, and I strongly suspect this is a bug. Extra weird is that I decided to take a look at it in the debugger; when I ran without the debugger I got three Power::infy messages, followed by a General::stop, and then an empty plot appeared. When I ran with the debugger and had it break on messages, I got two Power::infy messages (one after I told it to keep stepping) and then the plot appears normally. This is truly one for the department of mysterious effects. $\endgroup$ – Pillsy Oct 15 '15 at 16:33
  • 1
    $\begingroup$ Wolfram Technical Support contacted Support case with the identification [CASE:3445899] was created. $\endgroup$ – rhermans Oct 15 '15 at 17:02
  • 4
    $\begingroup$ @march - Your workaround can be shortened to Piecewise[{{0, y == 0}}, 1/y]. $\endgroup$ – Bob Hanlon Oct 15 '15 at 17:13
8
$\begingroup$

The problem is also present in Mma v 9.0.1 to 10.3 in Windows.

Wolfram Technical Support contacted. Support case with the identification [CASE:3445899] was created.

This does not solve the problem, just adds to the diagnostics.

The function get evaluated symbolically and at {0.0000715,0.} before starting to canvas the PlotRange.

f[x_, y_] := Block[{},
  If[
   Not[NumberQ[x]]
    || Not[NumberQ[y]]
    || Not[0 <= x <= 1]
    || Not[1 < y < 3]
   , Print[{x, y}]
   ];
  x]

Plot3D[f[x, y], {x, 0, 1}, {y, x + 1, x + 2}]

Mathematica graphics

but

Mathematica graphics

$\endgroup$
  • 3
    $\begingroup$ Not just there ... Reap@Plot3D[(Sow[{x, y}]; 1/y), {x, 0, 1}, {y, x + 1, x + 2}] $\endgroup$ – Dr. belisarius Oct 15 '15 at 16:53
  • $\begingroup$ Ahh.. so elegant... $\endgroup$ – rhermans Oct 15 '15 at 16:54
11
$\begingroup$

The best approach for plotting over non-rectagular domains is to use the regions form of Plot3D:

 Plot3D[1/y, Element[{x,y}, Parallelogram[{0,1},{{1,1},{0,1}}]]]

enter image description here

$\endgroup$
  • $\begingroup$ Can also be written as Plot3D[1/y, Element[{x, y}, ImplicitRegion[0 <= x <= 1 && x + 1 <= y <= x + 2, {x, y}]]] $\endgroup$ – Bob Hanlon Oct 15 '15 at 20:19
  • $\begingroup$ Right. There are a number of forms you could use for this particular region. More importantly, there are lots of regions that can't be cast into the traditional {var, min, max} form, but that can be cast as some form of region. $\endgroup$ – Brett Champion Oct 15 '15 at 21:04
1
$\begingroup$

Wolfram said "The syntax for Plot3D that you are using is undocumented (even though similar syntax for functions like Table or NIntegrate is documented), and is thus not yet expected to work consistently."

$\endgroup$

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.