This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

!, fact

Factorial function

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


n !


fact(n) represents the factorial of an integer.

The short hand call n! is equivalent to fact(n).

If n is a nonnegative integer smaller than the value returned by Pref::autoExpansionLimit(), then an integer is returned. If n is a numerical value that is not an integer, then an error occurs. If n is a symbolic expression, then a symbolic call of fact is returned.

Use expand(n!) to compute an explicit result for large integers n equal to or larger than Pref::autoExpansionLimit().

The gamma function generalizes the factorial function to arbitrary complex arguments. It satisfies gamma(n+1) = n! for nonnegative integers n. Expressions involving symbolic fact calls can be rewritten by rewrite(expression, gamma). Cf. Example 3.

The operator ! can also be used in prefix notation with an entirely different meaning: !command is equivalent to system("command").


Example 1

Integer numbers are produced if the argument is a nonnegative integer:

fact(0), fact(5), fact(2^5)

A symbolic call is returned if the argument is a symbolic expression:

fact(n), fact(n - sin(x)), fact(3.0*n + I)

The calls fact(n) and n! are equivalent:

5! = fact(5), fact(n^2 + 3)

Example 2

Use gamma(float(n+1)) rather than float(fact(n)) for floating-point approximations of large factorials. This avoids the costs of computing large integer numbers:

float(fact(2^13)) = gamma(float(2^13 + 1))

Example 3

The functions expand, limit, rewrite and series handle expressions involving fact:

expand(fact(n^2 + 4))

limit(fact(n)/exp(n), n = infinity)

rewrite(fact(2*n^2 + 1)/fact(n - 1), gamma)

The Stirling formula is obtained as an asymptotic series:

series(fact(n), n = infinity, 3)



An arithmetical expression representing a nonnegative integer

Return Values

Arithmetical expression.

Overloaded By


See Also

MuPAD Functions

Was this topic helpful?