Trouble computing the factorial of a vector
3 ビュー (過去 30 日間)
古いコメントを表示
For a problem I need to get the factorial of numbers 1-50. I started by defining n = [1:50] and then typing factorial(n), but the answer seems really strange, with almost every element equaling to 0 except for the last 4.
Columns 1 through 18
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
Columns 19 through 36
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
etc.
0 件のコメント
回答 (1 件)
John D'Errico
2021 年 1 月 21 日
編集済み: John D'Errico
2021 年 1 月 23 日
No. Look CAREFULLY at that vector.
Are they really zero? Or are they just relatively zero?
F = factorial(1:50);
F([1 2 48 49])
ans =
1.0e+62 *
0.0000 0.0000 0.1241 6.0828
That was using the default display format. Do you see that 1.0e62* in front? What do you think that means? The ENTIRE vector as displayed is multiplied by 1e62, but SOME of those numbers are too small to display when the vector is displayed in this format. So they appear as 0.0000. Had you used a different display format, they would now show up.
format long g
F([1 2 49 50])
ans =
1 2 6.08281864034268e+62 3.04140932017134e+64
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!