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

1 回表示 (過去 30 日間)
xueqi
xueqi 2014 年 5 月 22 日
回答済み: Star Strider 2014 年 5 月 23 日
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!

採用された回答

Star Strider
Star Strider 2014 年 5 月 23 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by