# Applying the binomial distribution to matrix data

The probability that a random variable $$X$$ with binomial distribution $$B(n,p)$$ is equal to the value $$k$$, where $$k = 0, 1,\dots,n$$. If we have the $$(n\times m)$$matrix and $$N_j$$,

$$f(x)= 1/2 \binom{3}{1} (1-x)^{2}x^1 \binom{2}{2} (1-x)^{0}x^2 \binom{3}{0} (1-x)^{3}x^0+ 1/4 \binom{3}{2} (1-x)^{1}x^2 \binom{2}{0} (1-x)^{2}x^0 \binom{3}{3} (1-x)^{0}x^3+ {1/9} \binom{3}{0} (1-x)^{3}x^0 \binom{2}{1} (1-x)^{1}x^1 \binom{3}{1} (1-x)^{2}x^1$$

My attempts using the Mathematica:

mat = {{1, 2, 0, 1/2}, {2, 0, 3, 1/4}, {0, 1, 1, 1/9}};
n1 = 3;
n2 = 2;
n3 = 3;


The solution was found, but manually using some functions:

mat[[1, 4]] Binomial[n1, mat[[1, 1]]] (1 - x)^{n1 - mat[[1, 1]]} (x)^mat[[1, 1]] Binomial[n2,mat[[1, 2]]] (1 - x)^{n2 - mat[[1, 2]]} (x)^mat[[1, 2]] Binomial[n3,mat[[1, 3]]] (1 - x)^{n3 - mat[[1, 3]]} (x)^mat[[1, 3]]


If the size of the matrix is larger, the solution will be difficult. Is there an automatic code that works in general?

I searched in previous answers and did not find a similar case.

Wolfram Language allows you to literally retype your formula in a notebook in a mathematical notation:

f[k_, nn_, x_] := Module[{n, m},
{n, m} = Dimensions[k];
Sum[k[[i, m]]*Product[Binomial[nn[[j]], k[[i, j]]] *
(1 - x)^(nn[[j]] - k[[i, j]])*
x^k[[i, j]], {j, 1, m - 1}], {i, 1, n}]
]

mat = {{1, 2, 0, 1/2}, {2, 0, 3, 1/4}, {0, 1, 1, 1/9}};
nn = {3, 2, 3};
f[mat, nn, x]


$$\frac{3}{4} x^5 (1-x)^3+\frac{3}{2} x^3 (1-x)^5+\frac{2}{3} x^2 (1-x)^6$$

My result is different than yours, so I might misunderstood something. Please look at my code, and I am sure you will be able to fix it.

• The result is precise and accurate... Thank you, I am very grateful to you... I wish I could ask you more questions. Commented Aug 6 at 16:34
• @Math-babylon, if you have some more specific questions related to this, you can ask here. If you have some other question, you are always welcome to post a new question on the site :) Commented Aug 6 at 16:35