# Quadratic approximation of a cost function with a Taylor expansion

Given an instantaneous cost function, $g(x, u)$, we can form a quadratic approximation of this cost function with a Taylor expansion about $x_0(t)$, $u_0(t)$: $$g(x,u) \approx g(x_0, u_0) + \frac{\partial g}{\partial x}\bar{x} + \frac{\partial g}{\partial u}\bar{u} + \frac{1}{2}\bar{x}^T \frac{\partial^2 g}{\partial x^2}\bar{x} + \bar{x} \frac{\partial^2 g}{\partial x \partial u} \bar{u} + \frac{1}{2} \bar{u}^T \frac{\partial^2 g}{\partial u^2}\bar{x}$$

with $\bar{x} = x - x_0$ and $\bar{u} = u - u_0$. But the quadratic approximation has to be in this format: $$g(x,u) \approx \bar{x}^T Q \bar{x} + \bar{u}^T R \bar{u}$$

How to derive the $Q$ and $R$ matrices from the second-order Taylor expansion?

-

To answer the question: it's much simpler to specify the cost function as $g(x) + h(u)$ instead of $g(x,u)$. Then two separate second order Taylor expansion could be applied corresponding to the Q and the R.