1
$\begingroup$

Could anybody tell me how to plot $z= 5-\sqrt{x^2+y^2}, 0 \le z \le 5$ in mathematica?

I haven't done much on multivariable yet, but I am inquisitive to know how to plot this cone on mathematica?

  • 0
    @MaX you don't seem to be in the list. You might not have confirmed your email address. Please do this. The confirmation email might be caught in your spam-catcher.2012-01-13

3 Answers 3

4

To restrict the plot to $0 \le z \le 5$, you can use the option RegionFunction, like so:

Plot3D[5 - Sqrt[x^2 + y^2], {x, -5, 5}, {y, -5, 5},   RegionFunction -> Function[{x, y, z}, 0 < z < 5]] 

Mathematica graphics

An essential difference between RegionFunction and PlotRange:

  • when using RegionFunction, all points generated outside the region are discarded before building the 3D object to show, and the boundary of the region is computed and plotted nicely.

  • when using PlotRange, all points are included in the 3D object, but it is clipped to a box determined by the plot range while rendering.

You can only restrict what's being show to a box using PlotRange while RegionFunction lets you specify a region of any shape. Please also see my two answers here.


You may also want to use a custom mesh, to make it prettier. Here's how to do it without leaving Cartesian coordinates:

Plot3D[5 - Sqrt[x^2 + y^2], {x, -5, 5}, {y, -5, 5},   RegionFunction -> Function[{x, y, z}, 0 < z < 5],   MeshFunctions -> Function[{x, y, z}, z]] 

Mathematica graphics

MeshFunctions -> {Function[{x, y, z}, z],                    Function[{x, y, z}, ArcTan[x, y]]} 

Mathematica graphics

  • 0
    @Mr.W I tried to make them pretty and anti-aliased but I ran into [the problem of ticks not scaling properly](http://stackoverflow.com/questions/8805451/tick-marks-dont-scale-in-graphics-why-and-how-to-fi$x$-this).2012-01-17
5

RegionPlot3D can be useful for this.

RegionPlot3D[  z - (5 - Sqrt[x^2 + y^2]),  {x, -5, 5}, {y, -5, 5}, {z, 0, 5},   PlotPoints -> 50 ] 

Mathematica graphics

4
Plot3D[5-Sqrt[x^2+y^2],{x,-5,5},{y,-5,5},PlotRange->{0,5}]