Stupid question about multinomial theorem (and Matlab)

  • Context: MATLAB 
  • Thread starter Thread starter AiRAVATA
  • Start date Start date
  • Tags Tags
    Matlab Stupid Theorem
Click For Summary

Discussion Overview

The discussion revolves around the multinomial theorem and its implementation in Matlab. Participants are exploring the correct formulation of the multinomial expansion and the algorithm to compute the coefficients for the expansion.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant outlines a procedure for deriving the multinomial expansion and seeks validation of their approach.
  • Another participant confirms the correctness of the multinomial coefficient expression but notes that it is typically presented for individual components.
  • A third participant suggests that the loop indices in the Matlab code should start from zero instead of one.
  • The original poster acknowledges this correction regarding the loop indices in their code.

Areas of Agreement / Disagreement

Participants generally agree on the formulation of the multinomial expansion, but there are differing views on the implementation details in Matlab, particularly regarding loop indexing.

Contextual Notes

The discussion does not resolve whether the initial Matlab implementation is correct, as it focuses on the structure of the loops rather than the overall algorithm.

AiRAVATA
Messages
172
Reaction score
0
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]

so

[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:
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;
          end
     end
end

so the vector coef contains the coefficients of the polynomial. What do you think? Is my approach correct or am I doing something wrong?
 
Physics news on Phys.org
Hi AiRAVATA! :smile:
AiRAVATA said:
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 \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?

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:)
 
not being smart but should it not be:

Code:
for i = [B]0[/B]:n
     for j = [B]0[/B]:i
          for k = [B]0[/B]:j
 
True, in the real code they all start from zero. Thanks for noticing though!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 21 ·
Replies
21
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 0 ·
Replies
0
Views
2K