how to cope with big numbers out of the capability of matlab

2 views (last 30 days)
Dear Fellows,
I would like to calculate the probability mass function for the generalize binomial distribution. Basically I just need to add a extra parameter in the usual pmf function of binomial distribution. I attach the code here.
if true
% n=100;
p=0.5;
x=1:100;
nthetas=1.6 %the value of nthetas is starting from 1
C=x.*(100-x);
pmf_=binopdf(x,100,0.5).*(nthetas.^C); %add the dispense parameter to a usual binomial distribution pmf
z=sum(pmf_); %normalized constant
pmf=pmf_/z;
end
There is no problem when theta is equal to 1.2. But when it gets bigger, for example 1.6 as in the code. The probability gets too big to calculate and ends up as Inf. Do you know how to deal with this problem?
Thanks!

Accepted Answer

Star Strider
Star Strider on 23 May 2014
I suggest writing your own function, but using logarithms to do the calculations. That may not be as precise and you may not be able to take the antilogs in the end (they would likely be Inf). I don’t know how far you would get with logarithmic calculations, but converting the results from natural to base-10 logs in the end will give you the ability to get farther than you are now.
There could be something inherent in MATLAB’s calculations that would prohibit this approach, but it’s worth experimenting to find out.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!