LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
CheckGenerator.m
1% r = CheckGenerator(Q, transient, prec)
2%
3% Checks if the matrix is a valid generator matrix: the
4% matrix is a square matrix, the matrix has positive or
5% zero off-diagonal elements, the diagonal of the matrix
6% is negative, the rowsum of the matrix is 0.
7%
8% If the "transient" parameter is set to false, it checks
9% if the real part of the maximum absolute eigenvalue is
10% less than zero and the rowsum is equal or less than 0.
11%
12% Parameters
13% ----------
14% Q : matrix, shape (M,M)
15% The generator to check.
16% transient : bool, optional
17% If true, the procedure checks if Q is a transient
18% generator, otherwise it checks if it is a valid
19% generator. The default value is false.
20% prec : double, optional
21% Entries with absolute value less than prec are
22% considered to be zeros. The default value is 1e-14.
23%
24% Returns
25% -------
26% r : bool
27% The result of the check.
28
29function r = CheckGenerator (Q,transient,prec)
30
31 global BuToolsVerbose;
32 global BuToolsCheckInput;
33 if isempty(BuToolsCheckInput)
34 BuToolsCheckInput = true;
35 end
36 global BuToolsCheckPrecision;
37 if isempty(BuToolsCheckPrecision)
38 BuToolsCheckPrecision = 1e-14;
39 end
40
41 if ~exist('prec','var')
42 prec = BuToolsCheckPrecision;
43 end
44
45 if ~exist('transient','var')
46 transient = false;
47 end
48
49 r = false;
50
51 if size(Q,1)~=size(Q,2)
52 if BuToolsVerbose
53 fprintf ('CheckGenerator: Generator is not a square matrix!\n');
54 end
55 return;
56 end
57
58 if any(diag(Q)>=prec)
59 if BuToolsVerbose
60 fprintf ('CheckGenerator: The diagonal of the generator is not negative (precision: %g)!\n', prec);
61 end
62 return;
63 end
64
65 N = size(Q,1);
66 odQ = Q<-prec;
67 for i=1:N
68 odQ(i,i) = 0;
69 end
70
71 if sum(any(odQ))>0
72 if BuToolsVerbose
73 fprintf ('CheckGenerator: The generator has negative off-diagonal element (precision: %g)!\n', prec);
74 end
75 return;
76 end
77
78 if transient
79 if max(sum(Q,2))>prec
80 if BuToolsVerbose
81 fprintf ('CheckGenerator: The rowsum of the transient generator is greater than 0 (precision: %g)!\n', prec);
82 end
83 return;
84 end
85
86 if max(real(eig(Q)))>=prec
87 if BuToolsVerbose
88 fprintf ('CheckGenerator: The transient generator has non-negative eigenvalue (precision: %g)!\n', prec);
89 end
90 return;
91 end
92 else
93 if any(abs(sum(Q,2))>prec)
94 if BuToolsVerbose
95 fprintf ('CheckGenerator: The rowsum of the generator is not 0 (precision: %g)!\n', prec);
96 end
97 return;
98 end
99 end
100 r = true;
101end