Repository navigation
Expand file tree
/
Copy pathpassivity.py
More file actions
54 lines (41 loc) · 1.38 KB
/
Copy pathpassivity.py
File metadata and controls
54 lines (41 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'''
Author: Mark Yeatman
Date: May 15, 2022
'''
from . import statesp as ss
from sympy import symbols, Matrix, symarray
from lmi_sdp import LMI_NSD, to_cvxopt
from cvxopt import solvers
import numpy as np
def is_passive(sys):
'''
Indicates if a linear time invarient system is passive
Constructs a linear matrix inequality and a feasibility optimization
such that is a solution exists, the system is passive.
The source for the algorithm is:
McCourt, Michael J., and Panos J. Antsaklis. "Demonstrating passivity and dissipativity using computational methods." ISIS 8 (2013).
'''
A = sys.A
B = sys.B
C = sys.C
D = sys.D
P = Matrix(symarray('p', A.shape))
# enforce symmetry in P
size = A.shape[0]
for i in range(0, size):
for j in range(0, size):
P[i, j] = P[j, i]
# construct matrix for storage function x'*V*x
V = Matrix.vstack(
Matrix.hstack(A.T * P + P*A, P*B - C.T),
Matrix.hstack(B.T*P - C, Matrix(-D - D.T))
)
# construct LMI, convert to form for feasibility solver
LMI_passivty = LMI_NSD(V, 0*V)
min_obj = 0 * symbols("x")
variables = V.free_symbols
solvers.options['show_progress'] = False
c, Gs, hs = to_cvxopt(min_obj, LMI_passivty, variables)
# crunch feasibility solution
sol = solvers.sdp(c, Gs=Gs, hs=hs)
return (sol["x"] is not None)