Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm wondering how to display the support $\mathrm{supp}(f)$ of a piecewise surface $z = f(x,y)$.

As an example, let's consider the following piecewise function (and plot it):

f[x_, y_] = Piecewise[{{1, 0 <= x <= 1 && 0 <= y <= 1}}];
g[x_, y_] = Integrate[f[x - t, y - t], {t, 0, 1}];
Plot3D[g[x, y], {x, -0.5, 2.5}, {y, -0.5, 2.5}, PlotRange -> Full]

enter image description here

My first thought was to use a contour plot for this purpose, such as

ContourPlot[g[x, y] == .05, {x, -0.5, 2.5}, {y, -0.5, 2.5}]

enter image description here

But this is of course only an approximation of the support. How do I display the actual support of my piecewise function?

Edit

The proposed solution in the comments below works great, the result looks as follows:

enter image description here

share|improve this question
2  
Something like RegionPlot[Or @@ Most[First[Internal`FromPiecewise[g[x, y]]]] // Evaluate, {x, -0.5, 2.5}, {y, -0.5, 2.5}]? –  J. M. Jun 19 '13 at 9:59
2  
RegionPlot[ g[x, y] > 0, {x, -0.5, 2.5}, {y, -0.5, 2.5}] –  Artes Jun 19 '13 at 10:00
    
Thanks! Didn't know about this option, it works great. –  Ailurus Jun 19 '13 at 10:06
add comment

2 Answers

up vote 9 down vote accepted

The most direct way uses RegionPlot e.g.

RegionPlot[ g[x, y] > 0, {x, -0.5, 2.5}, {y, -0.5, 2.5}]

let's customize it a bit using colors from many possible ColorData["Gradients"]:

GraphicsRow[ 
    RegionPlot[ g[x, y] > 0, {x, -0.5, 2.5}, {y, -0.5, 2.5}, 
                ColorFunction -> Function[{x, y}, ColorData[#][Abs[g[x, y]]]], 
                ColorFunctionScaling -> False, PlotPoints -> 100, MaxRecursion -> 5]& /@
    {"BlueGreenYellow", "DarkBands"} ]

enter image description here

One can also get the plot with ContourPlot, e.g. using the RegionFunction option:

ContourPlot[ g[x, y], {x, -0.5, 2.5}, {y, -0.5, 2.5}, 
             RegionFunction -> Function[{x, y}, g[x, y] > 0], Exclusions -> None] 

enter image description here

At last, we can make Plot3D better fitting to our needs:

Plot3D[ g[x, y], {x, -0.5, 2.5}, {y, -0.5, 2.5}, MeshFunctions -> {#3 &}, 
        PlotRange -> All, RegionFunction -> Function[{x, y}, g[x, y] > 0], 
        ColorFunction -> Function[{x, y}, ColorData["BlueGreenYellow"][g[x, y]]], 
        ColorFunctionScaling -> False, BoxRatios -> {2, 2, 1}, PlotPoints -> 80, 
        MaxRecursion -> 4, Exclusions -> None]

enter image description here

share|improve this answer
add comment

Here's another quick way to visualize the support region:

RegionPlot[Or @@ g[x, y][[1, All, 2]] // Evaluate, {x, -0.5, 2.5}, {y, -0.5, 2.5}]

support region for a piecewise function.

In some cases, one might want to run Reduce[] on the pile of constraints produced by Or @@ g[x, y][[1, All, 2]], before plotting, to reduce evaluation effort. (In this case, it did not do much, but it's a good idea in general.)

If one is not afraid of undocumented functions, here is another method:

RegionPlot[Or @@ Most[First[Internal`FromPiecewise[g[x, y]]]] // Evaluate,
           {x, -0.5, 2.5}, {y, -0.5, 2.5}]
share|improve this answer
1  
+1 for FromPiecewise –  Mr.Wizard Jun 19 '13 at 13:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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