Finding a continuous function to solve the following optimization problem. Suppose you have a compact set $\Omega \subset \mathbb{R}^n$ partitioned as $\Omega = \bigcup_{j=1}^n \Omega_j$ with that $\Omega_i  \cap \Omega_j = \emptyset$ if $i \neq j$. Define for $y_1,\ldots y_n \in \mathbb{R}$
$$
s = \sum_{j=1}^n y_j \chi_{A_j}
$$
(Essentially a simple function on $\Omega$). I was wondering if there's. Suppose also $m$ is the Lebeasgue measure. I wonder if the following problem
$$
E(f) = \frac{1}{2}\int_{\Omega} (f-s)^2dm
$$
Has solution with $f$ continuous. A first attempt I did was to use the Euler Lagrange equations, but this gives me $f = s$ which isn't necessarily continuous. Apart from this attempt I believe I could for example use the Stone-Weirstrass theorem, which would give me a dense subspace in $C(\Omega)$ and maybe look for the solution there. I think however I can still use the Euler Lagrange equations somewhat but maybe I need to better impose the constraint like
$$
\left\{
\begin{array}{l}
\text{minimize} \;E(f) \\
s.t. \;\;f \in C(\Omega)
\end{array}
\right.
$$
But I cannot think of a way (at least amongs the tools I know) that would enable me to solve the problem.
Can anyone suggest something to look up maybe?
 A: You can approximate $s$ arbitrarily by a continuous piecewise linear function. for instance, let the function be $y_j$ on $\Omega_j$ except on an arbitrarily small subset of it so that it can jump linearly into the other $y_j$'s (this is not rigorous but you should be able to make this more precise; this is just an outline). So the infimum of $E$ is $0$. Now suppose there exists a continuous $f$ such that $E(f) = 0$. This would imply $f=s$ almost everywhere. Reorder the $y_j's$ s.t. $y_1\le y_2 \le...\le y_n$. At least two of them are not equal (otherwise s would be continuous). WLOG name them $y_1$ and $y_2$. Then for $\epsilon$ small enough $f^{-1}((y_1+\epsilon,y_2-\epsilon))$ is an open set by continuity of $f$ and hence the integral over this set of $(f-s)^2$ is strictly positive, leading to a contradiction. Note that I assumed $f$ attains the value of $y_1$ and $y_2$ (hence the above open set is nonempty by the intermediate value theorem) since $f$ must equal $s$ almost everywhere and I'm assuming $\Omega_j$'s have positive measure. If they do not I leave it to you to modify the argument.
A: No, there is no one function giving the infimum, but based on Proposition 22, Chapter 3, Section 5 of Royden's: Real Analysis anf Exercice 15, Chapter 4 of this book, we can find for every $\epsilon >0$ (since s(.) is bounded measurable) a continuous function such that :
$\int _{\Omega}\left| f(x)-s(x)\right| dx\,<\,\epsilon$.
Therefore there is a sequence $f_{n}$ of continuous functions such
that $\,\,E(f_{n})\,\to\,0$, BUT there is not ONE continuous function
$f$ achieving the infimum!!
Take as an example $s(x)=0$ on
$[0,1)$ and $s(x)=1$ on $[1,2]$. It is clear that there is NO
continuous function giving $E(f)=0$ but $inf_{f}\,E(f)=0$ !!
