% MULTINOM file multinom.m Multinomial distribution % Version of 8/24/96 % Multinomial distribution (small N, m) N = input('Enter the number of trials '); m = input('Enter the number of types '); p = input('Enter the type probabilities '); M = 1:m; T = zeros(m^N,N); for i = 1:N a = rowcopy(M,m^(i-1)); a = a(:); a = colcopy(a,m^(N-i)); T(:,N-i+1) = a(:); % All possible strings of the types end MT = zeros(m^N,m); for i = 1:m MT(:,i) = sum(T'==i)'; end clear T % To conserve memory disp('String frequencies for type k are in column matrix MT(:,k)') P = zeros(m^N,N); for i = 1:N a = rowcopy(p,m^(i-1)); a = a(:); a = colcopy(a,m^(N-i)); P(:,N-i+1) = a(:); % Strings of type probabilities end PS = prod(P'); % Probability of each string clear P % To conserve memory disp('String probabilities are in row matrix PS')