|
| 1 | +""" slycot-import-test.py |
| 2 | +
|
| 3 | +Simple example script to test Slycot import |
| 4 | +RMM, 28 May 09 |
| 5 | +""" |
| 6 | + |
| 7 | +import numpy as np |
| 8 | +from scipy import * |
| 9 | +from control.matlab import * |
| 10 | +from control.exception import slycot_check |
| 11 | + |
| 12 | +# Parameters defining the system |
| 13 | +m = 250.0 # system mass |
| 14 | +k = 40.0 # spring constant |
| 15 | +b = 60.0 # damping constant |
| 16 | + |
| 17 | +# System matrices |
| 18 | +A = np.matrix([[1, -1, 1.], [1, -k / m, -b / m], [1, 1, 1]]) |
| 19 | +B = np.matrix([[0], [1 / m], [1]]) |
| 20 | +C = np.matrix([[1., 0, 1.]]) |
| 21 | +sys = ss(A, B, C, 0) |
| 22 | + |
| 23 | +# Python control may be used without slycot, for example for a pole placement. |
| 24 | +# Eigenvalue placement |
| 25 | +w = [-3, -2, -1] |
| 26 | +K = place(A, B, w) |
| 27 | +print("[python-control (from scipy)] K = ", K) |
| 28 | +print("[python-control (from scipy)] eigs = ", np.linalg.eig(A - B * K)[0]) |
| 29 | + |
| 30 | +# Before using one of its routine, check that slycot is installed. |
| 31 | +w = np.array([-3, -2, -1]) |
| 32 | +if slycot_check(): |
| 33 | + # Import routine sb01bd used for pole placement. |
| 34 | + from slycot import sb01bd |
| 35 | + |
| 36 | + n = 3 # Number of states |
| 37 | + m = 1 # Number of inputs |
| 38 | + npp = 3 # Number of placed eigen values |
| 39 | + alpha = 1 # Maximum threshold for eigen values |
| 40 | + dico = 'D' # Discrete system |
| 41 | + _, _, _, _, _, K, _ = sb01bd(n, m, npp, alpha, A, B, w, dico, tol=0.0, ldwork=None) |
| 42 | + print("[slycot] K = ", K) |
| 43 | + print("[slycot] eigs = ", np.linalg.eig(A + np.dot(B, K))[0]) |
| 44 | +else: |
| 45 | + print("Slycot is not installed.") |
0 commit comments