My intuition tells me that the following proposition is true:
Let $f: \Omega \rightarrow \mathbb{R}$ be a measurable function on a measurable set $\Omega \subseteq \mathbb{R}^n$. If $f$ is continuous and non negative then $\mathrm{ess\, sup}(f)=\text{sup}(f)$.
I'm using here the Borel sigma algebras on $\Omega$ and $\mathbb{R}$ respectively, and the Lebesgue measure $m$ on $\Omega$.
My measure theory background is very poor, that being said I tried to give a proof for the case where $\Omega$ is compact:
Let $A=\{a: m(\{ f\geq a \})=0 \}$. Therefore $\mathrm{ess\, sup}(f)= \inf A = E$. Let also $M=\max f = \sup f$ (it exists because $f$ is continuous on a compact set). I will prove $E \geq M$, and $E \leq M$ (otherwise there would be a contradiction on the defition of $\inf A$).
- $E \leq M$: if $a>M$ then $\{ f\geq a \}=\emptyset$, so $m(\{ f\geq a \})=0$, so $a \in A$. Therefore $E=\inf A \leq M$
- $E \geq M$: let $a \in A$, and suppose there's $x$ such that $f(x)>a$. By continuity of $f$ there also an open neighbourood $U(x)$ such that for every $y\in U(x)$ $f(y)>a$. Therefore $m(\{ f>a\})>0$ and this is impossible, since $m(\{ f\geq a \})=0$ (because $a \in A$), $\Omega$ has finite measure since it is (closed and) bounded and $\{ f<a \} $ and $\{ f > a \}$ are disjoint.
Provided the above reasoning holds I would like to extend from here the conclusion to a generic measurable $\Omega$: anybody could give me a hint in this direction? (or show me why the general proposition is wrong?)
Thanks!
Edit
Thanks to everybody for the help. Maybe it could be more interesting to require $\Omega$ non empty and connected.
For a counterexample to this proposition, take $\Omega = [0,1] \cup \{2\}$ in $\mathbb{R}$ with $f: \Omega \to \mathbb{R}$ given by $f(x) = x$. This function is continuous.
Then $\sup f = 2$, whereas $\mathrm{ess\,sup} f = 1$, since $\{f \ge 1\} = \{1,2\}$ and $\lambda(\{1,2\}) = 0$ where $\lambda$ is Lebesgue measure.
Additional condition to make it true: Let's additionally assume that
Then, in this case your proposition is true. For the proof, we already know $\mathrm{ess\,sup} f \le \sup f$, so we need to show $\mathrm{ess\,sup} f \ge \sup f$. Equivalently, fix any $a < \sup f$; we want to show that $\lambda(\{f \ge a\}) > 0$. Since $a < \sup f$, there exists $x_0$ such that $f(x_0) > a$. Since $f$ is continuous, there exists an open ball $B$ containing $x_0$ such that for $x \in B \cap \Omega$, $f(x) > a$. By our assumption (1) above, $\lambda(B \cap \Omega) > 0$. So $\lambda(\{f \ge a\}) > 0$.
Therefore, $\mathrm{ess\,sup} f = \sup f$.