# Show that $\nabla f(x) = 0$ doesn't imply $f$ is constant if $U$ is not path connected

Let $$U$$ be an open subset of $$\mathbb{R}^n$$. Let $$f: U \to \mathbb{R}$$ be differentiable with $$\nabla f(x) = 0$$ for all $$x \in U$$.

I have already shown that if $$U$$ is path-connected then $$f$$ is constant.

In the next task I have to show, that this statement is wront, if $$U$$ is not path-connected. I assume that I need a counterexample here with a $$f$$ is above where $$U$$ is not path-connected and $$f$$ is not constant, but I am struggling to understand which function should have $$\nabla f(x)=0$$ and not be constant.

I would really appreciate some help.

• I was going to suggest that you start by thinking about $n=1$. Dec 15, 2019 at 19:39

Take $$f(x,y)=1$$ if $$(x,y) \in B((0,0),1)$$
and $$f(x,y)=0$$ if $$(x,y) \in B((3,0),1)$$
So $$U=B((0,0),1) \cup B((3,0),1)$$
Take$$\begin{array}{rccc}f\colon&\mathbb R\setminus\{0\}&\longrightarrow&\mathbb R\\&x&\mapsto&\begin{cases}1&\text{ if }x>0\\0&\text{ if }x<0.\end{cases}\end{array}$$