Efficient Matlab implementation of Multinomial Coefficient

后端 未结 4 842
栀梦
栀梦 2021-02-11 07:35

I want to calculate the multinomial coefficient:

\"enter

where it is satisifed

4条回答
  •  长发绾君心
    2021-02-11 07:59

    using the tip provided by @jemidiah,

    and here is the code

    function c = multicoeff (k), 
        c = 1; 
        for i=1:length(k), 
          c = c* bincoeff(sum(k(1:i)),k(i)); 
        end; 
    end
    

    and some usage examples:

    octave:88> multicoeff([2 2 2])
    ans =  90
    octave:89> factorial(6)/(factorial(2)*factorial(2)*factorial(2))
    ans =  90
    octave:90> multicoeff([5 4 3])
    ans =  27720
    octave:91> factorial(12)/(factorial(5)*factorial(4)*factorial(3))
    ans =  27720
    

提交回复
热议问题