0
$\begingroup$

I try to plot the following inequalities f[x,y,z]<=1 and g[x,y,z]<=1 in a single plot such that both the regions are visible and also the intersection is highlighted. I tried the RegionPlot3D but it only shows the region which is common to them.

f[x_, y_, z_] = x + y + z;
g[x_, y_, z_] = x^2 + y^2 + z^2;

RegionPlot3D[f[x, y, z] <= 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]
RegionPlot3D[g[x, y, z] <= 1, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}]
$\endgroup$
1
  • $\begingroup$ One of those regions is completely within the other, tho; is something like RegionPlot3D[{x + y + z <= 1, x^2 + y^2 + z^2 <= 1}, {x, 0, 1}, {y, 0, 1}, {z, 0, 1}, PlotStyle -> Opacity[1/3]] what you had in mind? $\endgroup$ Commented Jul 27, 2022 at 17:21

1 Answer 1

1
$\begingroup$
Clear["Global`*"]

f[x_, y_, z_] = x + y + z;
g[x_, y_, z_] = x^2 + y^2 + z^2;

Since the region f[x, y, z] <= 1 is completely contained in the region g[x, y, z] <= 1, the intersection is just the smaller region. You cannot distinguish the smaller region from the intersection.

RegionPlot3D[{f[x, y, z] <= 1, g[x, y, z] <= 1, 
  f[x, y, z] <= 1 && g[x, y, z] <= 1}, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
 PlotStyle -> {Opacity[0.5], Opacity[0.5], Automatic},
 PlotLegends -> "Expressions"]

enter image description here

However, if the neither region is completely contained by the other

RegionPlot3D[{f[x, y, z] <= 1, g[x, y, z] <= 1/2, 
  f[x, y, z] <= 1 && g[x, y, z] <= 1/2}, {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
 PlotStyle -> {Opacity[0.5], Opacity[0.5], Automatic},
 PlotLegends -> "Expressions"]

enter image description here

$\endgroup$
6
  • $\begingroup$ Thanks Bob, it worked fine when I copied it first time, but now it is showing "{x+y+z<=1,x^2+y^2+z^2<=1,x+y+z<=1&&x^2+y^2+z^2<=1} must be a Boolean \ function"......don't really understand what's wrong here! $\endgroup$
    – seeker
    Commented Jul 27, 2022 at 19:51
  • $\begingroup$ Quit Mathematica and restart it. Copy, paste, and evaluate the code above. $\endgroup$
    – Bob Hanlon
    Commented Jul 27, 2022 at 19:55
  • $\begingroup$ Still showing the same message :-( $\endgroup$
    – seeker
    Commented Jul 27, 2022 at 20:09
  • $\begingroup$ What Mathematica version are you using? $\endgroup$
    – Bob Hanlon
    Commented Jul 27, 2022 at 20:10
  • $\begingroup$ 11.3, on Win 10 $\endgroup$
    – seeker
    Commented Jul 27, 2022 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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