def ab08nd_example(): from numpy import zeros, size from scipy.linalg import eigvals A = array([[1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0], [0, 0, 0, -4, 0, 0], [0, 0, 0, 0, -1, 0], [0, 0, 0, 0, 0, 3]]) B = array([[0, -1], [-1, 0], [1, -1], [0, 0], [0, 1], [-1, -1]]) C = array([[1, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 0, 1]]) D = zeros((3, 2)) out = slycot.ab08nd(6, 2, 3, A, B, C, D) nu = out[0] print('--- Example for ab08nd ---') print('The finite invariant zeros are') print(eigvals(out[8][0:nu, 0:nu], out[9][0:nu, 0:nu]))
def zero(self): """Compute the zeros of a state space system.""" if not self.states: return np.array([]) # Use AB08ND from Slycot if it's available, otherwise use # scipy.lingalg.eigvals(). try: from slycot import ab08nd out = ab08nd(self.A.shape[0], self.B.shape[1], self.C.shape[0], self.A, self.B, self.C, self.D) nu = out[0] if nu == 0: return np.array([]) else: return sp.linalg.eigvals(out[8][0:nu, 0:nu], out[9][0:nu, 0:nu]) except ImportError: # Slycot unavailable. Fall back to scipy. if self.C.shape[0] != self.D.shape[1]: raise NotImplementedError("StateSpace.zero only supports " "systems with the same number of " "inputs as outputs.") # This implements the QZ algorithm for finding transmission zeros # from # https://dspace.mit.edu/bitstream/handle/1721.1/841/P-0802-06587335.pdf. # The QZ algorithm solves the generalized eigenvalue problem: given # `L = [A, B; C, D]` and `M = [I_nxn 0]`, find all finite lambda # for which there exist nontrivial solutions of the equation # `Lz - lamba Mz`. # # The generalized eigenvalue problem is only solvable if its # arguments are square matrices. L = concatenate((concatenate( (self.A, self.B), axis=1), concatenate( (self.C, self.D), axis=1)), axis=0) M = pad(eye(self.A.shape[0]), ((0, self.C.shape[0]), (0, self.B.shape[1])), "constant") return np.array([ x for x in sp.linalg.eigvals(L, M, overwrite_a=True) if not isinf(x) ])
def zero(self): """Compute the zeros of a state space system.""" if not self.states: return np.array([]) # Use AB08ND from Slycot if it's available, otherwise use # scipy.lingalg.eigvals(). try: from slycot import ab08nd out = ab08nd(self.A.shape[0], self.B.shape[1], self.C.shape[0], self.A, self.B, self.C, self.D) nu = out[0] if nu == 0: return np.array([]) else: return sp.linalg.eigvals(out[8][0:nu, 0:nu], out[9][0:nu, 0:nu]) except ImportError: # Slycot unavailable. Fall back to scipy. if self.C.shape[0] != self.D.shape[1]: raise NotImplementedError("StateSpace.zero only supports " "systems with the same number of " "inputs as outputs.") # This implements the QZ algorithm for finding transmission zeros # from # https://dspace.mit.edu/bitstream/handle/1721.1/841/P-0802-06587335.pdf. # The QZ algorithm solves the generalized eigenvalue problem: given # `L = [A, B; C, D]` and `M = [I_nxn 0]`, find all finite lambda # for which there exist nontrivial solutions of the equation # `Lz - lamba Mz`. # # The generalized eigenvalue problem is only solvable if its # arguments are square matrices. L = concatenate((concatenate((self.A, self.B), axis=1), concatenate((self.C, self.D), axis=1)), axis=0) M = pad(eye(self.A.shape[0]), ((0, self.C.shape[0]), (0, self.B.shape[1])), "constant") return np.array([x for x in sp.linalg.eigvals(L, M, overwrite_a=True) if not isinf(x)])
def ab08nd_example(): from numpy import zeros, size from scipy.linalg import eigvals A = array([ [1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0], [0, 0, 0,-4, 0, 0], [0, 0, 0, 0,-1, 0], [0, 0, 0, 0, 0, 3]]) B = array([ [0,-1], [-1,0], [1,-1], [0, 0], [0, 1], [-1,-1]]) C = array([ [1, 0, 0, 1, 0, 0], [0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 0, 1]]) D = zeros((3,2)) out = slycot.ab08nd(6,2,3,A,B,C,D) nu = out[0] print('--- Example for ab08nd ---') print('The finite invariant zeros are') print(eigvals(out[8][0:nu,0:nu],out[9][0:nu,0:nu]))