Deriving time-dependent Euler-Lagrange equation Given a time dependent function $b(x,t):\mathbb{R}^n \times [0;+\infty)$. Derive the Euler-Lagrange equation from the energy function:
$$S = \int_0^T\left(\ddot{x} - b(x,t)\right)^2dt\tag{1}$$
Note that $$ is an $n$-dimensional vector.
My solution is the equation:
$$x^{(4)} - \left( \frac{\partial b}{\partial x} + \frac{\partial b^T}{\partial x} \right)x'' - \frac{\partial^2 b}{\partial x^2}(x')^2 - 2\frac{\partial b^2}{\partial x \partial t} x' + \frac{\partial b^T b}{\partial x} - \frac{\partial b^2}{\partial t^2} = 0.\tag{2}$$
But I would like to check and see the full reasoning from other people to  see if I am on the right track. 
 A: I'll be a bit more general: Let $L(t, q, \dot{q},\ddot{q}$) the lagrange function and let the action be
$$S[q]=\int L(t,q,\dot{q},\ddot{q}) \mathrm{d}t$$
And the first variation will be
\begin{align}
\delta S
&=S[q+\delta q]-S[q]\\
&= \int \frac{\partial L}{\partial q_i} \delta q_i+\frac{\partial L}{\partial \dot{q}_i} \delta \dot{q}_i+\frac{\partial L}{\partial \ddot{q}_i}\delta \ddot{q}_i \mathrm{d}t \\
&= \int \frac{\partial L}{\partial q_i}\delta q_i -\frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial L}{\partial \dot{q}_i} \delta q_i - \frac{\mathrm{d}}{\mathrm{d}t} \frac{\partial L}{\partial \ddot{q}_i} \delta \dot{q}_i \mathrm{d}t\\
&= \int \frac{\partial L}{\partial q_i}\delta q_i -\frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial L}{\partial \dot{q}_i} \delta q_i + \frac{\mathrm{d}^2}{\mathrm{d}t^2} \frac{\partial L}{\partial \ddot{q}_i} \delta q_i \mathrm{d}t\\
&= \int \left(\frac{\partial L}{\partial q_i} -\frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial L}{\partial \dot{q}_i} + \frac{\mathrm{d}^2}{\mathrm{d}t^2} \frac{\partial L}{\partial \ddot{q}_i}\right) \delta q_i \mathrm{d}t\\
\end{align}
Where I assumed that $\delta q=\delta \dot{q}=0$ on the boundaries. Which means that 
$$\frac{\delta S}{\delta q_i}=\frac{\partial L}{\partial q_i} -\frac{\mathrm{d}}{\mathrm{d}t}\frac{\partial L}{\partial \dot{q}_i} + \frac{\mathrm{d}^2}{\mathrm{d}t^2} \frac{\partial L}{\partial \ddot{q}_i}=0$$
are the Euler-Lagrange equations.
A: *

*If there are no boundary conditions, it is overkill to use the Euler-Lagrange (EL) equations as it is evident from the very beginning that 
$$ \ddot{x}^i ~=~ b^i(x,t), \qquad i~\in~\{1,\ldots,n\},$$
minimizes OP's functional (1).

*If OP wants to use EL equations, he must assume adequate boundary conditions ($x$ and $\dot{x}$ should be fixed at initial and final times). Then EL equations become
$$ \sum_{i=1}^n \left( \delta^i_j\frac{d^2}{dt^2} - \frac{\partial b^i}{\partial x^j}\right) (\ddot{x}^i - ~b^i)~=~0, \qquad j~\in~\{1,\ldots,n\}.$$ 
