Determination of a cost function in optimal control I'm working on learning optimal control and I can't figure out how to reduce this equation.
What I know: 
$$\int_{0}^{\infty} x(t)^{T}Qx(t) + 2x(t)^{T}Su(t) + u(t)^{T}Ru(t) dt$$
$$u = -R^{-1}S^{T}x + v$$
Q is symmetric, R is positive definite
The resulting cost function should be:
$$\int_{0}^{\infty} x(t)^{T}Qx(t) + v(t)^{T}Rv(t) dt$$
The work I have done so far has led me to a what seems like a dead end. I am not sure how to achieve the result.
My work:
$$\int_{0}^{\infty} x(t)^{T}Qx(t) + 2x(t)^{T}S(-R^{-1}S^{T}x + v) + (-R^{-1}S^{T}x + v)^{T}R(-R^{-1}S^{T}x + v) dt$$
$$\int_{0}^{\infty} x(t)^{T}Qx(t) - 2x(t)^{T}SR^{-1}S^{T}x + 2x(t)^{T}Sv + (-x^{T}SR^{-T} + v^{T})R(-R^{-1}S^{T}x + v) dt$$
$$\int_{0}^{\infty} x(t)^{T}Qx(t) - 2x(t)^{T}SR^{-1}S^{T}x + 2x(t)^{T}Sv + (-x^{T}SR^{-T}R + v^{T}R)(-R^{-1}S^{T}x + v) dt$$
$$\int_{0}^{\infty} x(t)^{T}Qx(t) - 2x(t)^{T}SR^{-1}S^{T}x + 2x(t)^{T}Sv + x^{T}SR^{-T}RR^{-1}S^{T}x -x^{T}SR^{-T}Rv - v^{T}RR^{-1}S^{T}x + v^{T}Rv dt$$
$$\int_{0}^{\infty} x(t)^{T}Qx(t) - 2x(t)^{T}SR^{-1}S^{T}x + 2x(t)^{T}Sv + x^{T}SR^{-T}S^{T}x -x^{T}SR^{-T}Rv - v^{T}S^{T}x + v^{T}Rv dt$$
I'm not really sure where to go from here.
 A: You can make use of the fact that $R=R^{\top}$. Even if this is not the case, you can make it so. In order to see why I will denote the final result for the integral with $J$ which is scalar, so it should always be true that $J=(J+J^{\top}\!)/2$. By doing this also to all the terms inside the integral it can be shown that you get the same answer if you redefine $R$ as $(R+R^{\top}\!)/2$, which is symmetric. The same can not be said about $S$, but you can use that the cross term is scalar and therefore $v^{\top}S^{\top}x=x^{\top}S\,v$. This is also why there is a $2$ in the original equation, because it can also be written as
$$
\int_0^\infty \begin{bmatrix}x \\ u\end{bmatrix}^\top \begin{bmatrix}Q & S \\ S^\top & R\end{bmatrix} \begin{bmatrix}x \\ u\end{bmatrix} dt
$$
Substituting in that $R=R^{\top}$ and that cross term is also equal to its transpose into your last expression allows it to be simplified to
$$
\int_0^\infty x^\top Q\,x - 2\,x^\top S\,R^{-1}S^\top x + 2\,x^\top S\,v + x^\top S\,R^{-1}S^\top x - x^\top S\,R^{-1}R\,v - x^\top S\,v + v^\top R\,v\,dt
$$
$$
\int_0^\infty x^\top\!\left(Q - S\,R^{-1}S^\top\right)x + v^\top\!R\,v\, dt
$$
The finial expression inside the integral is not identical to $x^\top\!Q\,x + v^\top\!R\,v$, because there aren't in general. But you can view the matrix within the brackets in the quadratic term of $x$, $Q - S\,R^{-1}S^\top$, as the new $Q$ matrix.
In order for there to be a solution to the LQR problem it does require that this new $Q$ matrix is positive semi-definite. This requirement is identical to the requirement of that
$$
\begin{bmatrix}Q & S \\ S^\top & R\end{bmatrix}
$$
is positive semi-definite as well, with $R$ still positive definite. So if the LQR problem is solvable for the following weighting matrices $(Q,R,S)$, then it will also be solvable when using $(Q-S\,R^{-1}S^\top,R,0)$ as weighting matrices.
