Permutations without overflow

版本 1.0.0 (1.2 KB) 作者: Lawrence Agbezuge
The use of the factorial function in computing permutations and combinations has overflow problems that are avoided by these two functions.
14.0 次下载
更新时间 2020/1/26

查看许可证

The use of the factorial function in computing nPr = n!/(n-r)! or in computing nCr = n!/((n-r)!*r!) has overflow problems when n>170 on a 64-bit machine.
These two functions: Perm(n,r) and Comb(n,r) avoid the overflow problem.
nPr is defined as Perm(n,r) and nCr is defined as Comb(n,r).

Example:
If n=171, factorial(n) = Inf on a 64-bit machine.
Therefore, neither P(171,15) nor C(171,15) can be evaluated directly.
Perm(171,15) = 1.6611e33, and
Comb(171,15) = 1.2703e21.
Likewise,
Perm(1000,49) = 3.0256e+146, and
Comb(171,15) = 4.9740e+83.

These two functions are useful in predicting the outcomes of Bernoulli experiments that utilize the binomial distribution.

引用格式

Lawrence Agbezuge (2024). Permutations without overflow (https://www.mathworks.com/matlabcentral/fileexchange/74033-permutations-without-overflow), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2019b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0