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!