Code covered by the BSD License  

Highlights from
Log of factorial of large numbers

Be the first to rate this file! 6 Downloads (last 30 days) File Size: 3.58 KB File ID: #14920

Log of factorial of large numbers

by Yvan Lengwiler

 

08 May 2007 (Updated 10 May 2007)

computes log10 of the factorial

| Watch this File

File Information
Description

This function computes log10 of the factorial. Unlike FACTORIAL, it is not limited to arguments less than 171.

Two methods are implemented, one based on the gamma function (thank you, John), as well as a direct sum. The user can choose between the two methods. The gamma method is superior and is therefore the default choice.

The function returns the log10 of the factorial, the mantissa and the exponent of the factorial, as well as a string representing the factorial.

For instance
[L,M,X,S] = logfactorial(1E6)
yields
L = 5.5657e+006 % log10(N!)
M = 8.2639 % mantissa
X = 5565708 % exponent
S = '8.26393e+5565708' % N! as a string

The function accepts scalars or arrays as inputs.

LOGFACTORIAL is the result of a seqeunce of improvements that were suggested by John D'Errico and Urs Schwarz in their discussion of another FEX file, LARGEFACTORIAL. LOGFACTORIAL is preferrable for two reasons:

1. The gamma-based code is much faster than the direct sum code, which is the only one implemented in LARGEFACTORIAL.

2. LARGEFACTORIAL returns a string as the first argument, which is not very convenient to perform further computations. LOGFACTORIAL returns the log10 as the first argument, so for instance 10.^logfactorial(...) does make sense.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
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.
Please login to add a comment or rating.
Updates
10 May 2007

More descriptive title. Correction of typo in the description.

Tag Activity for this File
Tag Applied By Date/Time
statistics Yvan Lengwiler 22 Oct 2008 09:12:18
probability Yvan Lengwiler 22 Oct 2008 09:12:18
factorial Yvan Lengwiler 22 Oct 2008 09:12:18
combinatorics Yvan Lengwiler 22 Oct 2008 09:12:18
log10 Yvan Lengwiler 22 Oct 2008 09:12:18

Contact us at files@mathworks.com