44'''
55
66from . import statesp as ss
7- from sympy import symbols , Matrix , symarray
8- from lmi_sdp import LMI_NSD , to_cvxopt
9- from cvxopt import solvers
10-
117import numpy as np
8+ import cvxopt as cvx
129
1310
1411def is_passive (sys ):
@@ -27,28 +24,38 @@ def is_passive(sys):
2724 C = sys .C
2825 D = sys .D
2926
30- P = Matrix (symarray ('p' , A .shape ))
31-
32- # enforce symmetry in P
33- size = A .shape [0 ]
34- for i in range (0 , size ):
35- for j in range (0 , size ):
36- P [i , j ] = P [j , i ]
37-
38- # construct matrix for storage function x'*V*x
39- V = Matrix .vstack (
40- Matrix .hstack (A .T * P + P * A , P * B - C .T ),
41- Matrix .hstack (B .T * P - C , Matrix (- D - D .T ))
27+ def make_LMI_matrix (P ):
28+ V = np .vstack ((
29+ np .hstack ((A .T @ P + P @A , P @B )),
30+ np .hstack ((B .T @P , np .zeros_like (D ))))
31+ )
32+ return V
33+
34+ P = np .zeros_like (A )
35+ matrix_list = []
36+ state_space_size = A .shape [0 ]
37+ for i in range (0 , state_space_size ):
38+ for j in range (0 , state_space_size ):
39+ if j <= i :
40+ P = P * 0.0
41+ P [i , j ] = 1.0
42+ P [j , i ] = 1.0
43+ matrix_list .append (make_LMI_matrix (P ).flatten ())
44+
45+ coefficents = np .vstack (matrix_list ).T
46+
47+ constants = - np .vstack ((
48+ np .hstack ((np .zeros_like (A ), - C .T )),
49+ np .hstack ((- C , - D - D .T )))
4250 )
4351
44- # construct LMI, convert to form for feasibility solver
45- LMI_passivty = LMI_NSD (V , 0 * V )
46- min_obj = 0 * symbols ("x" )
47- variables = V .free_symbols
48- solvers .options ['show_progress' ] = False
49- c , Gs , hs = to_cvxopt (min_obj , LMI_passivty , variables )
52+ number_of_opt_vars = int (
53+ (state_space_size ** 2 - state_space_size )/ 2 + state_space_size )
54+ c = cvx .matrix (0.0 , (number_of_opt_vars , 1 ))
5055
5156 # crunch feasibility solution
52- sol = solvers .sdp (c , Gs = Gs , hs = hs )
57+ sol = cvx .solvers .sdp (c ,
58+ Gs = [cvx .matrix (coefficents )],
59+ hs = [cvx .matrix (constants )])
5360
5461 return (sol ["x" ] is not None )
0 commit comments