# Variational form of 2nd order linear ODE

I have been having issues getting the variational form of the following differential equation.

$$\frac{d^2u}{dx^2} - u = -1$$

I looked to multiply by $$u$$ and integrate over the length for the variational form (as for weak form, except where the variation $$w$$ isn't arbitrary). However, the correct solution is:

$$\int \frac{1}{2} \left( \frac{d^2u}{dx^2}+u^2 \right) -u dx$$

I can't seem to find how to get to this solution. Any advice would be appreciated.

• Multiply bei $u'$ and integrate. Commented Apr 7, 2022 at 13:43

Let $$\varphi \in C_c^{\infty}(\Omega)$$. Multiplying the equation by $$\varphi\frac{d}{dx}u$$ and integrating over space gives $$\int\frac{d^2}{dx^2}u \frac{d}{dx}u\varphi-u\frac{d}{dx}u\varphi = - \frac{d}{dx}u\varphi.$$ Note that $$\frac{d^2}{dx^2}u\frac{d}{dx}u=\frac{1}{2}\frac{d}{dx}\left(\frac{d}{dx}u\right)^2$$ and $$u\frac{d}{dx}u=\frac{1}{2}\frac{d}{dx}u^2$$. By integrating by parts it follows $$\int-\frac{1}{2}\frac{d}{dx}u \frac{d}{dx}\varphi-\frac{1}{2}u^2\frac{d}{dx}\varphi dx=\int u \frac{d}{dx} \varphi dx.$$ Hence $$\int\frac{d}{dx}\varphi\left(\frac{1}{2}\frac{d}{dx}u+\frac{1}{2}u^2+u\right)dx=0$$ for any $$\varphi \in C_c^{\infty}(\Omega)$$ and hence this is the variational form. Note that I just did formal computations, but everything can be rigorous by using the fundamental lemma of calculus of variations.