%% Differentiate Factorial Function
% Differentiate an expression containing the factorial function \left(n^2 +n+1\right)!

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

% The derivative of the factorial function is expressed in terms of the digamma function.
%
% Copyright 2012-2019 The MathWorks, Inc.