Setting up Performance Index for Optimal Control I'm trying to determine the performance index for the system $$\dot{\bf x} = UA{\bf x},$$ where I want to minimize the velocity of the dynamical system where each agent in the system comes to a predetermined consensus at time $T$. (Here, ${\bf x}$ is the position vector, $U$ is a control matrix, and $A$ is a constant matrix). Things I know for certain: both the initial and final velocities of the system are $\bf 0$. I set up and wanted to try to minimize the performance index: $$J = \int_0^T\left[{1\over2}\|\dot{\bf x}\|^2 - \lambda^T(UA{\bf x} - \dot {\bf x})\right]\,dt$$I'm trying to take the derivative of $$H = {1\over2}\|\dot{\bf x}\|^2 - \lambda^TUA{\bf x}$$ with respect to the vector ${\bf x}$.
Here's what I did so far:
$$\begin{align*}{\partial H\over\partial {\bf x}} &= {1\over2}{\partial\over\partial {\bf x}}(\dot {\bf x}\cdot\dot{\bf x}) - {\partial\over\partial{\bf x}}(\lambda^TUA{\bf x})\\ &= {1\over2}(\dot{\bf x}\cdot\ddot{\bf x} + \ddot{\bf x}\cdot\dot{\bf x}) - {\partial\over\partial{\bf x}}(\lambda^TUA{\bf x})\\ &= {1\over2}(2\dot{\bf x}^T\ddot{\bf x}) - {\partial\over\partial{\bf x}}(\lambda^TUA{\bf x}) \\ &= \underbrace{\dot{\bf x}^T\ddot{\bf x}}_\text{scalar} - \underbrace{{\partial\over\partial{\bf x}}(\lambda^TUA{\bf x})}_{????}\end{align*}$$
I'm not entirely sure that this is even possible. According to an online matrix calculator, the 2nd part $${\partial\over\partial{\bf x}}(\lambda^TUA{\bf x}) = A^TU^T\lambda,$$ which is an $n\times 1$ vector. Is this correct? If so, the performance index is impossible, and likely indicates my performance index is not set up correctly, but I'm not sure what might be wrong.



 A: You get as variation of the action integral
\begin{align}
\delta J&=\int_0^T\left[\dot {\bf x}^\topδ\dot {\bf x}-δλ^\top(UA{\bf x}-\dot {\bf x})-λ^\top(UAδ{\bf x}-δ\dot {\bf x})\right]\,dt
\\
&=\left[(\dot {\bf x}+λ)^\topδ{\bf x}\right]_0^T
+\int_0^T\left[-(\ddot {\bf x}+\dot λ+A^\top U^\topλ)^\top δ{\bf x}-δλ^\top(UA{\bf x}-\dot {\bf x})\right]\,dt
\end{align}
so that the differential equations for the optimal/saddle-point solution inside the interval are
\begin{align}
\dot {\bf x}&=UA{\bf x}\\
0&=\ddot {\bf x}+\dot λ+A^\top U^\topλ
\end{align}
where the second can be reduced with the first so that $\dot λ$ is the leading derivative.
A: The solution you found for the second term is correct
$$
\frac{\partial}{\partial x} \left(\lambda^\top U\,A\,x\right) = \left(\lambda^\top U\,A\right)^\top.
$$
Sometimes the convention is used that partial derivative of a scalar with respect to a column vector gives a row vector. But if you consistently use one convention then it should not give mismatching dimensions.
However the solution for the first term is incorrect. Namely you calculated the derivative with respect to time instead of $x$. If you instead do take the partial derivative with respect to $x$, using that
$$
\dot{x} = U\,A\,x
$$
then the following expression can be obtained
$$
\begin{align}
\frac{\partial}{\partial x} \left(\dot{x}^\top\,\dot{x}\right) &= \frac{\partial}{\partial x} \left(x^\top\,A^\top\,U^\top\,U\,A\,x\right) \\
&= 2\,A^\top\,U^\top\,U\,A\,x
\end{align}
$$
And the dimensions of this expression does match the dimensions of the first partial derivative.
A: Using the symbol ${\dot x}$ for the velocity has led you astray, let me use $v$ instead. I'll also use a colon as an easy way to type the scalar/inner product, i.e. 
$$A:B={\rm tr}(A^TB)$$
Write the function of interest in these new terms, and find its differential and gradient
$$\eqalign{
 H &= \frac{1}{2}v:v - \lambda:v\cr
dH &= v:dv - \lambda:dv \cr
  &= (v - \lambda):dv \cr
  &= (v - \lambda):UA\,dx \cr
  &= A^TU^T(v - \lambda):dx \cr
\frac{\partial H}{\partial x}  &= A^TU^T(v - \lambda) \cr
}$$
The resulting gradient has the shape of a (column) vector.
