LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
CheckRAPRepresentation.m
1% r = CheckRAPRepresentation(H0, H1, prec)
2%
3% Checks if the input matrixes define a continuous time RAP.
4%
5% Matrices H0 and H1 must have the same size, the dominant
6% eigenvalue of H0 is negative and real, and the rowsum of
7% H0+H1 is 0 (up to the numerical precision).
8%
9% Parameters
10% ----------
11% H0 : matrix, shape (M,M)
12% The H0 matrix of the RAP to check
13% H1 : matrix, shape (M,M)
14% The H1 matrix of the RAP to check
15% prec : double, optional
16% Numerical precision, the default value is 1e-14
17%
18% Returns
19% -------
20% r : bool
21% The result of the check
22
23function r = CheckRAPRepresentation (D0, D1, prec)
24
25 global BuToolsVerbose;
26
27 global BuToolsCheckPrecision;
28 if isempty(BuToolsCheckPrecision)
29 BuToolsCheckPrecision = 1e-12;
30 end
31
32 if ~exist('prec','var')
33 prec = BuToolsCheckPrecision;
34 end
35
36 if size(D0,1)~=size(D0,2)
37 if BuToolsVerbose
38 fprintf ('CheckRAPRepresentation: D0 is not a quadratic matrix!\n');
39 end
40 r = false;
41 return;
42 end
43
44 if size(D1,1)~=size(D1,2)
45 if BuToolsVerbose
46 fprintf ('CheckRAPRepresentation: D1 is not a quadratic matrix!\n');
47 end
48 r = false;
49 return;
50 end
51
52 if size(D0)~=size(D1)
53 if BuToolsVerbose
54 fprintf ('CheckRAPRepresentation: D0 and D1 have different sizes!\n');
55 end
56 r = false;
57 return;
58 end
59
60 if max(abs((D0+D1)*ones(size(D0,1),1))) > prec
61 if BuToolsVerbose
62 fprintf ('CheckRAPRepresentation: A rowsum of D0+D1 is not 0!(precision: %g)\n',prec);
63 end
64 r = false;
65 return;
66 end
67
68
69 ev=eig(D0);
70 if max(real(ev))>=-prec
71 if BuToolsVerbose
72 fprintf ('CheckRAPRepresentation: there is an eigenvalue of D0 with non-negative real part (at precision %g)\n',prec);
73 end
74 r = false;
75 return;
76 end
77
78 ceig=ev;
79 reig=ev;
80 for i=1:length(ev)
81 if isreal(ev(i))
82 ceig(i)=-Inf;
83 reig(i)=real(ev(i));
84 else
85 ceig(i)=real(ev(i));
86 reig(i)=-Inf;
87 end
88 end
89
90 if max(reig) < max(ceig)
91 if BuToolsVerbose
92 fprintf ('CheckRAPRepresentation: The dominant eigenvalue of D0 is not real!\n');
93 end
94 r = false;
95 return;
96 end
97
98 if max(reig)==max(ceig)
99 if BuToolsVerbose
100 fprintf('CheckRAPRepresentation: The dominant and a complex eigenvalue of D0 has the same real part!\n');
101 end
102 end
103
104 r = true;
105end