1
$\begingroup$

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$,

enter image description here

$$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.

$\endgroup$

1 Answer 1

2
$\begingroup$

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

enter image description here

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.

$\endgroup$
2
  • $\begingroup$ The result is precise and accurate... Thank you, I am very grateful to you... I wish I could ask you more questions. $\endgroup$ Commented Aug 6 at 16:34
  • $\begingroup$ @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 :) $\endgroup$
    – Domen
    Commented Aug 6 at 16:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.