1function APHS = aph2_fitall(M1,M2,M3)
2% Fits an acyclic phase type distribution with the given moments.
3% The result may be unfeasible.
8% lower bound of M3
for SCV <= 1
9M3lb = 3*M1^3*(3*SCV-1+sqrt(2)*(1-SCV)^(3/2));
11if SCV <= 1 && abs(M3 - M3lb) < degentol
12 % when M3
is close to the lower bound, the sqrt argument
is zero
15 tmp0 = M3^2/9 + ((8*M1^3)/3 - 2*M2*M1)*M3 - 3*M1^2*M2^2 + 2*M2^3;
17 % infeasible: square root of negative element
20 APHS = {aph_fit(M1,M2,M3,2)};
26tmp3 = (6*M2 - 12*M1^2);
28% maximum number of solutions
30 % the diagonal elements of D0 are identical
45 h2v(1) = (tmp2 + tmp1)/tmp3;
46 h2v(2) = (tmp2 - tmp1)/tmp3;
54 r1v(j) = (M1 - h1)/h2;
63 if h1 > 0 && h2 > 0 && r1 >= -degentol && r1 <= (1+degentol)
64 % feasible (or almost feasible) solution!
65 r1 = max(min(r1,1),0);
66 APHS{idx} = aph2_assemble(h1, h2, r1);
71% returns 0, 1 or 2 feasible solutions
72APHS = APHS(1:(idx-1));
75 APHS = {aph_fit(M1,M2,M3,2)};