function M=multinom(N, n) % multinom(N, n) multinomial coefficient % % n is a row vector [n1, n2, n2....] where n1+n2+....=N % % for a matrix n, each row in n must sum to its corresponding value in % the row vector N - fill empty spaces with zeros if min(sum(n')==N)==0 error('n1+n2+... is not equal to N') end M=fact(N); F=prod(fact(n')); M=M./F;