% MGD file mgd.m Moment generating function for compound demand % Version of 5/19/97 % Uses m-functions csort, mgsum disp('Do not forget zeros coefficients for missing') disp('powers in the generating function for N') disp(' ') g = input('Enter COEFFICIENTS for gN '); y = input('Enter VALUES for Y '); p = input('Enter PROBABILITIES for Y '); n = length(g); % Initialization a = 0; b = 1; D = a; PD = g(1); for i = 2:n [a,b] = mgsum(y,a,p,b); D = [D a]; PD = [PD b*g(i)]; [D,PD] = csort(D,PD); end r = find(PD>1e-13); D = D(r); % Values with positive probability PD = PD(r); % Corresponding probabilities mD = [D; PD]'; % Display details disp('Values are in row matrix D; probabilities are in PD.') disp('To view the distribution, call for mD.')