1%{ @file fj_xmax_erlang.m
2 % @brief Expected maximum of K i.i.d. Erlang-k random variables
4 % @author LINE Development Team
8 % @brief Expected maximum of K i.i.d. Erlang-k random variables
11 % Computes the expected value of the maximum of K independent and
12 % identically distributed Erlang random variables with k stages
13 % and rate mu per stage.
16 % X_K^max = (1/mu) * sum_{n=1}^{K} C(K,n) * (-1)^{n-1} * sum_{m=1}^{n} C(n,m) * m! / (2*n^{m+1})
18 % For general k-stage Erlang, the formula involves k-fold convolution
19 % of exponential distributions.
21 % The Erlang distribution has mean k/mu and variance k/mu^2, giving
26 % Xmax = fj_xmax_erlang(K, k, mu)
31 % <tr><th>Name<th>Description
32 % <tr><td>K<td>Number of parallel servers (positive integer)
33 % <tr><td>k<td>Number of Erlang stages (positive integer,
default=2)
34 % <tr><td>mu<td>Rate parameter per stage (mean service time = k/mu)
39 % <tr><th>Name<th>Description
40 % <tr><td>Xmax<td>Expected maximum service time X_K^max
44 % A. Thomasian,
"Analysis of Fork/Join and Related Queueing Systems",
45 % ACM Computing Surveys, Vol. 47, No. 2, Article 17, July 2014.
48function Xmax = fj_xmax_erlang(K, k, mu)
51 k = 2; % Default to Erlang-2
55 line_error(mfilename, 'K must be a positive integer. Got K=%d.', K);
59 line_error(mfilename,
'k (number of stages) must be a positive integer. Got k=%d.', k);
63 line_error(mfilename,
'Rate mu must be positive. Got mu=%.4f.', mu);
66% For Erlang-2 (k=2), use the closed-form formula from the paper
68 % X_K^max = (1/mu) * sum_{n=1}^{K} C(K,n) * (-1)^{n-1} * sum_{m=1}^{n} C(n,m) * m! / (2*n^{m+1})
73 inner_sum = inner_sum + nchoosek(n, m) * factorial(m) / (2 * n^(m + 1));
75 outer_sum = outer_sum + nchoosek(K, n) * ((-1)^(n - 1)) * inner_sum;
77 Xmax = outer_sum / mu;
79 % For general k-stage Erlang, use numerical integration
80 % The CDF of Erlang-k
is: F(t) = 1 - exp(-mu*t) * sum_{j=0}^{k-1} (mu*t)^j / j!
81 % The expected max
is: X_K^max = integral_0^inf [1 - F(t)^K] dt
84 erlang_cdf = @(t) 1 - exp(-mu * t) .* sum_erlang_terms(mu * t, k);
86 % Integrand: 1 - F(t)^K
87 integrand = @(t) 1 - erlang_cdf(t).^K;
89 % Numerical integration (upper limit chosen based on Erlang mean and variance)
91 upper_limit = mean_erlang * 10 + 10 * sqrt(k) / mu; % Well beyond the tail
92 Xmax = integral(integrand, 0, upper_limit,
'RelTol', 1e-10,
'AbsTol', 1e-12);
97function S = sum_erlang_terms(x, k)
98% Helper function to compute sum_{j=0}^{k-1} x^j / j!
99% Handles both scalar and vector inputs
102 S = S + (x.^j) / factorial(j);