- A linear system can be expressed in a linear differential equation as
- Where
- is the state vector. It contains the values of all the state variables at a particular time
- is the state-transition matrix. it ‘shows’ how the state changes with time. The product of and gives the state at another time.
- is the control or input matrix. Loose definition: Shows the different ways the state can be controlled by .
- is the control vector. It represents the effort applied to the state to transition it into a new state
- is the time derivative of the state x.
- For any linear dynamical system, the state-transition matrix, and the control matrix, are generally fixed. So in order to drive the system to a specific state, it is the control vector that must be regulated, if the system is controllable; thus, if the rank of the controllability matrix of the system () is n. More on this here
- A common controller for dynamical systems is the proportional controller, expressed as
where is the proportional factor that must be chosen to regulate
- Substituting into the state-space representation of the linear system, we end up with the equation
- An interesting finding is that, the stability of the system can be determined by the nature of the eigenvalues of the matrix
- If the real part of any of the eigenvalues of the matrix is positive, then the system is unstable
- If the real parts of all the eigenvalues of the matrix are negative, then the system is stable
- So naturally, since is the only changeable variable in the matrix , you’d want to choose a that makes the eigenvalues of the matrix have negative real parts.
- This can easily be done in Matlab, using the comand
k = place (A, B, good_eigens)
where good_eigens is a vector of eigenvalues with negative real parts. More on how the place function works in Matlab can be found here
- Choosing the good_eigens vector manually is tricky. This is because, large negative parts of eigenvalues causes instability because the system tends to ‘shoot’ too quickly towards stability, making it overshoot in some cases. Small negative parts of eigenvalues also cause the system to very slowly approach stability. And this might not be ideal in some cases.
- So how to we choose the perfect eigenvalues that lie at the sweet spot between too fast and too slow? Use LQRs!
- Where
- The LQR algorithm chooses the best eigenvalues by optimizing (minimizing) a cost function whose parameters are specified by the user.
- The cost function, is
- is an nxn matrix that expresses the penalty for the speed at which each of the parameters in the state vector should be reached. For instance: for a state vector , if it has a matrix of then it means it gives a penalty of for reaching state parameters and slowly, a penalty of for reaching state parameter slowly and a penalty of for reaching state parameter slowly.
- is a qxq matrix (where q is the size of control vector ) that specifies the penalty for using up control effort . would be large if it is expensive to apply control .
- Optimizing the cost function and solving for involves solving a Riccati differential equation. Details can be found here. The time complexity for optimizing is . As such, LQR is intractable for systems with really large state-transition matrices.
- LQR can easily be used to find the optimal in Matlab by
k = lqr(A, B, Q, R)
. This returned gives the matrix optimal eigenvalues based on the user’s choice of penalty matrices Q and R. More on the lqr Matlab function here.
- The cost function, is