factorial is slower than prod() which is still pretty slow

Why is factorial(n) slower than prod(1:n)? I know with small n (<20) this is the case, but it's kind of annoying. For smallish n, it seems that just building a lookup table is the fastest, but it feels like a bad kluge. Any insights?

Answers (1)

factorial() is defined over matrices and is optimized for that situation. It also has error checking that prod() does not have.

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Asked:

on 15 Jun 2011

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!