Code covered by the BSD License  

Highlights from
PoissRatioCdf

image thumbnail
from PoissRatioCdf by Viktor Witkovsky
Computes the cdf and/or the pmf of the ratio of two independent Poisson random variables

SetValuesX(lambdaNum,lambdaDen,constant,stdTol,N)
function x = SetValuesX(lambdaNum,lambdaDen,constant,stdTol,N)
% Set the best N rational numbers as possible outcomes of the qoutient of
% two Poisson random variables with intensities lambdaNum and lambdaDen
% Q = constant * Y_lambdaNum / Y_lambdaDen
%
% Syntax
% x = SetValuesX(lambdaNum,lambdaDen,constant,N,stdTol)
%
% See also: PoissRatioCdf, PoissRatioPmf
%
% References:
% ARENDACK, B. - SCHWARZ, K. - TOLC JR, S. - WIMMER, G. - WITKOVSK, V.:
% Variability issues in determining concentration of isoprene in human
% breath by PTR-MS. Journal of Breath Research 2, 2008, 037007 (8pp),
% doi:10.1088/1752-7155/2/3/037007

% (c) Viktor Witkovsky (witkovsky@savba.sk)
% Revised: 14-Nov-2009 15:36:29

%% Check the inputs

if nargin < 4
    N  = 1000;
end

if nargin < 3
    stdTol = 3;
end

if nargin < 2
    constant = 1;
end

if nargin < 2 || nargin > 5,
    error('VW:SetValuesX:TooFewInputgas','Requires two input arguments.');
end

%% Set the range based on multiple (stdTol) of standard deviation(s)
stdNum = ceil(sqrt(lambdaNum));
lowNum = max(0,lambdaNum - stdTol * stdNum);
uppNum = lambdaNum + stdTol * stdNum;
stdDen = ceil(sqrt(lambdaDen));
lowDen = max(1,lambdaDen - stdTol * stdDen);
uppDen = lambdaDen + stdTol * stdDen;
indNum = lowNum:uppNum;
indDen = lowDen:uppDen;
[x,i,j] = unique(kron(indNum',1./indDen));
if length(x) > N
    jSort=sort(j);
    [jSortUnique,iInd] = unique(jSort);
    [iInddiff,iSort] = sort(diff([0;iInd]),'descend');
    ind = iSort(1:N);
    x = sort(x(jSort(iInd(ind))));
end
[num,den] = rat(x,1.e-6);
x = unique(num ./ den);
x = constant * x;

Contact us at files@mathworks.com