Existence of a continuous function with zeros in a closed set

196 Views Asked by At

If $E \subset \mathbb{R}$ is a closed subset show that there is a continuous real-valued function on $\mathbb{R}$ such that $f(x) = 0$ if and only if $x \in E$.

I've considered trying to show that the preimage of any open or closed set in $\mathbb{R}$ must be open or closed, but this didn't seem to get me anywhere.

1

There are 1 best solutions below

7
On

$f(x) = \min[\text{dist}(x,E),1]$, where $\text{dist}(x,E)=\inf\{|x-y|:y\in E\}$

Based on comments, we could also more simply use

$g(x) =\inf\{|x-y|:y\in E\}$