Clear Filters
Clear Filters

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

3 views (last 30 days)
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)

Walter Roberson
Walter Roberson on 15 Jun 2011
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 Discrete Math in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!