Multinomial Expansion in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Expansion Mathematica
Click For Summary

Discussion Overview

The discussion revolves around programming the multinomial expansion in Mathematica. Participants explore how to implement the mathematical concept of multinomial expansion, particularly focusing on the summation of nonnegative integer indices and the use of Mathematica functions to achieve this.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant presents the multinomial expansion formula and seeks assistance in programming it in Mathematica.
  • Another participant expresses confusion about the initial request and asks for clarification on the intended outcome.
  • A participant describes their specific case involving exponentials and integration, indicating a need for a more complex implementation than the standard Expand function.
  • One participant shares their progress using nested loops to compute the multinomial expansion for a specific case and seeks advice on generalizing the solution for variable numbers of terms and exponents.
  • Another participant suggests using an odometer-like approach or the Cartesian product of sets to handle variable numbers of terms, implying that there may be built-in functions in Mathematica to assist with this.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to implement the multinomial expansion in Mathematica, with differing opinions on the utility of the Expand function and the complexity of the task at hand.

Contextual Notes

Some participants express uncertainty regarding the effectiveness of the Expand function for their specific needs, indicating that the problem may involve more complex mathematical operations than initially presented.

EngWiPy
Messages
1,361
Reaction score
61
Hello,

I have the following equation, which is simply the multinomial exapnsion:

[tex]\left[\sum_{l=1}^L\,x_l\right]^n=\sum_{k_1,k_2,\ldots,k_L}{n\choose k_1,k_2,\ldots,k_L}\prod_{l=1}^L\,x_l^{k_l}[/tex]

where the summation is taken over all possibilities that the summation of the nonnegative integer indices k1,k2,...,kL equal n.

How can I program this using Mathematica??

Thanks in advance
 
Physics news on Phys.org
Any suggestion please? I am really need this. Any help will be greatly appreciated.
 
It really isn't clear what you want to do.
 
Hurkyl said:
It really isn't clear what you want to do.

Ok, first of all, thank you for replying. What I want to do is to write a function using Mathematica that computes the multinomial expansion, which is the right hand side equation in the first post. The difficulty as I see it, comes from the summation. For example:

[tex](x_1+x_2+x_3)^2=\underbrace{\sum_{k_1,k_2,k_3}{2\choose k_1,k_2,k_3}\prod_{n=1}^{3}x_n^{k_n}}_{\text{Multinomial Expansion}}[/tex]

where the summation in the right hand side takes place over all possibilities that [tex]k_1+k_2+k_3=2[/tex], and
[tex]\left(\begin{smallmatrix}2\\k_1,k_2,k_2\end{smallmatrix}\right)=\frac{2!}{k_1!\,k_2!\,k_3!}[/tex]

Doing that yields to the final result:

[tex](x_1+x_2+x_3)^2=x_1^2+x_2^2+x_3^2+2x_1x_2+2x_1x_3+2x_2x_3[/tex]


I hope that I explain the point.

Regards
 
What's wrong with the Expand function?
 
Hurkyl said:
What's wrong with the Expand function?

The problem is that, the multinomial I have looks like this:

[tex]\left[\sum_{n=1}^NA_n\,\tex{e}^{-\gamma/\gamma_n}\right]^m[/tex]

I want to exctract the exponentials and combine them with other exponentials and integrate them all over [tex]\gamma[/tex] to do my derivation for the performance metrics.
 
So far I reached to this point:

Code:
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]]]]]

x1^2+2 x1 x2+x2^2+2 x1 x3+2 x2 x3+x3^2

But how can I write it in general form, when the number of terms and the exponent are variables?
 
I'm still not sure why you think this will result in anything different than the expand function...


When the number of loops is variable, you essentially have to implement an odometer -- e.g. as a list whose n-th element is the value of the n-th variable. Then you have just one for loop that initializes / steps this odometer.


It might be easier, however, to construct the m-fold Cartesian product of the set {0, 1, ..., N} with itself. There is surely a builtin function to compute Cartesian products of lists, and it should be easy enough to use that to write a function that iterates it m times. But I don't have mathematica on my home computer to tell you what that function would be.

(The Cartesian product of A with B is the set AxB whose elements are all length-2 lists whose first element is from A and whose second element is from B)
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 0 ·
Replies
0
Views
2K
Replies
3
Views
7K
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K