1% [mass0, ini, K, clo] = GeneralFluidSolve (Q, R, Q0, prec)
3% Returns the parameters of the matrix-exponentially
4% distributed stationary distribution of a general
5% Markovian fluid model, where the fluid rates associated
6% with the states of the background process can be
7% arbitrary (zero
is allowed as well).
9% Using the returned 4 parameters the stationary
10% solution can be obtained as follows.
12% The probability that the fluid level
is zero
while
13% being in different states of the background process
14%
is given by vector mass0.
16% The density that the fluid level
is x
while being in
17% different states of the background process
is
20% \pi(x)=ini\cdot e^{K x}\cdot clo.
24% Q : matrix, shape (N,N)
25% The generator of the background Markov chain
26% R : diagonal matrix, shape (N,N)
27% The diagonal matrix of the fluid rates associated
28% with the different states of the background process
29% Q0 : matrix, shape (N,N), optional
30% The generator of the background Markov chain at
31% level 0. If not provided, or empty, then Q0=Q
is
32% assumed. The
default value
is empty.
33% precision : double, optional
34% Numerical precision
for computing the fundamental
35% matrix. The
default value
is 1e-14
39% mass0 : matrix, shape (1,Np+Nm)
40% The stationary probability vector of zero level
41% ini : matrix, shape (1,Np)
42% The initial vector of the stationary density
43% K : matrix, shape (Np,Np)
44% The matrix parameter of the stationary density
45% clo : matrix, shape (Np,Np+Nm)
46% The closing matrix of the stationary density
48function [mass0, ini, K, clo] = GeneralFluidSolve (Q, R, Q0, prec)
50 if ~exist(
'prec',
'var')
60 % partition the state space according to zero, positive and negative fluid rates
62 ixz = ix(abs(diag(R))<=prec);
63 ixp = ix(diag(R)>prec);
64 ixn = ix(diag(R)<-prec);
69 % permutation matrix that converts between the original and the partitioned state ordering
82 % reorder states with permutation matrix
P: 0, +, -
86 % new fluid process censored to states + and -
87 iQv00 = pinv(-Qv(1:Nz,1:Nz));
88 Qbar = Qv(Nz+1:end, Nz+1:end) + Qv(Nz+1:end,1:Nz)*iQv00*Qv(1:Nz,Nz+1:end);
89 absRi = diag(abs(1./diag(Rv(Nz+1:end,Nz+1:end))));
92 % calculate fundamental matrices
93 [Psi, K, U] = FluidFundamentalMatrices (Qz(1:Np,1:Np), Qz(1:Np,Np+1:end), Qz(Np+1:end,1:Np), Qz(Np+1:end,Np+1:end), 'PKU', prec);
97 iCn = absRi(Np+1:end,Np+1:end);
98 iCp = absRi(1:Np,1:Np);
99 clo = [(iCp*Qv(Nz+1:Nz+Np,1:Nz)+Psi*iCn*Qv(Nz+Np+1:end,1:Nz))*iQv00, Pm*absRi];
101 if isempty(Q0) % regular boundary behavior
103 clo = clo *
P; % go back the the original state ordering
105 % calculate boundary vector
106 Ua = iCn*Qv(Nz+Np+1:end,1:Nz)*iQv00*ones(Nz,1) + iCn*ones(Nn,1) + Qz(Np+1:end,1:Np)*inv(-K)*clo*ones(Nz+Np+Nn,1);
107 pm = linsolve ([U,Ua]', [zeros(1,Nn),1]')';
110 mass0 = [pm*iCn*Qv(Nz+Np+1:end,1:Nz)*iQv00, zeros(1,Np), pm*iCn]*
P;
111 ini = pm*Qz(Np+1:end,1:Np);
114 % solve a linear system for ini(+), pm(-) and pm(0)
116 M = [-clo*Rv; Q0v(Nz+Np+1:end,:); Q0v(1:Nz,:)];
117 Ma = [sum(inv(-K)*clo,2); ones(Nz+Nn,1)];
118 sol = linsolve ([M,Ma]', [zeros(1,N),1]')';
121 mass0 = [sol(Np+Nn+1:end), zeros(1,Np), sol(Np+1:Np+Nn)]*
P;