%% Compute Factorial Function for Symbolic Expression
% Compute the factorial function for a symbolic expression. factorial returns exact symbolic output as the function call.

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

% Calculate the factorial for a value of n = 3. Substitute the value of n by using subs.

fVal = subs(f,n,3)

%
% Copyright 2012-2019 The MathWorks, Inc.