mathematica:: 3d piecwise function problem

i'm trying to plot a function $$\ f(x,y)=cos(\sqrt{x^2 +y^2})$$,same as cos(r).. f(x,y)=0 for points ,which are on circle.when the points are out of this circle i want the function f(x,y) to be 0 as well. so the support of my function to be the circle.i want to plot this situation.. as i thought, my function is $$f(x,y)= \left\{ \begin{array}{c} cos(r) ,r<\pi/2\\ 0,othervise \\ \end{array} \right.$$ but my plot isn't continuous...please help me understand the problem.--> --> That is a feature to indicate that your function is not continuous there. You can use the Exclusions option to prevent it

k[x_, y_] := With[{r = Sqrt[x^2 + y^2]},
Piecewise[{{Cos[r], r < Pi/2}}, 0]
]
Plot3D[k[x, y], {x, -5, 5}, {y, -5, 5}, Exclusions -> None] Edit

If you are wondering why this plot looks a bit bumpy at the bottom, the reason is that there are too few polygons used to create a sharp plot. You can try

Plot3D[k[x, y], {x, -5, 5}, {y, -5, 5}, Exclusions -> None,
PlotPoints -> 100, MaxRecursion -> 6]

and then you clearly see your circle at the bottom • thanks, now i have this plot.but don't understand why isn't support circle? my solution must be my plot just without breaking..and this looks a little , different cause i don't see the circle on the xoy flat – Tamar Beridze Apr 6 '18 at 16:03
• looks exactly what i needed, thank you very much . – Tamar Beridze Apr 6 '18 at 17:16

I think the problem is with $\texttt{Piecewise[]}$. Try this variation instead:

$\texttt{f[x_, y_] := With[{r = Sqrt[x*x + y*y]}, If[r > Pi/2, 0, Cos@r]];}$ $\texttt{Plot3D[f[x, y], {x, -5, 5}, {y, -5, 5}]}$ You can use the option $\texttt{PlotPoints -> 100}$ to make the base sharper, but using $\texttt{Piecewise[]}$ leaves a gap in the plot surface as you noticed.

• thank you for your comment , but still got the same plot :( – Tamar Beridze Apr 6 '18 at 15:20
• thanks for uploading..but as i thought f(x,y) must me nonzero on the circle with radius pi/2..my problem is to see this picture ..but this plot doesn't seem so..am i wrong with constructing the function? – Tamar Beridze Apr 6 '18 at 16:09
• You are wrong as the plot shows. If $r=\pi/2$ then $\cos(r)=0$. – Somos Apr 6 '18 at 16:16
• r=π/2 is the points (x,y) which satisfy the x^2+y^2=(π/2)^2 so they are the circle points....and the cos must be zero on this circle points.. – Tamar Beridze Apr 6 '18 at 16:23