I have been given a binomial distribution: $$B(m+n;n,p)=\frac{(m+n)!}{m!n!}p^mq^n.$$
Here $m = 10^3$, $n=10^2$, $p=10^{-2}$, $q=1-p.$
I'm using MATLAB to compute log $B(m+n;n,p)$ and store the value in logB
m=10^3;
n=10^2;
p=10^(-2);
q=1-p;
logB=log(factorial(m+n)/(factorial(m)*factorial(n))*p^m*q^n)
I get logB as NaN . How can I modify the formula to avoid floating point error and get a valid answer?