In lecture 5.5 Bouncing ball, slide 26, Coursera's Control of Mobile Robot course, how are the state space equations formed in "Equations of motion in-between bounces"? Why is [0 -g] added?

And how is the state space equation for bounces formed?

P.S. The ball released from a height h.


Matrix notation in general is nice because of how compactly you're able to write and especially read everything, similar to using descriptive variable names in programming or performing algebra with variables instead of values with units.

In your case, state space notation typically has the state vector $x$ that is comprised of a "list" of derivatives. This is the result of decomposing a higher order differential equation into a set of coupled first order differential equations. In your case, it looks like you have a height $h$ as a state, with a first derivative:

$$ x = \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] $$

If you take the derivative of your state vector $x$, you get $\dot{x}$, which is equivalent to:

$$ \dot{x} = \left[\begin{matrix} \dot{h} \\ \ddot{h} \end{matrix}\right] $$

Basically, everyone gets an extra "dot" (derivative). Now the thing to do is to find expressions for $\dot{x}$ in terms of $x$.

So, for the first entry in $\dot{x}$, in terms of a value from the state vector $x$, you can only say:

$$ \dot{h} = \dot{h}\\ $$

Since $\dot{h}$ is the second entry in the state vector $x$, you would write that as:

$$ \dot{h} = \left[\begin{matrix} 0 & 1 \end{matrix}\right] x \\ $$

Again, remember that $x$ is really equal to $\left[\begin{matrix} h\\\dot{h}\end{matrix}\right]$, and so you are saying:

$$ \dot{h} = \left[\begin{matrix} 0 & 1 \end{matrix}\right] \left[\begin{matrix} h\\\dot{h}\end{matrix}\right] \\ $$

If you multiply that out, you get:

$$ \dot{h} = \left(0*h\right) + \left(1*\dot{h}\right) \\ $$

which obviously then is the same as $\dot{h} = \dot{h}$.


Now, to the second entry in $\dot{x}$, again in terms of a value from the state vector $x$, well.... the second entry in $\dot{x}$, which is $\ddot{h}$, doesn't have anything to do with either entry in $x$!

Instead, the expression for $\ddot{h}$ is just $\ddot{h} = -g$; that is, the vertical acceleration is just gravity. But, you have to include the values from $x$, which means you have to explicitly state that you aren't using any:

$$ \ddot{h} = \left[\begin{matrix} 0 & 0 \end{matrix}\right] \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] + \left(-g\right) \\ $$

Now, go back to the expression for the first entry in $\dot{x}$, and be more explicit that you aren't using any constants:

$$ \dot{h} = \left[\begin{matrix} 0 & 1 \end{matrix}\right] \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] + 0 \\ $$

When you write the two equations together, then you see that you get:

$$ \dot{h} = \left[\begin{matrix} 0 & 1 \end{matrix}\right] \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] + 0 \\ \ddot{h} = \left[\begin{matrix} 0 & 0 \end{matrix}\right] \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] + \left(-g\right) \\ $$

Regroup it a little and you end up with the matrix notation from your slide:

$$ \left[\begin{matrix} \dot{h} \\ \ddot{h} \end{matrix}\right] = \left[ \begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix}\right] \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] + \left[ \begin{matrix} 0 \\ -g \end{matrix} \right] \\ $$

And again, if you let:

$$ x = \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] \\ $$


$$ \dot{x} = \left[\begin{matrix} \dot{h} \\ \ddot{h} \end{matrix}\right] \\ $$

And finally you can rewrite the matrix notation as:

$$ \boxed{\dot{x} = \left[ \begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix}\right] x + \left[ \begin{matrix} 0 \\ -g \end{matrix} \right]} \\ $$

The other way to get there is to just start with the equation of motion:

$$ \ddot{h} = -g \\ $$

That's it; the ball is only accelerating because of gravity. There's a technique to get to the state space equation from here that, like most other math/algebra stuff, will become second nature with practice. Essentially, re-write the equation to include the "missing" terms:

$$ \ddot{h} + 0*\dot{h} + 0*h = -g \\ $$

And you have to know that you're trying to get to a final form of:

$$ \dot{x} = Ax + Bu\\ $$

So you rearrange and get a little closer:

$$ \ddot{h} = -0*h - 0*\dot{h} - g \\ $$

Obviously $-0 = +0 = 0$, but I'm just highlighting that the expression's getting rearranged. Now you can see that you have a constant of $-g$, and it looks like your state vector is then $\left[\begin{matrix} h \\ \dot{h} \end{matrix} \right]$. Now you can write:

$$ \ddot{h} = \left[\begin{matrix} 0 & 0 \end{matrix}\right]\left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] - g \\ $$

And here again it looks like you could say $x = \left[\begin{matrix} h \\ \dot{h} \end{matrix}\right]$, and if you're trying to get to:

$$ \dot{x} = Ax + Bu \\ $$

