LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
GeneralFluidSolve.m
1% [mass0, ini, K, clo] = GeneralFluidSolve (Q, R, Q0, prec)
2%
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).
8%
9% Using the returned 4 parameters the stationary
10% solution can be obtained as follows.
11%
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.
15%
16% The density that the fluid level is x while being in
17% different states of the background process is
18%
19% .. math::
20% \pi(x)=ini\cdot e^{K x}\cdot clo.
21%
22% Parameters
23% ----------
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
36%
37% Returns
38% -------
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
47
48function [mass0, ini, K, clo] = GeneralFluidSolve (Q, R, Q0, prec)
49
50 if ~exist('prec','var')
51 prec = 1e-14;
52 end
53
54 if ~exist('Q0','var')
55 Q0 = [];
56 end
57
58 N = size(Q,1);
59
60 % partition the state space according to zero, positive and negative fluid rates
61 ix = (1:N);
62 ixz = ix(abs(diag(R))<=prec);
63 ixp = ix(diag(R)>prec);
64 ixn = ix(diag(R)<-prec);
65 Nz = length(ixz);
66 Np = length(ixp);
67 Nn = length(ixn);
68
69 % permutation matrix that converts between the original and the partitioned state ordering
70 P = zeros(N);
71 for i=1:Nz
72 P(i,ixz(i))=1;
73 end
74 for i=1:Np
75 P(Nz+i,ixp(i))=1;
76 end
77 for i=1:Nn
78 P(Nz+Np+i,ixn(i))=1;
79 end
80 iP = inv(P);
81
82 % reorder states with permutation matrix P: 0, +, -
83 Qv = P*Q*iP;
84 Rv = P*R*iP;
85
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))));
90 Qz = absRi * Qbar;
91
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);
94
95 % closing matrix
96 Pm = [eye(Np), Psi];
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];
100
101 if isempty(Q0) % regular boundary behavior
102
103 clo = clo * P; % go back the the original state ordering
104
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]')';
108
109 % create the result
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);
112 else
113
114 % solve a linear system for ini(+), pm(-) and pm(0)
115 Q0v = P*Q0*iP;
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]')';
119 ini = sol(1:Np);
120 clo = clo * P;
121 mass0 = [sol(Np+Nn+1:end), zeros(1,Np), sol(Np+1:Np+Nn)]*P;
122 end
123end