Optimizing a functional with initial value problem constraint Let $y$ be a smooth function $[0,L] \to \mathbb{R}$. I am interested in finding the values of $\alpha\in[0,2\pi)$ such that the solution of the initial value problem
$$\tag{1}\label{eq1}
\begin{cases}
g(t,y,y')=0,\\
y(0)=\alpha
\end{cases}
$$
is a local extremum of the functional
$$J(y) = \int_{0}^{L}F(t,y)\,dt.$$
I thought I could solve this problem using calculus of variations. As far as I understood (and also looking at this question), if $y$ is both a solution of \eqref{eq1} and an extremum of $J$, then there exists a function $\lambda = \lambda(t)$ such that the following equation holds:
$$
\frac{\partial F}{\partial y} = \lambda \left(\frac{\partial g}{\partial y} - \frac{d}{dt} \frac{\partial g}{\partial y'}\right).
$$
Am I correct?
In particular, in my case the second term inside the parenthesis vanishes, so that I only have
$$\tag{2}\label{eq2}
\frac{\partial F}{\partial y} = \lambda \frac{\partial g}{\partial y}.
$$
Now, I can solve \eqref{eq2} for $y= y(\lambda)$. However, being $\lambda$ a function, substitution of $y(\lambda)$ into \eqref{eq1} gives a new initial value problem (this time in $\lambda$), and so I have not reduced the problem at all.
What am I missing?
 A: The calculus of variation generally solves problems of the form

What arbitrary function $y$ extremizes $I = \int {\cal F}[y](\mathbf{x}) \ {\rm d} \mathbf{x}$, possibly given some constraints on $y$ and fixed boundary values?

You have a problem of the form

What arbitrary boundary value $\alpha$ extremizes $I = \int {\cal F}[y_\alpha](\mathbf{x}) \ {\rm d} \mathbf{x}$, given that $y_\alpha(\mathbf{x})$ is a uniquely fixed function given by $\alpha$ (by a procedure involving $g$)?

Now you could rephrase your problem to involve an arbitrary function $y$ and impose the constraint $g(t,y,y')=0$ using a Lagrange multiplier -- but the constrained calculus of variations is only ever going to tell you that the only possible choice of $y$ is $y_\alpha$, the thing satisfying the $g$ constraint. And then you're still left wondering what $\alpha$ you should choose.
You need to actually have a varying function of $\alpha$ which you extremize at some point. Clearly, $\alpha$ determines $y_\alpha$ (via $g$ constraint) and hence $\alpha$ determines $j(\alpha) := J(y_\alpha)$. You need to vary $\alpha$ in this expression and optimize.
(Note that you may be able to rewrite $J(y_\alpha)$ in a useful way using the equation $y_\alpha$ obeys, in order to extract its $\alpha$ dependence, maybe without ever needing to actually work out $y_\alpha$.)
