LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
LevelDependentFluidStationaryDistr.m
1% res = LevelDependentFluidStationaryDistr (masses, iniF, KF, cloF, iniB, KB, cloB, what, points)
2% calculates the startionary distribution of first order and second order
3% level dependent fluid models
4%
5% * masses: list of masses (K+1 vectors, if there are K levels)
6% * iniF, KF, cloF: initial vector, matrix exponent and closing vector for
7% the forward direction for each level, a list of size K
8% * iniB, KB, cloB: initial vector, matrix exponent and closing vector for
9% the backward direction for each level, a list of size K
10% * what: string, can be 'pdf', 'cdf' and 'cdfm'
11% - 'pdf' returns the (state-dependent) density for each point
12% - 'pdfd' returns the derivative of the density
13% - 'cdf' returns the distribution function, P(X<p)
14% - 'cdfm' returns the distribution function, P(X<=p)
15%
16function res = LevelDependentFluidStationaryDistr (masses, iniF, KF, cloF, iniB, KB, cloB, T, what, points)
17
18 K = length(T);
19 T = [0 T];
20 N = length(masses{1});
21
22 function KAi = integExp(KA,L)
23 l=CRPSolve(KA);
24 r=CRPSolve(KA')';
25 l=l/(l*r);
26 KAi = inv(-(KA-r*l)) *(eye(size(KA,1))-expm((KA-r*l)*L)) + r*l*(L+exp(-L)-1);
27 end
28
29 function [KAi,KBi] = integExp2(KA,KB,L)
30 if min(abs(eig(KA))) > min(abs(eig(KB)))
31 KAi = inv(-KA)*(eye(size(KA,1))-expm(KA*L));
32 KBi = integExp(KB, L);
33 else
34 KAi = integExp(KA, L);
35 KBi = inv(-KB)*(eye(size(KB,1))-expm(KB*L));
36 end
37 end
38
39 cummulate = strcmp(what,'cdf') || strcmp(what,'cdfm');
40 res = [];
41 for p=points
42 pres = zeros(1,N);
43 k=0;
44 while k<K && p>=T(k+1)
45 if cummulate
46 if k>0
47 [sumKF, sumKB] = integExp2(KF{k}, KB{k}, T(k+1)-T(k));
48 val = iniF{k}*sumKF*cloF{k} + iniB{k}*sumKB*cloB{k};
49 pres = pres + val;
50 end
51 if p>T(k+1) || strcmp(what,'cdfm')
52 pres = pres + masses{k+1};
53 end
54 end
55 k = k + 1;
56 end
57 if k==K && p==T(k+1) && strcmp(what,'cdfm')
58 pres = pres + masses{k+1};
59 end
60 prem = p - T(k);
61 Tk = T(k+1)-T(k);
62 if strcmp(what,'pdf')
63 pres = iniF{k}*expm(KF{k}*prem)*cloF{k} + iniB{k}*expm(KB{k}*(Tk-prem))*cloB{k};
64 elseif strcmp(what,'pdfd')
65 pres = iniF{k}*KF{k}*expm(KF{k}*prem)*cloF{k} - iniB{k}*KB{k}*expm(KB{k}*(Tk-prem))*cloB{k};
66 elseif strcmp(what,'cdf') || strcmp(what,'cdfm')
67 [sumKF, sumKB] = integExp2(KF{k}, KB{k}, prem);
68 pres = pres + iniF{k}*sumKF*cloF{k} + iniB{k}*expm(KB{k}*(Tk-prem))*sumKB*cloB{k};
69 end
70 res = [res; pres];
71 end
72end
73
Definition Station.m:245