problem using factorial in matlab
Show older comments
I wanted to calculate 200! but after 170! matlab starts showing result NaN. So is there any way possible to calculate this number using matlab???
Accepted Answer
More Answers (1)
Steven Lord
on 8 Nov 2017
0 votes
If you're computing this as an intermediary step to compute a final result and will immediately divide it by the factorial of some other number, don't compute the result that way. My guess is that you're trying to compute the binomial coefficient nchoosek, in which case you should use that function.
If you can't use nchoosek (because your homework tells you not to, for example) you could turn a ratio of two factorials into the appropriate call to prod by using cancellation. [To see what I mean, write out how you would compute factorial(8) and factorial(4) on paper. Determine how you would use those representations to compute factorial(8)/factorial(4) without actually calling factorial, then generalize that process.]
Categories
Find more on Performance and Memory 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!