What is the best way to handle this situation?

f[x_, y_] = Exp[1/(x – y)];

Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5},

MeshFunctions -> {#3 &},

AxesLabel -> Automatic]

=================

3

You can keep the original definition of the function and just add Exclusions -> x == y to the plot.

– Rahul

Oct 5 ’15 at 3:11

@m_goldberg: Seems to clean up the graph just fine: i.stack.imgur.com/hug0F.png

– Rahul

Oct 5 ’15 at 3:32

@Rahul Excellent! Thanks for the great help. 🙂

– David

Oct 5 ’15 at 3:49

=================

1 Answer

1

=================

I am presuming you want to eliminate the singularity. Perhaps this will work for you.

Clear[f]

f[x_, y_] /; Abs[x – y] > .05 := Exp[1/(x – y)]

Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5},

ClippingStyle -> None,

MeshFunctions -> {#3 &},

AxesLabel -> Automatic]

Instead of .05, which I chose arbitrarily, you may find a smaller value more to your liking.

You could also do what Rahul suggested in a comment, but you will need to use Quiet to suppress the error messages.

Quiet @

Plot3D[Exp[1/(x – y)], {x, -5, 5}, {y, -5, 5},

Exclusions -> x == y,

ClippingStyle -> None,

MeshFunctions -> {#3 &},

AxesLabel -> Automatic]

This gives the a plot that is indistinguishable form the one shown above.

My helper is back! Thanks. However, I do not understand the function notation. Can you help me with what f[x_, y_] /; Abs[x – y] > .05 := Exp[1/(x – y)] does?

– David

Oct 5 ’15 at 3:07

1

@David. /; is the operator form of the functionCondition, which you should study. You will find very useful. In this case it makes f undefined in the region of the singularity, so Plot3D doesn’t try to plot there.

– m_goldberg

Oct 5 ’15 at 3:21

1

@David. I can make nothing of your “Ouch” comment. There is nothing in my answer that can destroy anything you have in your notebook. Clear[f] could delete previous definitions of f from your working kernel, which is what it should do, since they might interfere with the new definition. But it can’t destroy anything in the notebook itself.

– m_goldberg

Oct 5 ’15 at 3:25

My bad. I just have two functions f in the global workspace now.

– David

Oct 5 ’15 at 3:43

Two absolutely wonderful explanations. Thanks to both of you.

– David

Oct 5 ’15 at 3:49