then you need to figure out to write for the other terms in $\dot{x}$. First, define what $\dot{x}$ is equal to:

$$ \dot{x} = \left[\begin{matrix} \dot{h} \\ \ddot{h} \end{matrix}\right] \\ $$

and you've already got the expression for $\ddot{h}$, so now you just need an expression for $\dot{h}$ that fits in the framework. Again, this winds up with the trivial

$$ \dot{h} = \dot{h} + 0 \\ $$

and you again wind up with:

$$ \left[\begin{matrix} \dot{h} \\ \ddot{h} \end{matrix}\right] = \left[\begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix}\right]\left[\begin{matrix} h \\ \dot{h} \end{matrix}\right] + \left[\begin{matrix} 0 \\ -g \end{matrix}\right] \\ $$

or, again,

$$ \dot{x} = \left[\begin{matrix} 0 & 1 \\ 0 & 0 \end{matrix}\right]x + \left[\begin{matrix} 0 \\ -g \end{matrix}\right] \\ $$

This is like factoring polynomials, trig proofs, or any other skill - it's something that's awkward at first and only gets easier with practice. Hopefully this is all clear enough to show you how that particular expression was derived. If not, please leave a comment and I'll try to help clarify.

  • 1
    $\begingroup$ I’d give this answer a second upvote if I could. Very nice. $\endgroup$ – SteveO Jan 22 at 22:49
  • $\begingroup$ (+1) nice answer. I would avoid to use $y$ as state variables to avoid any confusion since the same letter is assigned to the output in the post. $\endgroup$ – CroCo Jan 28 at 9:16
  • 1
    $\begingroup$ @CroCo - Great point; just made the edit. Thanks! $\endgroup$ – Chuck Jan 28 at 13:59

From Newton's second law, we have $$ \sum F = m\ddot{h} $$ Assume for simplicity the only force acts on the ball is the gravitational force $f_g$ (i.e. for more accurate model, you may consider the drag force as well) $$ \begin{align} -f_g &= m\ddot{h} \\ -mg &= m\ddot{h} \\ \ddot{h} &= -g \tag{1} \end{align} $$ Eq.(1) is a second order differential equation. We need to convert it to a first order differential equation by introducing two variables as follows: $$ \begin{align} x_1 &= h \tag{2} \\ x_2 &= \dot{h} \tag{3} \end{align} $$ Now differentiate Eq.(2) and Eq.(3) with respect to time, we get

$$ \begin{align} \dot{x}_1 &= \dot{h} \tag{4} \\ \dot{x}_2 &= \ddot{h} \tag{5} \end{align} $$ From Eq.(3) and Eq.(4), we have $$ \dot{x}_1 = \dot{h} = x_2 $$ From Eq.(1) and Eq.(5), we have $$ \dot{x}_2 = \ddot{h} = -g $$

The new representation is now

$$ \begin{align} \dot{x}_1 &= x_2 \\ \dot{x}_2 &= -g \end{align} $$

In a matrix-vector form,

$$ \begin{align} \begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &= \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} + \begin{bmatrix} 0 \\ -g \end{bmatrix} \end{align} $$ This is what in the presentation, however, a more correct model would be $$ \begin{align} \underbrace{ \begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} }_{\dot{x}} &= \underbrace{ \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} }_{A} \underbrace{ \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} }_{x} + \underbrace{ \begin{bmatrix} 0 \\ -1 \end{bmatrix} }_{B} g \end{align} $$

The system is now in this form: $$ \dot{x} = Ax + Bu $$ where $u=g$ is the input of the system. In this case, the gravity is considered as an input that governs the ball's motion.

For the output, we assume the height $h$ is the output (i.e. it is an arbitrarily choice, we may choose the velocity $\dot{h}$), therefore, the output in the new representation is constructed as follows: $$ y = \underbrace{ \begin{bmatrix} 1 & 0 \end{bmatrix} }_{C} \underbrace{ \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} }_{x} $$

  • $\begingroup$ This is a great answer, and the $x_1$, $x_2$ convention is super common and actually the way I was taught. $\endgroup$ – Chuck Jan 23 at 0:26

g is added because it is needed for initializing the physics engine. Box2d takes before the first run a value which is usually -9.81 but the user can change it to 9.81 if is his coordinate system works different or he can use even zero gravity. In contrast, the term state space refers to the action space in which the overall system can be. For example, if the ball is at position=30,20 and then moves to 30,10 this has to do with the state space transition.

import Box2D
g = 9.81
world = Box2D.b2World(gravity=(0,g), doSleep=True)

The matrix notation in the original posting is very illustrative, because it makes clear that bouncing balls have to do with mathematics and linear algebra. It is the lingua franca in science and should be used as much as possible to prevent the fuzzy logic enthusiasts from taking over our control-theory.

  • 1
    $\begingroup$ "g is added because it is needed for initializing the physics engine" that is not true or poorly worded. Also, your answer is vague and confusing. $\endgroup$ – CroCo Jan 22 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.