Once you derive the equations of motion for a system, the next step in simulating it numerically is to compute the state-space representation, the backbone of modern contorl theroy. This is useful because by placing the equations of motion in a common format we can apply a whole host of techniques to study the system. Computing the state space is made up of 3 main steps
- Determine the States
- Determine the State Transitions
- Determine the Measurement
Determining the States
When we say determine the states, we want to find the minimum number of variables that we can use to represent the system for all time. Put another way, if we have a full set of state variables at one time, we could represent it at any other time. Take, for example, a ball in a gravity field. If we know it’s position and velocity at any point in time we could use the equations of motion to find its positions and velocity at any other time. If we only knew one piece of information, position or velocity, we could not determine the other. Let’s write an n state system together in a vector form as the following
This is called our state vector. For a 1-D ball in a gravity field, our states would be a position r, and a velocity v. The state vector would be
Determine the State Transitions
In our definition of states, we said that given the full set of state information at one point in time, we want to figure out its state at another point in time. In order to do this, we need to find out how our state vector changes with time. This means taking the derivative of the state vector
In the case of our 1-D ball, the derivative of our state vector would be
We can then plug in our equations of motion
In a slightly more general form, the derivative of our state vector can be written as the following
Which means the derivative vector is some function of the time, the current state, and some external input, u.
Determine the Measurement Vector
This third component of a complete state-space representation is a bit rarer than the first two. It’s the measurement vector and comes up mostly in the field of estimation. Once again, it’s a vector and it relates your current, time, state, and some external input to what you would measure.
I don’t generally use the measurement vector, so, for now, let’s pretend it just doesn’t exist. For the rest of this whenever I say state-space representation I’m only going to discuss two parts
- The state Vector,
- The time derivative of the state Vector ,
Example Time: The Nonlinear Pendulum
Now that we have an idea what the state-space representation is, let’s practice on an example problem we’ve encountered on this blog before, the non-linear pendulum.
Here the equation of motion is as follows
The state vector for this problem are
Taking it’s time derivative, and substituting in the equation of motion we get
We now have our pendulum in a state-space representation. A good sanity check is to add all the orders of the governing equation together and seeing if it matches the number of states. In this case, we have 1 2nd-order equation of motion and 2 states so we’re good.
Example Time: CartPole
Let’s now expand to a system which requires multiple coupled equations to describe it. I derive the equations of motion for the cart pole system here, so here they are re-produced without derivation
Now, we have constants in our equations of motion, c1 and c2, as well as some external input, u. Here the statespace representation is
Let’s now do our quick sanity check. We have 2 2-nd order differential equations so we should have four states, and we do so it passes our check.
Problem Set
I’ve uploaded a small problem set if you want to practice placing systems into state-space form
Problem 1
Problem 2
Problem 3
where,
Problem 4
I’ve created a short video working through them below
Want More Gereshes?
If you want to receive new Gereshes blog post directly to your email when they come out, you can sign up for that here!
Don’t want another email? That’s ok, Gereshes also has a twitter account and subreddit!