Skip to content

Clean examples#267

Merged
murrayrm merged 2 commits intopython-control:masterfrom
don4get:refactor/clean-examples
Apr 16, 2019
Merged

Clean examples#267
murrayrm merged 2 commits intopython-control:masterfrom
don4get:refactor/clean-examples

Conversation

@don4get
Copy link
Copy Markdown
Contributor

@don4get don4get commented Jan 5, 2019

Since previous PR #266 came a little bit too late, this one only aims at cleaning 2 examples.

@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 78.383% when pulling 6567c2c on don4get:refactor/clean-examples into 31e6944 on python-control:master.

@murrayrm
Copy link
Copy Markdown
Member

murrayrm commented Apr 7, 2019

I don't see what this PR is trying to accomplish. Seems to just be renaming some files??

@don4get
Copy link
Copy Markdown
Contributor Author

don4get commented Apr 13, 2019

Indeed, I agree that's not a critical MR.

Still, it does a little bit more than just renaming examples which original was confusing (test_feedback.py does not test feeback, but just controllability and observability).

In the example of pole placement, the original file full of commented code, without any explanation for the user nor any tips on how to use the library. Moreover, the commented code seems to imply that ab01md is the slycot routine for pole placement, which is not:
http://slicot.org/objects/software/shared/doc/AB01MD.html

So I cleaned commented code, I highlighted for new users of the library how they can try to use slycot with the useful slycot_check, and I compared scipy pole placement with slycot one.

To me, the example is a lot clearer this way, don't you think so?

Original code

#from slycot import sb01bd
K = place(A, B, [-3, -2, -1])
print("Pole place: K = ", K)
print("Pole place: eigs = ", np.linalg.eig(A - B * K)[0])

# from slycot import ab01md
# Ac, Bc, ncont, info = ab01md('I', A, B)

New code

# Python control may be used without slycot, for example for a pole placement.
# Eigenvalue placement
w = [-3, -2, -1]
K = place(A, B, w)
print("[python-control (from scipy)] K = ", K)
print("[python-control (from scipy)] eigs = ", np.linalg.eig(A - B * K)[0])

# Before using one of its routine, check that slycot is installed.
w = np.array([-3, -2, -1])
if slycot_check():
    # Import routine sb01bd used for pole placement.
    from slycot import sb01bd

    n = 3  # Number of states
    m = 1  # Number of inputs
    npp = 3 # Number of placed eigen values
    alpha = 1 # Maximum threshold for eigen values
    dico = 'D'  # Discrete system
    _, _, _, _, _, K, _ = sb01bd(n, m, npp, alpha, A, B, w, dico, tol=0.0, ldwork=None)
    print("[slycot] K = ", K)
    print("[slycot] eigs = ", np.linalg.eig(A + np.dot(B, K))[0])
else:
    print("Slycot is not installed.")

@murrayrm murrayrm merged commit d8d0a9c into python-control:master Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants