% MULTINOMIAL_COEFFICIENT % % Lecture 5B example: multinomial_coefficient(10, [4 4 2]) = 3150 % function c = multinomial_coefficient(n, kk) % The simplest way would be % c = factorial(n) / prod(factorial(kk)); % But because the intermediate results can be very big, % we use logarithms and the gamma function logc = gammaln(n+1) - sum(gammaln(kk+1)); c = round(exp(logc));