Where the Rubber Meets the Road: State-Space Methods Part 1

The concept that we will explore in this article is incredibly important because it sits right at the tipping point between trivial and non-trivial problems. Trivial problems are the problems that we are all used to doing in classes, where it is simple enough to complete in an hour or two and easy to check your work. Non-trivial problems are the problems that we encounter in the real world with real systems. These are either “unsolvable”, too difficult or time-consuming for us to solve by hand.

Introduction

In the 60’s, engineers researching control systems discovered a way to make calculations easier. This was the state-space method. These models are matrix-based, easy to code, and you can use GPU hardware accelerators to run them efficiently. The concept has a bit of a learning curve but it is a very intuitive way to describe complicated dynamics systems as it combines simple linear algebra and calculus concepts. The model’s core is an addition of a set of vector-matrix multiplications. State-space models can be used for anything from, circuits, to motors, to entire aircraft dynamics and nuclear reactors. In this article, I will go through a background knowledge refresher and the basic theory behind these methods. In a later article we will dive into some examples.

Background Knowledge

The following few sections are a refresher of the background knowledge required to dive into the state-space method. If this is all old news to you, great! if not, then I recommend digging a little more into the things that may be a little rusty. There are many high-quality resources available to get that rust knocked off.

Linear Algebra

Vectors are numeric quantities with a magnitude and a direction. The magnitude of a vector is a scalar. They are often underlined or written in bold font for notation and can be represented as matrices. They can be represented by a column matrix of dimensions \(n\times1\)
$$\begin{bmatrix}
p \\ q \\ r
\end{bmatrix}$$

Matrix multiplication only works for particular matrix dimensions. The rows in the second matrix must be the same as the columns in the first.
$$[C]=[A][B]$$
If A is \(m\times n\) and B is \(j \times k\) then \(n\) and \(j\) must be equal and the resulting dimension is \(m \times k\)

When you multiply a matrix by a vector, you rotate and scale that vector. This means that the same matrix rotates and scales different vectors differently. As this is a Linear transformation, lines on the input vector space are mapped to lines on the output vector space.

Differential Equations

An ordinary differential equation (ODE) contains derivatives of dependent variables with respect to a single independent variable. ODEs are used to represent many aspects of dynamic and chaotic systems. Differential equations are typically denoted by an equation and some boundary conditions.

Multiple ODEs can be combined into systems of ODEs
$$\begin{bmatrix}
y_1 \\ y_2 \\ \vdots \\ y_n
\end{bmatrix}
=\begin{bmatrix}
f_1(y_1,y_2,\dots,y_n,t) \\
f_2(y_1,y_2,\dots,y_n,t) \\
\vdots \\
f_n(y_1,y_2,\dots,y_n,t)
\end{bmatrix}$$

Initial Value Problems

Initial value problems are the solutions to an ODE starting from an initial state and solved over a period of time. These problems are solved by propagating the motion of a solution point through a vector field defined by the differential equation. The resulting trajectory is known as an integral curve. The form of an initial value problem is
$$\begin{matrix}
\frac{d\psi}{dx}=f(x,\psi) \
\psi(0)=A
\end{matrix}$$

The state-space method is just a generalized linear initial value problem.

Integration Methods

Numerical Integration methods are used to solve these initial value problems. For example, integrating an accelerometer output twice can provide the position of an object over time. The higher the order of the integration method, the more accurate the results are.

Different integration methods may use different numbers of function evaluations to determine the value at the next time step. They also make different assumptions about how the signal changes between the discrete points. These methods are used to step from a value at one timestep to a value at a second timestep.

Using numerical integration has the potential to introduce numerical instability and errors as it is just a fancy approximation scheme, but it is usually the only way to solve very complicated systems of equations. It is also beneficial for systems with nonlinear inputs.

For fast systems with a very high natural frequency, you need to be careful about selecting an integration method. Combining different integration methods for some applications leads to a better function evaluation. For Example, you could use Euler’s method for the acceleration-to-velocity integration and then the Tustin method for the velocity-to-position integration. One run of thumb when choosing an integration method is the more information about the modeled system you can bake into the integration method, the better your results will be. For more information I have a previous article dedicated to numerical integration.

Eigenvalues

I think eigenvalues are one of the most important mathematical concepts that we can use. The Eigenvalue is the magnitude of the scaling of the Eigenvector. An eigenvalue is a complex number with both real and imaginary parts. The eigenvalue is a scalar \(\lambda\) that satisfies the equation $$Mv=\lambda v$$. The matrix \(M\) represents what’s called the Hamiltonian matrix, and \(v\) is the eigenvector. Eigenvalues are the roots of the characteristic equation derived from a set of differential equations. A system of \(n\) different equations produces \(n\) eigenvalues. The trick that makes eigenvalues so useful is that they are used to determine the stability of a system.

