problem using factorial in matlab
显示 更早的评论
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???
采纳的回答
更多回答(1 个)
Steven Lord
2017-11-8
0 个投票
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.]
类别
在 帮助中心 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!