Critical points of $f|_S$?

Let $f: U\rightarrow \mathbb R$ be a differentiable function on the open set $U\subset \mathbb R^{n}$ and let $S\subset U$ be a subset (not necessarily closed). Suppose we were to study the extremals of the restriction $f|_S$. Why can't we just look that study the critical points of $f|_S$ studying

$$\nabla (f|_S)(p)=0?$$

I guess it has to do with differentiability issues, but I couldn't find a counter-example and the books don't discuss that.

Thanks.


Solution 1:

You can do that if $S$ is open.

If $S$ is not open, things are more complicated. For instance, assume that $S$ is closed (but it could be neither open nor closed, e.g. take a sphere which is half-open and half-closed), then you can have maxima and minima on the boundary.

If you are working in one dimension, for instance $S=[a, b]$, you can just compute the values of $f$ in $a$ and $b$ and compare with the values of the function at the other stationary points that you found in $(a, b)$.

When you work in higher dimensions or with more complicated sets, though, you cannot get the values of $f$ at the boundary so easily and it is more convenient to use other techniques, like Lagrangian multipliers.