The State-Space Method

With that out of the way lets, move on to our main course. A state-space model is a powerful tool in ,modeling, simulation, and control system design. It represents a system as input, output, and state variables. It’s not just a theoretical concept, but a practical approach used to model physical systems, measurements, and noise. The state-space form is a type of linear model, and state-space models are the ideal representation of systems for modern control system design

The state variables are selected to fully describe the system, and define the output variables. In essence, a state-space system converts a set of differential equations into an equivalent set of 1st-order ODEs.
In its continuous linear form, the matrix equation for a state space model is:
$$\begin{matrix} \dot{x} = Ax+Bu \\
y=Cx+Du
\end{matrix}$$


where \(x\) is the state vector, \(u\) is the input vector, and \(y\) is the output vector..

\(A\) is called the state matrix. it has dimensions of \(N_x \times N_x\) where \(N_x\) is the number of states. The state matrix describes the internal dynamics of the system by describing how the state elements interact with each other, in other words, this matrix represent the coupled linear equations of your system. By building a state matrix \(A\) we are in effect, linearizing the equations that make up our dynamic system.

\(B\) is the input to the state matrix. It has dimensions of \(N_x \times N_u\) where \(N_u\) is the number of inputs to the system. This matrix describes how inputs to the system affect the internal states.

\(C\) is the state-to-output matrix, It has the dimensions of \(N_y \times N_x\) where \(N_y\) is the number of elements in the output vector. This matrix describes how the internal states affect observable parameters. Not all sates is a system are required to be observable or measurable.

The final matrix \(D\) is called the feedthrough matrix; it has the dimensions of \(N_y \times N_u\). This matrix describes how an input to the system affects the immediate observable outputs. The D matrix is not typically used as we have knowledge of the control signal inputs beforehand and our main interest are the interactions of the inputs and the state dynamics.

The combination of these matrices with the state vector and input vectors describe how the state vector changes over time. For a basic system, the matrix representation remains the same while the input and state vectors change.

The output of a state-space simulation is a time-domain response, which, is what we’re interested in when designing or analyzing interacting systems. The inputs to our system are a time-domain control signal and an initial state.

When you linearize a system of differential equations that describe a complicated system, such as an aircraft, you must remember that linearization only works for a narrow assumption for conditions. Outside these operating conditions, the approximation is not usable. Linearizing works well when the derivatives of the system do not change too much around the desired operating point. An operating point is the point around which you linearize a system. For example a system denoted by the following equations

$$\begin{matrix}
\frac{dA}{dt}=3A-A^2-AB \\
\frac{dB}{dt} = 2B-AB-2B^2
\end{matrix}$$

Can be linearized around the operating point \(A=0\), \(B=0\) to get the matrix form

$$\begin{bmatrix}\dot{A}\\ \dot{B}\end{bmatrix}
\begin{bmatrix}
3 & 0\\
0 & 2
\end{bmatrix}
\begin{bmatrix}
A \\ B
\end{bmatrix}
+
\begin{bmatrix}
0 \\ 0
\end{bmatrix}$$

Linearizing works well when the derivatives of the system do not change too much around the desired operating point.

The eigenvalues of the entire system are simply the eigenvalues of the A matrix. The eigenvalues of a state-space system representation can be described with the basic equation for the eigenvalues of a matrix
$$eig(A)=det(sI-A)=0$$
The eigenvalues of the state-space system can tell us about the stability of the system.

EigenvalueEffect
Positive real numberDriven away from a steady state (unstable)
Negative Real NumberDriven toward a steady state (stable)
0Remains at disturbed position
Identical to another eigenvalueeffects cannot be determined
Complex Positive Real NumberOscillates around steady state with increasing amplitude (unstable)
Complex Negative Real NumberOscillates around a steady state with decreasing amplitude (stable)
Imaginary NumberOscillates around steady-state value with constant amplitude

We can see that in general, when the real component of the eigenvalue is positive, then the system is unstable. When the real component of eigenvalue is negative, then the system is stable. This makes sense, as positive feedback loops have an increasing effect, while negative feedback loops have a decreasing effect.

Now I’ve saved the best for last. Because the state-space model builds equations for the derivative vectors, you can use any numerical integration methods to integrate over the derivative vectors to get the states. When we do this we solve for the system’s time-series dynamics for all states simultaneously. This allows us to examine all of the state values at any time that we would like. And all we had to do was integrate a little bit of linear algebra.

Conclusion

I hope that this gives you a little bit of an introduction to the state-space methods and that it sheds some light on how to build intuitive and usable mathematical models of systems. I also hope that this gives you a practical example of why the basics of linear algebra and calculus are so important, as we start to combine all of the basic concepts into this very powerful practical tool.

Part 2 will go heavy on examples so be prepared!