A subset $U$ of a complete metric space such that all continuous functions on $U$ attain a minimum must be closed I was working on the following problem:

Suppose we have a complete metric space $(X,d)$. Show that if every continuous function on a subset $U \subset X$ attains a minimum, then $U$ is closed.

If we suppose that $U$ is not closed, then there is a limit point of $U$, which we call $x$, that is not contained in $U$. Since $x$ is a limit point of $U$, there is a sequence $\langle x_{n} : x_{n} \in U \rangle$ where $x_{n} \rightarrow x$. I am trying to construct a function on $U$ which does not attain a minimum using the above sequence. At this point I consider myself stuck.
 A: If your function is real-valued, suppose you have a subset that does not have one of its limit points, say $y$. Then define $f(x) = d(x,y)$. The infimum value is zero but it cannot be obtained within the subset or else the limit point $y$ would be in your subset. So there is no minimum value of $f$ obtained on your subset.
A: We show that $U^C$ is open. Let $v$ be in $U^C$ and consider the function $g: U \rightarrow \mathbb{R}$ given by $$g(u) = d(u,v).$$ By hypothesis, this function must be obtain its minimum. Its minimum must be positive. If the minimum value of $g$ were $0$, then there must be some $u \in U$ so that $$0=g(u)=d(u,v).$$ Since $d$ is a metric, that would imply that $u=v$, so $v \in U$. But that's not good because $v \in U^C$. So its minimum value must be greater than $0$. Say its minimum is $m$. Then $v \in B_{m}(v) \subseteq U^C$, (since $m$ was the minimum of all distances from $v$ to things in $U$) so $U^C$ must be open, and $U$ must be closed.
A: Maybe by contraposition, consider $U:=(0,1)$, and $f(x)=x$. $U$ is not closed, and the continuous function $f$ takes neither a maximum nor a minimum. If you want a min. but not a max., or viceversa, use $V:=[0,1)$ or $W:=(0,1]$. 
A: If $U$ is not closed it has an an accumulation point $a$ outside of $U$, the continuous function $f(x)=d(a,x)$ does not attain a minimum. So $U$ must be closed for all continuous functions to reach a minimum.
