function [z,pz] = mgsumn(varargin) % MGSUMN [z,pz] = mgsumn([x1;p1],[x2;p2], ..., [xn;pn]) % Version of 6/2/97 Uses MATLAB version 5.1 % Sum of n independent simple random variables % Utilizes distributions in the form [x;px] (two rows) % Iterates mgsum n = length(varargin); % The number of distributions z = 0; % Initialization pz = 1; for i = 1:n % Repeated use of mgsum [z,pz] = mgsum(z,varargin{i}(1,:),pz,varargin{i}(2,:)); end