Factorial of large numbers
by Yvan Lengwiler
27 Apr 2007
(Updated 10 May 2007)
computes factorials of large arguments using standard algorithm
|
Watch this File
|
| File Information |
| Description |
This function implements a standard algorithm for computing factorials. It may not be the most efficient for very large arguments, but it is very transparent. The function accepts single numbers as inputs or arrays.
Note that for any real work, the code suggested by John D'Errico is actually preferable, because it is faster and more precise. This code is implemented in another file on FEX, logfactorial. I would therefore suggest that you use that function instead of largefactorial. |
| Acknowledgements |
This submission has inspired the following:
Log of factorial of large numbers
|
| MATLAB release |
MATLAB 7.1.0 (R14SP3)
|
|
Tags for This File
|
| Everyone's Tags |
|
| Tags I've Applied |
|
| Add New Tags |
Please login to tag files.
|
| Comments and Ratings (6) |
| 28 Apr 2007 |
urs (us) schwarz
|
|
|
| 28 Apr 2007 |
urs (us) schwarz
|
|
|
| 29 Apr 2007 |
John D'Errico
|
|
|
| 29 Apr 2007 |
Urs (us) Schwarz
|
|
|
| 04 May 2007 |
Yvan Lengwiler
|
|
|
| 07 May 2007 |
John D'Errico
|
|
|
| Updates |
| 30 Apr 2007 |
Improved documentation and speed. |
| 30 Apr 2007 |
1) Bug fix: Two elements were preassigned to wrong size, which lead to runtime error.
2) Better documentation with examples. |
| 03 May 2007 |
If many factorials are computed at the same time, the function now computes only the increments and then aggregates the results. This leads to a significant gain in terms of speed.
I have also implemented vectorization as suggested by a reviewer. |
| 07 May 2007 |
A small improvement of speed is achieved by using arrayfun instead of a loop. The gain is relevant only if an array if supplied as argument. |
| 10 May 2007 |
Better documentation.
Small bug fix.
Slightly better speed. |
|
Contact us at files@mathworks.com