Message Boards Message Boards

0
|
3052 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

How do I plot a solid bounded below by g(x,y) and above by h(x,y)?

Posted 7 years ago

Hi!

I'm not sure if this is the right place to ask this type of question, but how would I graph a solid bounded below by

g[x_, y_] = 9 - x^2 - 4 y^2

and above by

h[x_, y_] = 25 - 4 x^2 - 16 y^2

where the boundaries are given to be (|x| < 3 , |y| < 3 , 0 < z < 30)?

I'm required to use RegionFunction[] to limit the bounds by their intersection but when I did so, I got an odd looking graph. Here's the relevant part of the code as well as the resulting graph.

g[x_, y_] = 9 - x^2 - 4 y^2;
h[x_, y_] = 25 - 4 x^2 - 16 y^2;
i[x_, y_] = h[x, y] - g[x, y];

p1 = Plot3D[g[x, y], {x, -3, 3}, {y, -3, 3},
   PlotRange -> {0, 30},
   Mesh -> None,
   RegionFunction -> Function[{x, y, z}, g[x, y] < i[x, y] < h[x, y]]];

p2 = Plot3D[h[x, y], {x, -3, 3}, {y, -3, 3},
   PlotRange -> {0, 30},
   Mesh -> None,
   RegionFunction -> Function[{x, y, z}, g[x, y] < i[x, y] < h[x, y]],
   PlotStyle -> {Blue, Opacity[0.5]}];

Show[{p1, p2},
   PlotLabel -> "Ideal Model for a Small Jet of Ionized Particles",
   AxesLabel -> {"x", "y", "z"},
   BoxRatios -> {1, 1, 1},
   ImageSize -> Large]

Overlaid Graphs

POSTED BY: Phil .
2 Replies

Either something like:

g[x_, y_] = 9 - x^2 - 4 y^2
h[x_, y_] = 25 - 4 x^2 - 16 y^2
ContourPlot3D[{z == g[x, y], z == h[x, y]}, {x, -3, 3}, {y, -3, 
  3}, {z, 0, 30}, PlotPoints -> 50, ContourStyle -> Opacity[0.5], RegionFunction -> (g[#1, #2] < h[#1, #2] &)]

or:

g[x_, y_] = 9 - x^2 - 4 y^2
h[x_, y_] = 25 - 4 x^2 - 16 y^2
RegionPlot3D[
 z > g[x, y] \[And] z < h[x, y], {x, -3, 3}, {y, -3, 3}, {z, 0, 30}, 
 PlotPoints -> 50]

But the latter generally does not give nice smooth boundaries where the functions intersect, increasing PlotPoints does help a bit...

POSTED BY: Sander Huisman
Posted 7 years ago

Thank you very much! The first one worked perfectly!

POSTED BY: Phil .
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract