factorial

Factorial function

Syntax

factorial(n)
factorial(A)

Description

factorial(n) returns the factorial of n.

factorial(A) returns the factorials of each element of A.

Input Arguments

n

Symbolic variable or expression representing a nonnegative integer.

A

Vector or matrix of symbolic variables or expressions representing nonnegative integers.

Examples

Compute the factorial function for these expressions:

syms n
f = factorial(n^2 + 1)
f =
factorial(n^2 + 1)

Now substitute the variable n with the value 3:

subs(f, n, 3)
ans =
     3628800

Differentiate the expression involving the factorial function:

syms n
diff(factorial(n^2 + n + 1))
ans =
factorial(n^2 + n + 1)*psi(n^2 + n + 2)*(2*n + 1)

Expand the expression involving the factorial function:

syms n
expand(factorial(n^2 + n + 1))
ans =
factorial(n^2 + n)*(n^2 + n + 1)

Compute the limit for the expression involving the factorial function:

syms n
limit(factorial(n)/exp(n), n, inf)
ans =
Inf

Call factorial for the matrix A. The result is a matrix of the factorial functions:

A = sym([1 2; 3 4]);
factorial(A)
ans =
[ 1,  2]
[ 6, 24]

More About

expand all

Factorial Function

This product defines the factorial function of a positive integer:

n!=k=1nk

The factorial function 0! = 1.

Tips

  • Calling factorial for a number that is not a symbolic object invokes the MATLAB® factorial function.

See Also

| | |

Was this topic helpful?