# How do I invert a system in state space form?

Suppose I have a system described in state-space form. Can I invert the system (swapping the roles of the input $u$ and output $y$)?

\begin{align} \dot{x} &= A\,x + B\,u \\ y &= C\,x + D\,u \end{align}

and $D$ is invertible, then we can use the second equation to solve for $u$ in terms of $x$ and $y$:

$$u = D^{-1} (y - C\,x)$$

We can then substitute that back into the original state-space description to get the inverse system:

\begin{align} \dot{x} &= (A - B\,D^{-1}\,C)\,x + B\,D^{-1}\,y \\ u &= -D^{-1}\,C\,x + D^{-1}\,y \end{align}

However, in typical systems $D$ is zero. What is the significance of requiring $D$ to be invertible to inverse the system? Is there a work-around allowing us to invert systems where $D=0$?

When $D$ is invertible means that an equivalent transfer function has the same order numerator as denominator. So the inverse also has the same order numerator as denominator. The stated state space model can only represent transfer functions which are proper, the degree of the numerator does not exceed the degree of the denominator. When $D$ is not invertible means that the order of the numerator is less then the degree of the denominator, so for the inverse the degree of the numerator does exceed the degree of the denominator.
It is still possible to represent an 'improper' transfer function as a state space model, however you then have to introduce an $E$ matrix as well. This is called a descriptor state space model and is defined as
which has an improper transfer function when $E$ is not full rank, so not invertible. finding the inverse of a state space model with a not invertible $D$ is more complicated, since it is not directly clear what the degree difference would be between numerator and denominator, thus how much rank deficiency $E$ needs to have.
Suppose I know the trajectory $x(t)$ and $\dot{x}(t)$ that I want the system to follow. If the B matrix is invertible, then the inverse system is simply $u=B^{-1}\left(\dot{x}-A x\right)$.