LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
PH2From3Moments.m
1% [alpha, A] = PH2From3Moments(moms, prec)
2%
3% Returns a PH(2) which has the same 3 moments as given.
4%
5% Parameters
6% ----------
7% moms : vector of doubles, length(3)
8% The moments to match
9% prec : double, optional
10% Numerical precision, default value is 1e-14
11%
12% Returns
13% -------
14% alpha : matrix, shape (1,2)
15% The initial probability vector of the PH(2)
16% A : matrix, shape (2,2)
17% Transient generator matrix of the PH(2)
18%
19% Notes
20% -----
21% Raises an error if the moments are not feasible with
22% a PH(2).
23%
24% References
25% ----------
26% .. [1] M. Telek and A. Heindl, "Moment bounds for acyclic
27% discrete and continuous phase-type distributions of
28% second order," in In Proc. of UK Performance
29% Evaluation Workshop, UKPEW, 2002"
30
31function [alpha, A] = PH2From3Moments (moms, prec)
32
33 if ~exist('prec','var')
34 prec = 1e-14;
35 end
36
37 m1 = moms(1);
38 m2 = moms(2);
39 m3 = moms(3);
40
41 % check moment boounds
42 m2l = APH2ndMomentLowerBound(m1, 2);
43 m3l = APH3rdMomentLowerBound(m1, m2, 2);
44 m3u = APH3rdMomentUpperBound(m1, m2, 2);
45
46 if m2<m2l
47 error('The given second moment is not feasible!');
48 end
49 if m3<m3l
50 error('The given third moment is not feasible (too small)!');
51 end
52 if m3>m3u
53 error('The given third moment is not feasible (too large)!');
54 end
55
56 % check if we have an exponential distribution
57 if abs(m2/m1/m1-2.0) < prec
58 alpha = 1;
59 A = -1/m1;
60 return;
61 end
62
63 % calculate parameters
64 b = 3.0*m1*m2-m3;
65 c = 3.0*m2*m2-2.0*m1*m3;
66 e = -2.0*m1*m1+m2;
67 a = b*b+6.0*c*e;
68 if a<0
69 a = 0;
70 end
71 a = sqrt(a);
72 if c>0
73 lambda1 = (b - a) / c;
74 lambda2 = (b + a) / c;
75 p = (-b-6.0*m1*e+a) / (b+a);
76 elseif c<0
77 lambda1 = (b + a) / c;
78 lambda2 = (b - a) / c;
79 p = (b+6.0*m1*e+a) / (-b+a);
80 elseif c==0
81 lambda1 = 0;
82 lambda2 = 1.0 / m1;
83 p = 0;
84 end
85
86 % return the result
87 alpha = [p,1.0-p];
88 A = [-lambda1, lambda1; 0,-lambda2];
89end