Mathematica code for multinomial expansion

In summary, the conversation is about finding a Mathematica code for the multinomial expansion of a given number of sum terms raised to a power. The first speaker is looking for help in deriving the expanded formula, while the second speaker is asking for clarification on the desired output. The first speaker then provides a code that partially solves the problem, but is looking for a way to generalize it.
  • #1
nikozm
54
0
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
 
Physics news on Phys.org
  • #2
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?
 
  • #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 ?
 
  • #4
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:
multi[m_, n_] := Expand[Sum[Subscript[x, i], {i, 1, m}]^n]
 
  • #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]]]]]
 

Related to Mathematica code for multinomial expansion

1. How do I use Mathematica to expand a multinomial expression?

To expand a multinomial expression, you can use the Expand function in Mathematica. Simply input the expression you want to expand and the function will return the expanded form. For example, Expand[(x+y+z)^3] will return x^3 + 3x^2y + 3x^2z + 3xy^2 + 6xyz + 3xz^2 + y^3 + 3y^2z + 3yz^2 + z^3.

2. Can Mathematica expand multinomial expressions with variables raised to fractional powers?

Yes, Mathematica can expand multinomial expressions with variables raised to fractional powers. For example, Expand[(x^(1/2)+y^(1/3))^2] will return x + 2x^(1/2)y^(1/3) + y^(2/3).

3. Is there a limit to the number of terms in a multinomial expansion that Mathematica can handle?

Mathematica can handle an unlimited number of terms in a multinomial expansion. However, the more terms there are, the longer it may take for Mathematica to compute the expansion.

4. Can I specify the order of the expanded terms in Mathematica?

Yes, you can specify the order of the expanded terms in Mathematica using the MonomialOrder option. This option allows you to choose from several different types of monomial ordering, such as Lexicographic, GradedLexicographic, and EliminationOrder.

5. How can I check if my multinomial expansion in Mathematica is correct?

You can use the Expand function to expand the expression manually and compare it to the result from Mathematica. Additionally, you can use the FullSimplify function to simplify the expanded expression and see if it matches the original expression. If the two expressions are equivalent, then your multinomial expansion is correct.

Similar threads

Replies
3
Views
992
  • Calculus
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
704
  • Programming and Computer Science
Replies
6
Views
1K
  • Quantum Physics
Replies
5
Views
849
  • Advanced Physics Homework Help
Replies
1
Views
786
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Calculus
Replies
2
Views
2K
Back
Top