LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
aph2_fitall.m
1function APHS = aph2_fitall(M1,M2,M3)
2% Fits an acyclic phase type distribution with the given moments.
3% The result may be unfeasible.
4
5degentol = 1e-8;
6
7SCV = (M2-M1^2)/M1^2;
8% lower bound of M3 for SCV <= 1
9M3lb = 3*M1^3*(3*SCV-1+sqrt(2)*(1-SCV)^(3/2));
10
11if SCV <= 1 && abs(M3 - M3lb) < degentol
12 % when M3 is close to the lower bound, the sqrt argument is zero
13 tmp0 = 0;
14else
15 tmp0 = M3^2/9 + ((8*M1^3)/3 - 2*M2*M1)*M3 - 3*M1^2*M2^2 + 2*M2^3;
16 if tmp0 < 0
17 % infeasible: square root of negative element
18 % APHS = {};
19 % added by GC
20 APHS = {aph_fit(M1,M2,M3,2)};
21 return;
22 end
23end
24tmp1 = 3*sqrt(tmp0);
25tmp2 = M3 - 3*M1*M2;
26tmp3 = (6*M2 - 12*M1^2);
27
28% maximum number of solutions
29if tmp0 == 0
30 % the diagonal elements of D0 are identical
31 n = 1;
32else
33 n = 2;
34end
35
36% solution parameters
37h1v = zeros(n,1);
38h2v = zeros(n,1);
39r1v = zeros(n,1);
40
41if n == 1
42 h2v = tmp2/tmp3;
43 h1v = h2v;
44else
45 h2v(1) = (tmp2 + tmp1)/tmp3;
46 h2v(2) = (tmp2 - tmp1)/tmp3;
47 h1v(2) = h2v(1);
48 h1v(1) = h2v(2);
49end
50
51for j = 1:n
52 h1 = h1v(j);
53 h2 = h2v(j);
54 r1v(j) = (M1 - h1)/h2;
55end
56
57APHS = cell(1,n);
58idx = 1;
59for j = 1:n
60 h1 = h1v(j);
61 h2 = h2v(j);
62 r1 = r1v(j);
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);
67 idx = idx + 1;
68 end
69end
70
71% returns 0, 1 or 2 feasible solutions
72APHS = APHS(1:(idx-1));
73% added by GC
74if isempty(APHS)
75 APHS = {aph_fit(M1,M2,M3,2)};
76end
77end