MATLAB: Using factorial in optimiztion toolbox

Optimization Toolbox

Hello everyone,i am using genetic algorithm in optimization toolbox, my variables are integers and in my constraint part factorial of those variables are calculated
(like factorial(x(1))
When variables take value < 140 then optimization is done but when values of variables reaches 150 or more optimization results are not obtained i suppose due to very large quantity.
When i formulated my objective function using toolbox which can calculate factorial > 150 following error is showing
##Optimization running. Error running optimization. Constraint function must return real value.##
so can anyone please give me a solution to this problem that how to calculate factorial of variables which take value > 150! .
Please reply It will be really helpful for me, Thanking you in advance!

Best Answer

Do you really need to know the factorial of those large numbers? Or would it be sufficient to know the logarithm of the numbers? I suggest that you use Stirling's formula (or this discussion) to approximate the logarithm of factorials:

log(n!) = n*log(n/e) + 1/2*log (2*pi*n)

Alan Weiss

MATLAB mathematical toolbox documentation