1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Stupid question about multinomial theorem (and Matlab)

  1. May 20, 2009 #1
    I know that there is a theorem to calculate the coefficients for a multinomial expansion, but I'm having a hard time implementig the algorithm. What I need to know is if my procedure is correct:

    [tex](A + B + C + D)^n = \sum_{i=0}^n \dbinom{n}{i} A^{n-i} (B + C + D)^i[/tex]

    [tex]= \sum_{i=0}^n \dbinom{n}{i} A^{n-i} \sum_{j=0}^i \dbinom{i}{j} B^{i-j} (C + D)^j[/tex]

    [tex]= \sum_{i=0}^n \dbinom{n}{i} A^{n-i} \sum_{j=0}^i \dbinom{i}{j} B^{i-j} \sum_{k=0}^j \dbinom{j}{k} C^{j-k} D^k,[/tex]


    [tex](A + B + C + D)^n = \sum_{i=0}^n \sum_{j=0}^{i} \sum_{k=0}^{j}\dfrac{n!}{(n-i)!(i-j)!(j-k)!k!} A^{n-i} B^{i-j} C^{j-k} D^k [/tex]

    Is that correct?

    If so, I'm trying to compute the coefficients in Matlab in the following way

    Code (Text):

    h = 1;
    for i = 1:n
         for j = 1:i
              for k = 1:j
                   coef(h,1) = factorial(n)/(factorial(n-i)*factorial(i-j)*factorial(j-k)*factorial(k))
                   h = h+1;
    so the vector coef contains the coefficients of the polynomial. What do you think? Is my approach correct or am I doing something wrong?
  2. jcsd
  3. May 20, 2009 #2


    User Avatar
    Science Advisor
    Homework Helper

    Hi AiRAVATA! :smile:
    Yes, though it's normally written for an individual component:

    coefficient of AaBbCcDd = n!/a!b!c!d! (with a + b + c + d = n) :wink:

    (I don't know anything about porgramming though :redface:)
  4. May 21, 2009 #3
    not being smart but should it not be:

    Code (Text):

    for i = [B]0[/B]:n
         for j = [B]0[/B]:i
              for k = [B]0[/B]:j
  5. May 21, 2009 #4
    True, in the real code they all start from zero. Thanks for noticing though!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Threads - Stupid question multinomial Date
Probably a stupid question regarding 4-dimensional space Jun 4, 2014
Prime factoring stupid question Jan 1, 2014
A stupid question about infinity Feb 21, 2012
Stupid simplification question Oct 19, 2011
A stupid question I think Oct 18, 2011