Calculus of variation with inequality constraints Find the function $y$ which maximizes the functional $$J[y] = \int_0^1 g(x) y(x) dx$$ subject to $0 \leq y(x) \leq 1$ for all $x\in [0,1]$ and $$\int_0^1 y(x) dx = k$$ where $g$ is a strictly increasing function.

I know that I can take care of the isoperimetric constraint quite easily using the Lagrangian
$$K[y] = \int_0^1 (g(x) y(x) + \lambda y(x)) dx$$
I also know that I can take care of constraints of the form $y(x) \leq 1$ using a substitution such as $u^2(x) = 1 - y(x)\geq 0$ to get
$$K[u] = \int_0^1 \left( g(x) \left( 1 - u^2(x) \right) + \lambda \left( 1 - u^2(x) \right) \right) dx$$
However, I am quite at a loss with a constraint of the form $0 \leq y(x) \leq 1$, i.e., when two inequalities are involved at the same time. How can I take care of this?
 A: Suppose that on two infinitesimal intervals $A = [a, a+dx]$ and $B = [b, b+dx]$, we have $a < b$, $y > \epsilon$ on $A$ and $y< 1 - \epsilon$ on $B$. Let $C = [0,1] - A - B$. Since $g$ is strictly increasing, $\int_A g(x) \, dx \le
\int_B g(x) \, dx$. Define $$y_1(x) =\begin{cases} y(x) - \epsilon & x\in A\\y(x) + \epsilon & x\in B\\y(x) & x\in C\end{cases}$$
Then, $$\begin{align}\int_0^1 g(x)y_1(x) \, dx &= \int_A g(x)y_1(x) \, dx + \int_B g(x)y_1(x) \, dx +\int_C g(x)y_1(x) \, dx\\
&= \int_A g(x)(y(x)-\epsilon) \, dx + \int_B g(x)(y(x)+\epsilon) \, dx +\int_C g(x)y(x) \, dx\\
&= \int_0^1 g(x)y(x) \, dx + \epsilon\left(\int_B g(x) \, dx - \int_Ag(x) \, dx\right)\\
& \ge \int_0^1 g(x)y(x) \, dx\end{align}$$
Thus, raising the value of $y$ for higher values of $x$ at the expense of the value of $y$ for lower values of $x$ increases $J$. Taking this to the extreme while still satisfying $0 \le y \le 1$ and $\int_0^1 y \, dx = k$ gives
$$y(x)=\begin{cases} 0 & x < 1-k\\1&x \ge 1 - k\end{cases}.$$
A: I think its better to write your constraint in this form:
$0 \leq y(x) \leq 1 \implies -\frac{1}{2} \leq y(x)-\frac{1}{2} \leq \frac{1}{2} \implies \left( y(x)-\frac{1}{2} \right)^2 \leq \frac{1}{4} \implies  y(x)^2-y(x)<0$. Now you can use your knowledge to solve the problem.
Good luck.
