# How is this StateSpaceModel derived?

Modifying an example from the documentation,

StateSpaceModel[{a x'[t] + b x[t] == c u'[t] + d u[t]},
{{x[t], 0}}, {u[t]}, {x[t]}, t
]


(state x, input u, output x) gives state space model

Can someone please tell me how that was derived?

• From the documentation: state-space model obtained by Taylor linearization about the point $(x_{i_0} ,u_{i_0})$ of the differential or difference equations eqns with outputs $g_i$ and independent variable $\tau$. Oct 15, 2017 at 2:47
• @swish Thanks, I've read that, but I'm looking for a step-by-step derivation. Oct 15, 2017 at 2:49

The standard method depends on what is called state space realization. Which involves determining $A,B,C,D$ from the transfer function of the ODE.

The standard form of state space representation is

\begin{align*} x^{\prime} & =Ax+Bu\\ y & =Cx+Du \end{align*}

Taking Laplace transform of the above

\begin{align*} sX\left( s\right) & =AX\left( s\right) +BU\left( s\right) \\ Y\left( s\right) & =CX\left( s\right) +DU\left( s\right) \end{align*}

From the first equation $X\left( s\right) =\left( sI-A\right) ^{-1}BU\left( s\right)$ and the second equation becomes $Y\left( s\right) =C\left( \left( sI-A\right) ^{-1}BU\left( s\right) \right) +DU\left( s\right)$ or

$$Y\left( s\right) =\left( C\left( \left( sI-A\right) ^{-1}B\right) +D\right) U\left( s\right)$$

Therefore

$$\frac{Y\left( s\right) }{U\left( s\right) }=C\left( \left( sI-A\right) ^{-1}B\right) +D\tag{1}$$

This is the transfer function. So given an ODE, we want to find its $A,B,C,D$. How do we do this?

We start by converting the ODE itself to Laplace domain, then we try to match things in order to find $A,B,C,D$. If the ODE has proper transfer function, then we can always find a representation. Here is an example for illustration.

Let

$$y^{\prime\prime}\left( t\right) +2y^{\prime}\left( t\right) +3y\left( t\right) =u\left( t\right) \tag{2}$$

The goal is to find its $A,B,C,D$ Taking Laplace transform

\begin{align} s^{2}Y\left( s\right) +2sY\left( s\right) +3Y\left( s\right) & =U\left( s\right) \nonumber\\ \frac{Y\left( s\right) }{U\left( s\right) } & =\frac{1}{s^{2} +2s+3}\tag{3} \end{align}

How can we solve for $A,B,C,D$ from

$$\frac{1}{s^{2}+2s+3}=C\left( \left( sI-A\right) ^{-1}B\right) +D$$

This seems not possible, as these seems to be too many unknowns, and one equation.

But assuming the system is what called controllable form, we can simplify things and then be able to solve for $A,B,C,D$. The Controllable form uses this setup (for an $n$ states SISO system)

\begin{align*} x^{\prime} & = \begin{pmatrix} 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ a_{1} & a_{2} & \cdots & a_{n} \end{pmatrix}% \begin{pmatrix} x_{1}\\ x_{2}\\ \vdots\\ x_{n} \end{pmatrix} + \begin{pmatrix} 0\\ 0\\ \vdots\\ 1 \end{pmatrix} u\\ y & = \begin{pmatrix} c_{1} & c_{2} & c_{3} & c_{4} \end{pmatrix} \begin{pmatrix} x_{1}\\ x_{2}\\ \vdots\\ x_{n} \end{pmatrix} +Du \end{align*}

Since there are 2 states in this example, then

$$A= \begin{pmatrix} 0 & 1\\ a_{1} & a_{2} \end{pmatrix}$$

And $B= \begin{pmatrix} 0\\ 1 \end{pmatrix} .$ Therefore,

$$x^{\prime}= \begin{pmatrix} 0 & 1\\ a_{1} & a_{2} \end{pmatrix} \begin{pmatrix} x_{1}\\ x_{2} \end{pmatrix} + \begin{pmatrix} 0\\ 1 \end{pmatrix} u$$

And let $C= \begin{pmatrix} c_{1} & 0 \end{pmatrix}$ if we want the output $x_{1}$. If the output is $x_{2}$ then $C= \begin{pmatrix} 0 & c_{2} \end{pmatrix}$, finally $D= \begin{pmatrix} d \end{pmatrix}$.

So what we have is this equation

\begin{align*} \frac{1}{s^{2}+2s+3} & = \begin{pmatrix} c_{1} & 0 \end{pmatrix} \left( \left( s \begin{pmatrix} 1 & 0\\ 0 & 1 \end{pmatrix} -% \begin{pmatrix} 0 & 1\\ a_{1} & a_{2} \end{pmatrix} \right) ^{-1} \begin{pmatrix} 0\\ 1 \end{pmatrix} \right) + \begin{pmatrix} d \end{pmatrix} \\ & = \begin{pmatrix} c_{1} & 0 \end{pmatrix} \left( \begin{pmatrix} s & -1\\ -a_{1} & s-a_{2} \end{pmatrix} ^{-1} \begin{pmatrix} 0\\ 1 \end{pmatrix} \right) + \begin{pmatrix} d \end{pmatrix} \\ & = \begin{pmatrix} c_{1} & 0 \end{pmatrix} \begin{pmatrix} -\frac{1}{-s^{2}+a_{2}s+a_{1}}\\ -\frac{s}{-s^{2}+a_{2}s+a_{1}} \end{pmatrix} + \begin{pmatrix} d \end{pmatrix} \\ & =\frac{c_{1}}{s^{2}-a_{2}s-a_{1}}+d \end{align*}

