[Math] Finding a function with an infinite number of minima/maxima over a bounded domain

calculusmultivariable-calculusreal-analysis

I am studying multivariable calculus and I noticed that whenever we want a function with an infinite number of maxima or minima, we usually pick periodic functions. There are examples of non-periodic ones, for example $$f(x,y)=x^2+4y^2-4xy+2$$
(picked up from this post).

I was wondering, can we find an example of such a function, with domain of definition being a bounded set, a ball for example, with an infinite number of local/global minima/maxima (of course, not periodical)? Or is this something not permitted due to the compactness of the closure of the ball? Is there any difference between one variable and many variables?

I am mainly interested in what happens when talking about non-constant functions of class $C^1$. Thanks in advance.

EDIT: The answer was easy and provided by $f$ above and in the comments. I had strict minima/maxima in mind, so the question is now about strict points:

Can I can always find a $C^1$ non-constant function defined on a ball, with an infinite number of strict maxima – for example – that is points inside the ball at which the maximum is attained and all the other points in the ball have strictly smaller values?

Best Answer

Let $D$ be the open ball and $A\subset D$ be any non-empty, relatively closed subset.

Then $r(x):=\frac12\operatorname{dist}(x,A\cup\partial D)$ is continuous and $$ f(x)=\begin{cases}\left(\int_{B(r(x),x)}r(x)\,\mathrm dx\right)^2&r(x)>0\\0&r(x)=0\end{cases}$$ is $C^1(D)$ with local (and at the same time global) minima precisely at the points $\in A$. In order to have strict minima, just make sure that $A$ is discrete.