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

2026-03-25 13:51:58.1774446718
On
mathematica:: 3d piecwise function problem
75 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
4
On
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.

That is a feature to indicate that your function is not continuous there. You can use the
Exclusionsoption to prevent itEdit
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
and then you clearly see your circle at the bottom