Week 4: Finishing Preparations
April 17, 2026
Last week, we left off with a novel way to describe our system, the State-Space representation. This allows our variables and equations to be represented by a collection of matrices. This week, we are going to put this property to use, specifically by “finding” the optimal gain matrix. Finding is quoted because there is a caveat to this: the optimal matrix can only be found given the physical properties of the pendulum that we are dealing with, i.e., the mass of the rod, the speed of the cart, etc. Without the actual physical parts of the pendulum yet, there is no way to find THE optimal gain matrix.
However, in the meantime, we can prepare to make the calculation easier once we have the numbers.
A bit of background, Linear Algebra refers to the study of, well, lines, specifically linear equations, such as
. A system of linear equations can be represented using matrix multiplication. For example, the system
![]()
![]()
![]()
Is the same as

This allows us to connect multiple equations together and perform operations on them simultaneously. As the complexity of the operation grows, i.e., integrations, this method is considerably simpler to implement. This is also why we transitioned to State-Space.
Back on track. Remember, our goal for the pendulum is to keep it from tipping over. One way to mathematically describe “not tipping over” is by keeping the angle between the pole and the ground at 90 degrees. In essence, the difference between the ideal state, 90 degrees, and the actual state of the pendulum is a cost(J) that we want to minimize, a cost that can be described by this integral
![]()
Notice that I’m using the full State Vector (x) rather than just the angle. This is because not only are we controlling the rod to stay upright, but we are also trying to make the cart stay in the middle, so that, in case of a disturbance, it has the most leeway to correct its state. Q here is the weight matrix, it tells the system which variable of x we care the most about, that is, the change in which variable will increase the cost the most. Similar to the state of the system, the cost of the input also has to be considered, hence the second half of the integral, where the input (u) imposes a cost for sub-optimal control choices.
Using A, B, Q, and R, we can solve the Continuous-time Algebraic Riccati Equation(CARE) to find our optimal gain matrix K. Then, we can feed it into
![]()
which provides us with the necessary input to keep our system in check.
With this finished, all the preparatory math is done, it is now time to move on from the theoretical and begin actually setting up the pendulum. See you next week.

Leave a Reply
You must be logged in to post a comment.