binomfactors
Every once in a while someone wishes to compute a VERY large binomial coefficient. While I'll admit that most of the time the proper solution is to compute the log of the coefficient. The best solution for this is to use gammaln.
n = 20000000;
k = 5000000;
gammaln(n+1) - gammaln(k+1) - gammaln(n-k+1)
ans =
11246694.4048045
Once in a rare while someone might wish to compute the integer factors of this coefficient. I've now had two recent occasions to look for such a factorization, so I assume there must be someone else in the world who has a use for them too.
tic,[facs,count] = binomfactors(20000000,5000000);toc
Elapsed time is 43.071204 seconds.
We can verify the result by computing the log of the binomial coefficient from the factors. See that it is identical to that returned from gammaln above.
sum(log(facs).*count)
ans =
11246694.404804
How many digits are in this number?
sum(log(facs).*count)/log(10)
ans =
4884377.31965857
I did say it was large, with approximately 4.8 million digits.
So, for that rare person who wishes to compute the factors of a binomial coefficient, binomfactors does exactly that. Or, if all you wish to see are some ideas on how one might design a prime sieve for such a computation in MATLAB, this might be of some interest.
(Note that while this tool is used in my vpi toolbox, it does not require vpi to run.)
引用格式
John D'Errico (2024). binomfactors (https://www.mathworks.com/matlabcentral/fileexchange/26702-binomfactors), MATLAB Central File Exchange. 检索来源 .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
- AI, Data Science, and Statistics > Statistics and Machine Learning Toolbox > Probability Distributions > Discrete Distributions > Negative Binomial Distribution >
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0.0 |