1% [alpha, A] = PH3From5Moments(moms)
3% Returns a PH(3) which has the same 5 moments as given.
7% moms : vector of doubles, length(5)
12% alpha : vector, shape (1,3)
13% The initial probability vector of the PH(3)
14% A : matrix, shape (3,3)
15% Transient generator matrix of the PH(3)
19% Raises an error if the moments are not feasible with
20% a PH(3). Also note that the numerical behavior of the
21% procedure can be poor if the moments are close to the
22% boundary of the feasible region.
26% .. [1] G. Horvath and M. Telek, "On the canonical
27% representation of phase type distributions,"
28% Performance Evaluation, vol. 66, no. 8, pp.
31function [alpha, A] = PH3From5Moments (moms, prec)
33 if ~exist('prec','var')
37 % convert the moments to reduced moments
38 rmoms = ReducedMomsFromMoms(moms);
40 rmoms(i) = rmoms(i) / moms(1)^i;
43 %solve linear system of equations for a0 a1 a2
44 M = [rmoms(3) -rmoms(2) rmoms(1); rmoms(4) -rmoms(3) rmoms(2); rmoms(5) -rmoms(4) rmoms(3)];
45 a = M\[1; rmoms(1); rmoms(2)];
47 discr = a(3)^2-3*a(2);
49 error ('Invalid characteristic polynomial!');
52 gu = (a(3) + 2*sqrt(discr)) / 3;
53 g0 = (a(3) + sqrt(discr)) / 3;
55 [~,ix] = sort(real(roots([1 fliplr(a')])),'ascend');
57 lmb = -roots([1 fliplr(a')]);
60 d1 = a(2) - a(3) - a(1) * rmoms(2);
61 d2 = a(1) - a(2) - a(3) * d1;
62 d3 = -a(1) - a(2)*d1 - a(3)*d2;
64 if d1>prec || (abs(d1)<prec && d2>0)
65 error ('Negative density around 0!');
69 error('Invalid eigenvalues!');
72 if imag(lambda(1)) < prec
79 error('Invalid eigenvalues (gl>gu detected)!');
92 error('alpha_2
is negative!');
100 if real(lambda(1))==lambda(1) && g2<gl
103 x13 = x1 - a(1) / (x1^2 - a(3)*x1 + a(2));
106 bels = (a(3)-x1)^2 - 4*(x1^2-a(3)*x1+a(2));
107 if bels<0 && bels>-prec
111 x2 = (a(3) - x1 + sqrt(bels)) / 2;
112 x3 = (a(3) - x1 - sqrt(bels)) / 2;
113 p1 = d1 / (x13 - x1);
114 p2 = (x1*d1 + d2) / (x13-x1) / x2;
115 p3 = (x1*x2*d1 + x2*d2 + x1*d2 + d3) / (x13-x1) / x2 / x3;
117 A = [-x1 0 x13; x2 -x2 0; 0 x3 -x3] / moms(1);
120 if x13<-prec || x13>x1
121 error('Invalid generator!');
124 if min(real(alpha))<-prec
125 error('Initial vector has negative entries!');
128 if max(abs(imag(alpha)))>prec
129 error('Inital vector has complex entries!');
132 if max(real(alpha))>1+prec
133 error('Initial vector has entries that are greater than 1!');