LQR using SciPy by murrayrm · Pull Request #683 · python-control/python-control
This PR updates the mateqn module to allow the use of SciPy linear algebra functions as a replacement for Slycot functions. Among other things, this allows the use of the lqr command without having to install Slycot.
I implemented this by changing all of the mateqn functions (lyap, care, dare, etc) to accept at method keyword that can either be scipy or slycot. The default value for method is slycot if it is installed, otherwise scipy, so there is no change in behavior if you have Slycot.
Other changes:
- Updated
lqrto callcarerather than replicating the code and cleaned up a lot of the code inmateqnto be more Pythonic. - Modified the
slycot_checkfunction so that it stores the result of checking whetherslycotcan be imported rather than trying to import every time the function is called. - Implemented a function for checking size and properties of matrices passed to
mateqnfunctions (mateqn._check_shape) that provides more consistent errors (this also required updating some of the unit tests). - Modified
dareto solve the generalized Sylvester equation usingslycot.sg02adrather than usingslycot.sg02mdto solve the simplified form of the discrete algebraic Riccati equation because there seems to be an error in the way thatstabilizingis handled insg02md(it returns the closed loop eigenvalues in the wrong order). (I'm working on generating a concrete counterexample for posting to Slycot.)