Converting ODE to Variational Problem (for numerical solution) This might be a stupid question, but I cannot find the answer anywhere and as an engineer I don't have the mathematical foundation to investigate this properly myself. So,
If I have a simple ODE, say for example a harmonic oscillator like $u''+u=0$, I know that I can try to convert it into a variational problem by finding a Lagrange function $F$, so that if I plug it into to the Euler-Lagrange differential equation $$\frac{\partial F}{\partial u}-\frac{\mathrm{d}}{\mathrm{d}x}\frac{\partial F}{\partial u'}+\frac{\mathrm{d^{2}}}{\mathrm{d}x^{2}}\frac{\partial F}{\partial u''}=0$$ I get my ODE back. In this case one easily finds that e.g. $$F=\left(u'\right)^2-u^2$$ fulfills this condition. However now I considered the naive idea of simply just taking the following integral $$\int_{x_{1}}^{x_{2}}(u''+u)^{2}\mathrm{d}x\rightarrow\text{min.}$$ So basically to take $F:=(\text{some ODE})^2$. Naively this seems to me like in its minimum the ODE is satisfied. To test this, I implemented a numerical solver that takes a polynomial ansatz and solves the coefficients to find an approximation of the solution (here a sine) of the ODE between $0$ and $\pi/2$. And it seems to actually work but the solution isn't exactly the same as for $F=\left(u'\right)^2-u^2$ - it is a little bit less accurate (so clearly not the optimal solution yielded by the ansatz)! However, if I take piece-wise linear functions, this native functional completely fails to provide an approximate solution, while $F=\left(u'\right)^2-u^2$ works perfectly. To investigate a little further I plugged in $F=(u''+u)^{2}$ into the Euler-Lagrange eq. and realize that I get $$2(u''+u)+2\left(u''+u\right)''=0$$ which seems to satisfy the same solution as my original problem. So my two questions that arise from all this:
1) Why is it that the naive idea of doing $F=(\text{some ODE})^2$ seems to be working somewhat but not always, if I want to numerically solve an ODE via variational method?
2) Consequently: If I have an ODE of the form $f(u, u', u'', ..., x)=0$, all ODEs of the form $f(u, u', u'', ..., x) + \left(f(u, u', u'', ..., x)\right)' + \left(f(u, u', u'', ..., x)\right)'' + ... =0$ seem to have the same solution as the original ODE, but they are in fact of higher order. What is the significance of these ODEs and their solutions?
Apologies of the lengthy post but I would really appreciate any input on this. As I said, I am an engineer and quite out of my depth here. Thank you in advance!
 A: Here are some comments from a theoretical (as opposed to numerical) point of view:


*

*On one hand, the variational problem for the 1st-order Lagrangian $$F~=~\frac{1}{2}(u^{\prime})^2-\frac{1}{2}u^2 \tag{1}$$
needs 2 boundary conditions (BCs) (which OP hasn't specified) in order to deduce the Euler-Lagrange (EL) equation
$$u^{\prime\prime}+u~\equiv~(D^2+1)u~=~0 ,\tag{2}$$ 
which is a 2nd-order ODE. 

*On the other hand, the variational problem for the 2nd-order Lagrangian $$F~=~\frac{1}{2}(u^{\prime\prime}+u)^2 ~\geq~ 0\tag{3}$$
needs 4 BCs (which OP hasn't specified) in order to deduce the EL equation
$$(D^2+1)^2u~=~0 ,\tag{4}$$ which is a 4th-order ODE. 

*On one hand, the variational problem (1) does not make sense without BCs, because we e.g. can pick a constant function $u(x)={\rm const}$ to make $F$ as negative as we would like. There is no infimum.

*On the other hand, the variational problem (3) does make sense without BCs because $F\geq 0$ is manifestly non-negative. The minimum is obviously given by solutions to eq. (2).

*Clearly a solution to the ODE (2) is also a solution to the ODE (4), but not vice-versa.
