Search code examples
matlabmathfactorialsymbolic-math

Get an error while using factorial function in matlab?


When trying to compute this sequence I get an error

syms n
limit(((-3)^n)/factorial(n),inf)

Error using factorial (line 17) N must be a matrix of non-negative integers. Error in (line 9)

How do you fix this or specify the matrix they want?


Solution

  • The factorial function wasn't designed for use of symbolic references, and often chokes on them. It might work if you have a new enough version (2012b claims it works), but I don't think it'll necessarily work with older versions, I've found some documents claiming it won't in fact. The following two methods have been suggested to work around the problem.

    limit((-3)^n/sym('n!'),n,inf)
    limit((-3)^n/gamma(n+1),n,inf)