We now compare the RHS to the LHS. We see that $d=0$ and that

\begin{align*} c_{1} & =1\\ -a_{2} & =2\\ -a_{1} & =3 \end{align*}

We have solved it. We found $A,B,C,D$. The state space is then

\begin{align*} A & = \begin{pmatrix} 0 & 1\\ a_{1} & a_{2} \end{pmatrix} = \begin{pmatrix} 0 & 1\\ -3 & -2 \end{pmatrix} \\ B & = \begin{pmatrix} 0\\ 1 \end{pmatrix} \\ C & = \begin{pmatrix} c_{11} & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 \end{pmatrix} \\ D & = \begin{pmatrix} 0 \end{pmatrix} \end{align*}

Mathematica writes all these into one state space form, like this

Let us verify

 StateSpaceModel[{x''[t]+2 x'[t]+3x[t]==u[t]},
{{x[t],0}},{u[t]},{x[t]},t, StateSpaceRealization -> "Controllable"]


Applying this method to your ODE

$$ax^{\prime}\left( t\right) +bx\left( t\right) =cu^{\prime}\left( t\right) +d\ u\left( t\right)$$

Where $u\left( t\right)$ is the input. Taking Laplace transform gives

\begin{align*} asX\left( s\right) +bX\left( s\right) & =csU\left( s\right) +dU\left( s\right) \\ X\left( s\right) \left( as+b\right) & =U\left( s\right) \left( cs+d\right) \end{align*}

Hence the transfer function (TF) is

$$\frac{X\left( s\right) }{U\left( s\right) }=\frac{cs+d}{as+b}%$$

This transfer function is proper, but not strict proper. Every transfer function which is proper is realizable. A proper means the transfer function $X\left( s\right)$ has its numerator polynomial of at most the same order as the numerator $U\left( s\right)$ .

But if the TF is not strict proper, then we must convert it from proper to strict proper by simply doing long division. Which gives

$$\frac{cs+d}{as+b}=\frac{c}{a}+\frac{\frac{d-b\frac{c}{a}}{a}}{s+\frac{b}{a} }\tag{1}$$

Now this is strict proper transfer function, since numerator has one degree less than denominator. Now we compare this to the controllable form. Since $n=1$ here, then

\begin{align*} \frac{c}{a}+\frac{\frac{d-b\frac{c}{a}}{a}}{s+\frac{b}{a}} & = \begin{pmatrix} c_{1} \end{pmatrix} \left( \left( s \begin{pmatrix} 1 \end{pmatrix} - \begin{pmatrix} a_{1} \end{pmatrix} \right) ^{-1} \begin{pmatrix} 1 \end{pmatrix} \right) + \begin{pmatrix} d_{1} \end{pmatrix} \\ & = \begin{pmatrix} c_{1} \end{pmatrix} \frac{1}{s-a_{1}}+ \begin{pmatrix} d_{1} \end{pmatrix} \\ & =\frac{c_{1}}{s-a_{1}}+d_{1} \end{align*}

Hence we see that, by comparing terms that

\begin{align*} c_{1} & =\frac{d-b\frac{c}{a}}{a}\\ a_{1} & =-\frac{b}{a}\\ d_{1} & =\frac{c}{a} \end{align*}

The system is

\begin{align*} x^{\prime} & = \begin{pmatrix} -\frac{b}{a} \end{pmatrix} x_{1}+ \begin{pmatrix} 1 \end{pmatrix} u\\ y & = \begin{pmatrix} \frac{d-b\frac{c}{a}}{a} \end{pmatrix} x_{1}+ \begin{pmatrix} \frac{c}{a} \end{pmatrix} u \end{align*}

Or, in Mathematica form

$$\begin{pmatrix} -\frac{b}{a} & 1\\ \frac{-bc}{a^{2}}+\frac{d}{a} & \frac{c}{a} \end{pmatrix}$$

Lets check

StateSpaceModel[{a x'[t]+b x[t]==c u'[t]+d u[t]},
{{x[t],0}},{u[t]},{x[t]},t,StateSpaceRealization->"Controllable"]


Notice that StateSpaceRealization->"Controllable" is needed, since the method I used above uses this Realization. But you can convert this form to other standard forms.

The method I used starts from the Controllable form. The one you showed used the Observable form

StateSpaceModel[{a x'[t]+b x[t]==c u'[t]+d u[t]},
{{x[t],0}},{u[t]},{x[t]},t,StateSpaceRealization->"Observable"]


I can do the above again, starting with the observable form and solve to find $A,B,C,D$, But there is an easy way to go from one form to another, by simply transposition of matrices.

From textbook: (added: Screen shot below is from bottom of page 2 of this chapter of a book I found at this university link canonicals.pdf).

Which will now give the form you showed at the top.

QED.

The forms supported by Mathematica in state space are given ref/StateSpaceRealization.html with the shape of the Matrices. (in the details section). So assuming any one of these, and following the same steps showed above, you'll be able to find the $A,B,C,D$ of the ODE. Example shown here are for SISO. For MIMO, things get little more complicated. The transfer function become a matrix of transfer funtions now.
And yes, the $D$ matrix do not change going from controllable to observable.