# Issue with LQR Q matrix for a cart-pendulum model

I am currently trying to develop a controller using LQR for a Segway. The model that I am using is an inverted pendulum on a massless cart. I have made animations of the uncontrolled pendulum and of the pendulum with a PD controller, so I know that my model dynamics are correct. I have also developed an LQR controller for my system which works in simulation.

The issue that I am having is that when I substitute a "0" for a "1" in my LQR Q matrix for one particular term, then both MATLAB and Python's control systems library are unable to produce a solution. I need to have this zero in my Q matrix because the corresponding variable (the position in x of the segway, where x is the position of the contact point between the segway/pendulum and the ground) is unobservable in my real system (I don't have a sensor which allows the Segway to localize itself). Python throws the error:

slycot.exceptions.SlycotArithmeticError: The Hamiltonian or symplectic matrix H has less than n stable eigenvalues;

And MATLAB throws the error:

Error using lqr (line 42) Cannot compute the stabilizing Riccati solution S for the LQR design. This could be because:

• R is singular,
• [Q N;N' R] needs to be positive definite,
• The E matrix in the state equation is singular.

The linearized model of the system about theta = 0 (pendulum is vertical) is described by:

zdot = Az + Bu

z = [theta thetadot x xdot]'

And the corresponding A and B matrices with values substituted in are:

A = [[ 0 1 0 0 ], [58.8 0 0 0 ], [ 0 0 0 1 ], [29.4 0 0 0 ]]

B = [0 6 0 4]'

With Q equal to the 4x4 identity matrix and R equal to 1, MATLAB and Python's LQR solvers return a result. But if Q is:

Q = [[1 0 0 0],[0 1 0 0],[0 0 0 0],[0 0 0 1]]

Then the solvers throw the above errors. This result is especially surprising to me given that one does not need to know the position of a cart/pendulum system to stabilize it. Substituting 0s for any of the other 1s in the above Q matrix (while keeping a 1 in the third column/row) does not result in any of the above errors being thrown.

Any ideas on why this problem is popping up or how I can work around it? Thanks.

• LQR assumes state feedback (I could be wrong). So assumption that a state is un observable doesn't seem right. Please post the equations for the system as well as a diagram.
– AJN
Jun 11 at 1:28
• AFAIK, the position state doesn't affect the pendulum dynamics. Neither does velocity (especially since you assumed massless cart IMO). Only the cart acceleration is important. Don't model that state while designing LQR and implementing the control! So your plant will have one state fewer than the original plant Modell it only when an animation or simulation is being done. Never model more states than the bare minimum required[*] while designing control systems. It will make the designer's life easier!
– AJN
Jun 11 at 1:29