1function h = map_m1ps_h_recursive(C, D, mu, N, K)
2% MAP_M1PS_H_RECURSIVE Recursive computation of h_{n,k} coefficients
4% h = MAP_M1PS_H_RECURSIVE(C, D, mu, N, K) computes the h_{n,k} vectors
5% used in the sojourn time distribution
for a MAP/M/1-PS queue.
7% The h_{n,k} vectors satisfy the recursion (Theorem 1 in paper):
8% h_{n,0} = e (vector of ones), for n = 0, 1, ...
9% h_{n,k+1} = 1/(theta+mu) * [n*mu/(n+1) * h_{n-1,k} + (theta*I + C) * h_{n,k}
11% where h_{-1,k} = 0 for all k
14% C - M x M matrix governing MAP transitions without arrivals
15% D - M x M matrix governing MAP transitions with arrivals
16% mu - Service rate (scalar)
17% N - Maximum value of n to compute (determines rows)
18% K - Maximum value of k to compute (determines columns)
21% h - Cell array of size (N+1) x (K+1)
22% h{n+1, k+1} contains the M x 1 vector h_{n,k}
23% (indices shifted by 1 for MATLAB 1-based indexing)
26% Masuyama, H., & Takine, T. (2003). Sojourn time distribution in a
27% MAP/M/1 processor-sharing queue. Operations Research Letters, 31(6),
30% See also: MAP_M1PS_SOJOURN, MAP_COMPUTE_R
32% Copyright (c) 2012-2025, Imperial College London
39% Compute theta (uniformization parameter)
40theta = max(abs(diag(C)));
42% Pre-compute constant matrices
43theta_plus_mu = theta + mu;
44theta_I_plus_C = theta * I + C;
46% Initialize cell array to store h_{n,k}
47% h{n+1, k+1} stores h_{n,k} (shift indices by 1)
50% Base
case: h_{n,0} = e
for all n
55% Recursive computation: fill column by column (increasing k)
58 % Compute h_{n,k+1}
using the recursion formula
59 % h_{n,k+1} = 1/(theta+mu) * [n*mu/(n+1) * h_{n-1,k}
60 % + (theta*I + C) * h_{n,k}
64 term2 = theta_I_plus_C * h{n+1, k+1};
67 % First term: n*mu/(n+1) * h_{n-1,k}
69 term1 = (n * mu / (n + 1)) * h{n, k+1};
72 % Third term: D * h_{n+1,k}
74 term3 = D * h{n+2, k+1};
77 h{n+1, k+2} = (term1 + term2 + term3) / theta_plus_mu;