LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
qbd_finite_solve.m
1function [pi, L] = qbd_finite_solve(A_minus, A_0, A_plus, N)
2% QBD_FINITE_SOLVE Stationary distribution of a finite-capacity QBD process.
3%
4% [PI, L] = QBD_FINITE_SOLVE(A_MINUS, A_0, A_PLUS, N)
5%
6% Solves a homogeneous finite-capacity QBD with buffer size N.
7% The generator has the block-tridiagonal structure:
8%
9% Q = [ B_0 A_plus ]
10% [ A_minus A_0 A_plus ]
11% [ A_minus A_0 A_plus ]
12% [ ... ... ... ]
13% [ A_minus B_N ]
14%
15% where B_0 = A_0 + A_minus (absorption of downward transitions at 0)
16% and B_N = A_0 + A_plus (absorption of upward transitions at N).
17%
18% Uses block LDU elimination (forward reduction + back substitution)
19% to solve pi*Q = 0, sum(pi) = 1 in O(N*m^3) time where m is the
20% phase dimension.
21%
22% Inputs:
23% A_minus - m x m sub-diagonal block (downward transitions)
24% A_0 - m x m diagonal block (internal transitions, negative diagonal)
25% A_plus - m x m super-diagonal block (upward transitions)
26% N - buffer capacity (levels 0, 1, ..., N)
27%
28% Outputs:
29% pi - cell array of length N+1, pi{k+1} is the 1 x m
30% stationary probability vector at level k
31% L - mean number in system (sum over k of k * sum(pi{k+1}))
32%
33% Copyright (c) 2026, Imperial College London. BSD 3-Clause License.
34
35m = size(A_0, 1);
36
37% Boundary blocks
38B_0 = A_0 + A_minus; % level 0: no downward transitions
39B_N = A_0 + A_plus; % level N: no upward transitions
40
41% Forward reduction (block Gaussian elimination)
42% Eliminate sub-diagonal: transform Q into upper block-bidiagonal form.
43% F{k} stores the modified diagonal block at level k.
44% G{k} stores the super-diagonal block at level k.
45F = cell(N + 1, 1);
46G = cell(N + 1, 1);
47
48F{1} = B_0;
49G{1} = A_plus;
50
51for k = 1:N-1
52 % Multiplier: A_minus * inv(F{k})
53 M = A_minus / F{k};
54 F{k + 1} = A_0 - M * A_plus;
55 G{k + 1} = A_plus;
56end
57
58% Last level
59if N > 0
60 M = A_minus / F{N};
61 F{N + 1} = B_N - M * A_plus;
62else
63 F{1} = A_0; % single level, no transitions possible
64end
65
66% Solve pi * [upper bidiagonal] = 0 with normalization.
67% Last level: pi_N is in the left null space of F{N+1}.
68% Replace first column of F{N+1}' with normalization placeholder,
69% then back-substitute.
70
71% Find pi_N from the nullspace of F{N+1}
72% pi_N * F{N+1} = 0 => F{N+1}' * pi_N' = 0
73[~, ~, V] = svd(F{N + 1}.');
74pi_N = V(:, end).';
75pi_N = pi_N / sum(pi_N); % temporary normalization
76
77% Back substitution: pi_{k} * F{k} + pi_{k+1} * A_minus = 0
78% => pi_{k} = -pi_{k+1} * A_minus * inv(F{k})
79pi = cell(N + 1, 1);
80pi{N + 1} = pi_N;
81
82for k = N:-1:1
83 pi{k} = -pi{k + 1} * A_minus / F{k};
84end
85
86% Normalize so that sum of all probabilities = 1
87total = 0;
88for k = 1:(N + 1)
89 total = total + sum(pi{k});
90end
91for k = 1:(N + 1)
92 pi{k} = pi{k} / total;
93end
94
95% Mean number in system
96L = 0;
97for k = 1:(N + 1)
98 L = L + (k - 1) * sum(pi{k});
99end
100end