LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
CheckMERepresentation.m
1% r = CheckMERepresentation(alpha, A, prec)
2%
3% Checks if the given vector and matrix define a valid matrix-
4% exponential representation.
5%
6% Parameters
7% ----------
8% alpha : matrix, shape (1,M)
9% Initial vector of the matrix-exponential distribution
10% to check
11% A : matrix, shape (M,M)
12% Matrix parameter of the matrix-exponential distribution
13% to check
14% prec : double, optional
15% Numerical precision. The default value is 1e-14.
16%
17% Returns
18% -------
19% r : bool
20% True, if the matrix is a square matrix, the vector and
21% the matrix have the same size, the dominant eigenvalue
22% is negative and real
23%
24% Notes
25% -----
26% This procedure does not check the positivity of the density!
27% Call 'CheckMEPositiveDensity' if it is needed, but keep in
28% mind that it can be time-consuming, while this procedure
29% is fast.
30
31function r = CheckMERepresentation (alpha, A, prec)
32
33 global BuToolsVerbose;
34 global BuToolsCheckPrecision;
35 if isempty(BuToolsCheckPrecision)
36 BuToolsCheckPrecision = 1e-14;
37 end
38
39 if ~exist('prec','var')
40 prec = BuToolsCheckPrecision;
41 end
42
43 if size(A,1)~=size(A,2)
44 if BuToolsVerbose
45 fprintf ('CheckMERepresentation: The matrix is not a square matrix!\n');
46 end
47 r = false;
48 return;
49 end
50
51 if length(alpha)~=size(A,1)
52 if BuToolsVerbose
53 fprintf ('CheckMERepresentation: The vector and the matrix have different sizes!\n');
54 end
55 r = false;
56 return;
57 end
58
59 if sum(alpha)<-prec*length(alpha) || sum(alpha)>1+prec*length(alpha)
60 if BuToolsVerbose
61 fprintf ('CheckMERepresentation: The sum of the vector elements is less than zero or greater than one (precision: %g)!\n',prec);
62 end
63 r = false;
64 return;
65 end
66
67 if max(real(eig(A)))>=prec
68 if BuToolsVerbose
69 fprintf ('CheckMERepresentation: There is an eigenvalue of the matrix with non-negative real part (at precision %g)!\n',prec);
70 end
71 r = false;
72 return;
73 end
74
75 ev = eig(A);
76 [~,ix] = sort(abs(real(ev)));
77 maxev = ev(ix(1));
78
79 if ~isreal(maxev)
80 if BuToolsVerbose
81 fprintf ('CheckMERepresentation: The dominant eigenvalue of the matrix is not real!\n');
82 end
83 r = false;
84 return;
85 end
86
87 if sum(abs(ev(1:end))==abs(maxev)) > 1 && BuToolsVerbose
88 fprintf ('CheckMERepresentation warning: There are more than one eigenvalue with the same absolute value as the largest eigenvalue!\n');
89 end
90
91 r = true;
92end