diff --git a/examples/check-controllability-and-observability.py b/examples/check-controllability-and-observability.py new file mode 100644 index 000000000..ea3254911 --- /dev/null +++ b/examples/check-controllability-and-observability.py @@ -0,0 +1,34 @@ +""" check-controllability-and-observability.py + +Example to check the controllability and the observability of a state space system. +RMM, 6 Sep 2010 +""" + +from scipy import * # Load the scipy functions +from control.matlab import * # Load the controls systems library + +# Parameters defining the system +m = 250.0 # system mass +k = 40.0 # spring constant +b = 60.0 # damping constant + +# System matrices +A = matrix([[1, -1, 1.], + [1, -k / m, -b / m], + [1, 1, 1]]) + +B = matrix([[0], + [1 / m], + [1]]) + +C = matrix([[1., 0, 1.]]) + +sys = ss(A, B, C, 0) + +# Check controllability +Wc = ctrb(A, B) +print("Wc = ", Wc) + +# Check Observability +Wo = obsv(A, C) +print("Wo = ", Wo) diff --git a/examples/slicot-test.py b/examples/slicot-test.py deleted file mode 100644 index f14e2995c..000000000 --- a/examples/slicot-test.py +++ /dev/null @@ -1,26 +0,0 @@ -# Simple test function to test out SLICOT interface -# RMM, 28 May 09 - -import numpy as np # Numerical library -from scipy import * # Load the scipy functions -from control.matlab import * # Load the controls systems library - -# Parameters defining the system -m = 250.0 # system mass -k = 40.0 # spring constant -b = 60.0 # damping constant - -# System matrices -A = matrix([[1, -1, 1.], [1, -k/m, -b/m], [1, 1, 1]]) -B = matrix([[0], [1/m], [1]]) -C = matrix([[1., 0, 1.]]) -sys = ss(A, B, C, 0); - -# Eigenvalue placement -#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) diff --git a/examples/slycot-import-test.py b/examples/slycot-import-test.py new file mode 100644 index 000000000..7e4f0d9a9 --- /dev/null +++ b/examples/slycot-import-test.py @@ -0,0 +1,45 @@ +""" slycot-import-test.py + +Simple example script to test Slycot import +RMM, 28 May 09 +""" + +import numpy as np +from scipy import * +from control.matlab import * +from control.exception import slycot_check + +# Parameters defining the system +m = 250.0 # system mass +k = 40.0 # spring constant +b = 60.0 # damping constant + +# System matrices +A = np.matrix([[1, -1, 1.], [1, -k / m, -b / m], [1, 1, 1]]) +B = np.matrix([[0], [1 / m], [1]]) +C = np.matrix([[1., 0, 1.]]) +sys = ss(A, B, C, 0) + +# 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.") diff --git a/examples/test-statefbk.py b/examples/test-statefbk.py deleted file mode 100644 index b7467bc7e..000000000 --- a/examples/test-statefbk.py +++ /dev/null @@ -1,27 +0,0 @@ -# test-statefbk.py - Unit tests for state feedback code -# RMM, 6 Sep 2010 - -import numpy as np # Numerical library -from scipy import * # Load the scipy functions -from control.matlab import * # Load the controls systems library - -# Parameters defining the system -m = 250.0 # system mass -k = 40.0 # spring constant -b = 60.0 # damping constant - -# System matrices -A = matrix([[1, -1, 1.], [1, -k/m, -b/m], [1, 1, 1]]) -B = matrix([[0], [1/m], [1]]) -C = matrix([[1., 0, 1.]]) -sys = ss(A, B, C, 0); - -# Controllability -Wc = ctrb(A, B) -print "Wc = ", Wc - -# Observability -Wo = obsv(A, C) -print "Wo = ", Wo - - diff --git a/examples/tfvis.py b/examples/tfvis.py index 7929f7023..e0c9b1e8e 100644 --- a/examples/tfvis.py +++ b/examples/tfvis.py @@ -348,7 +348,7 @@ def redraw(self): tvec, yvec = control.matlab.step(self.sys) plt.plot(tvec.T, yvec) except: - print "Error plotting step response" + print("Error plotting step response") plt.suptitle('Step Response') self.canvas_pzmap.show()