# How to plot $z= 5-\sqrt{x^2+y^2}, 0 \le z \le 5$ in mathematica?

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?

-
i would use cylindrical coords $z=5-r, 0\leq r\leq5, 0\leq\theta\leq2\pi$ after looking up how to plot something like this in the mathematica "help" – yoyo Dec 21 '11 at 16:10
You might be interested in the proposal for a Mathematica-specific StackExchange site. We are quite close to getting into beta, so please consider committing soon! – Verbeia Jan 12 '12 at 1:53
@Verbeia:I have committed, hope we go to beta phase soon :-) – Quixotic Jan 12 '12 at 14:57

Plot3D[5-Sqrt[x^2+y^2],{x,-5,5},{y,-5,5},PlotRange->{0,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
]


-

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]]


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]]


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


-
Looks pretty. +1 – Mr.Wizard Jan 17 '12 at 14:41
@Mr.W I tried to make them pretty and anti-aliased but I ran into the problem of ticks not scaling properly. – Szabolcs Jan 17 '12 at 15:47