forked from alchemyst/Skogestad-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobusttools.py
82 lines (63 loc) · 1.62 KB
/
robusttools.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import numpy as np
import utils
"""Use this file to add more MIMO functions for robust stability and performance"""
def wI(tau, ro, rinf, s):
"""
Uncertainity weight function. Based on equation 7.38 (p273) and 8.28 (p297).
Parameters
----------
tau : float
tau = 1 / x at y = 1.
ro : float
ro = y at x-low.
rinf : float
rinf = y at x-high.
Returns
-------
wI : float
Uncertainity weight.
NOTE
----
This is just one example of a uncertainity weight function.
"""
return (tau * s + ro) / (tau / rinf * s + 1)
def UnstructuredDelta(M, DeltaStructure):
"""
Function to calculate the unstructured delta stracture for a pertubation.
Parameters
----------
M : matrix (2 by 2),
TODO: extend for n by n
M-delta structure
DeltaStructure : string ['Full','Diagonal']
Type of delta structure
Returns
-------
delta : matrix
unstructured delta matrix
"""
if DeltaStructure == "Full":
[U, s, V] = utils.SVD(M)
S = np.diag(s)
delta = 1/s[0] * V[:,0] * U[:,0].H
elif DeltaStructure == 'Diagonal':
# TODO: complete
delta = 'NA'
else: delta = 0
return delta
def SpecRad(A):
"""
Function to calculate the spectral radius, which is the magnitude of the
largest eigenvalue of a matrix.
Parameters
----------
M : matrix (n by n)
Returns
-------
rho : float
Spectral radius.
Note
----
The spectral norm provides a lower bound for any matrix norm.
"""
return max(np.linalg.eigvals(A))