FACTORIALRATIO

版本 1.4.0.0 (2.8 KB) 作者: Jos (10584)
Ratio of factorials, as in (a!b!c!...) / (d!e!f!g!...) (version 2.0, oct 2012)
1.9K 次下载
更新时间 2012/10/25

查看许可证

FACTORIALRATIO - ratio of factorial numbers

FR = FACTORIALRATIO (A,B) calculates the ratio between products of
factorials specified by A and B. A and B are lists of positive
integers, with N and M elements, respectively. The number of values in
each list may differ. The factorial ratio is based on the following formula:

(A1! * A2! * ... * AN!)
FR = -------------------------
(B1! * B2! * ... * BM!)

However, an approach is taken that increases the accuracy when A or B
contain larger values, as mentioned in the help of FACTORIAL.

Examples:

f1 = factorialratio([10 8 6],[9 6 5]) ;
f2 = 10 * 8 * 7 * 6 ; % by hand
f3 = (factorial(10) * factorial(8) * factorial(6)) ./ ...
(factorial(9) * factorial(6) * factorial(5)) ;
disp('f1, f2, f3 = ') ; disp([f1 f2 f3])


% Also for larger values FACTORIALRATIO works correctly
f1 = factorialratio(150,143) ;
f2 = prod(144:150) ; % by hand
% where FACTORIAL lacks precision
f3 = factorial(150) ./ factorial(143) ;
disp('f1, f2, f3 = ') ; disp([f1 f2 f3])
disp(' Differences with f2 = ') ; disp([f1-f2 f2-f2 f3-f2])

% and even for extreme numbers things turn out well
f1 = factorialratio(30000,29998) ;
f2 = (30000 * 29999) ; % by hand
% whereas calls to FACTORIAL fail miserably ...
f3 = factorial(30000) ./ factorial(29998) ;
disp('f1, f2, f3 = ') ; disp([f1 f2 f3])

Note that, for instance, factorialratio(200,1) also fails, of course.
For such occasions other engines have to be used.

See also prod, factorial, gammaln

引用格式

Jos (10584) (2025). FACTORIALRATIO (https://ww2.mathworks.cn/matlabcentral/fileexchange/23018-factorialratio), MATLAB Central File Exchange. 检索时间: .

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

Community Treasure Hunt

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

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

fixed bug for inputs with only 2's

1.1.0.0

fixed small bug in error checks

1.0.0.0