Trouble computing the factorial of a vector
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
John D'Errico
el 21 de En. de 2021
Editada: John D'Errico
el 23 de En. de 2021
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 comentarios
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!