Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica code for multinomial expansion

  1. Apr 11, 2015 #1
    Hello,

    I m looking for a mathematica code for the multinomial expansion of the general case of (let's say m sum terms given in a power of n), e.g., the code for the 1st equation in http://en.wikipedia.org/wiki/Multinomial_theorem

    Any help would be useful.

    Thanks
     
  2. jcsd
  3. Apr 13, 2015 #2

    DrClaude

    User Avatar

    Staff: Mentor

    I'm not sure I understand what you want. Do you mean you want code that, given ##m## and ##n##, returns the expanded product? Or you want the multinomial coefficients?
     
  4. Apr 13, 2015 #3
    Hello,

    First, thank you for replying. I m interested to deriving the whole expanded formula not just the multinomial coefficient, since the latter can be straightforwardly returned via the corresponding mathematica command "multinomial"

    Is there a way to build an efficient code for multinomial expansion for the general case ?
     
  5. Apr 13, 2015 #4

    DrClaude

    User Avatar

    Staff: Mentor

    I'm still not sure what you want. When you have such a question, it is good to explain clearly what the input to the function is, and what you want to get out.

    Is this what you are looking for?
    Code (Text):

    multi[m_, n_] := Expand[Sum[Subscript[x, i], {i, 1, m}]^n]
     
     
  6. Apr 13, 2015 #5
    The expand command does the job, but i want to further elaborate on the product terms (powered to the corresponding multinomial coefficients).

    In particular, i want to express the following general form: ∑^{L}_{p1,p2,...,pn=0 && p1+p2+...+pn=L} f(x)^{p1+p2+...+pn}. There is a code for a certain case (see bellow) but how can i generalize it ?

    x = 0; For[k1 = 0, k1 <= 2, k1++,
    For[k2 = 0, k2 <= 2, k2++,
    For[k3 = 0, k3 <= 2, k3++,
    If[k1 + k2 + k3 == 2,
    x = x + Multinomial[k1, k2, k3]*
    x1^k1*x2^k2*x3^k3];
    If[k1 == 2 && k2 == 2 && k3 == 2, Print[x]]]]]
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Mathematica code for multinomial expansion
  1. Principia mathematica (Replies: 11)

  2. Problem with Mathematica (Replies: 11)

  3. Series expansion (Replies: 1)

Loading...