LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
MomentsFromMG.m
1% moms = MomentsFromMG(alpha, A, K, prec)
2%
3% Returns the first K moments of a matrix geometric
4% distribution.
5%
6% Parameters
7% ----------
8% alpha : vector, shape (1,M)
9% The initial vector of the matrix-geometric distribution.
10% The sum of the entries of alpha is less or equal to 1.
11% A : matrix, shape (M,M)
12% The matrix parameter of the matrix-geometric
13% distribution.
14% K : int, optional
15% Number of moments to compute. If K=0, 2*M-1 moments are
16% computed. The default value is 0.
17% prec : double, optional
18% Numerical precision for checking the input.
19% The default value is 1e-14.
20%
21% Returns
22% -------
23% moms : row vector of doubles
24% The vector of moments.
25%
26
27function moms = MomentsFromMG (alpha, A, K)
28
29 global BuToolsCheckInput;
30 if isempty(BuToolsCheckInput)
31 BuToolsCheckInput = true;
32 end
33
34 if BuToolsCheckInput && ~CheckMGRepresentation (alpha, A)
35 error('MomentsFromMG: Input isn''t a valid MG representation!');
36 end
37
38 if ~exist('K','var') || K==0
39 K = 2*length(alpha) - 1;
40 end
41
42 fmoms = zeros(1,K);
43 iA = inv(eye(size(A))-A);
44 for i=1:K
45 fmoms(i) = factorial(i) * sum(alpha*iA^i*A^(i-1));
46 end
47 moms = MomsFromFactorialMoms (fmoms);
48end
49