Fix NaN error when n>300
Afficher commentaires plus anciens
I need to write the following equation so that it works when n is anything greater than 300. It currently works for anythig 300 or less but anything greater I get NaN.
Formula written into code:
.
Current code:
n=100;
numerator=1;
for i=n:-2:2
numerator=numerator*i;
end
denominator=1;
for i=n-1:-2:1
denominator=denominator*i;
end
%percision 10^-4
digits(6);
%calculate r
R=numerator/denominator;
disp(R)
Réponses (1)
If you have symbolic toolbox use vpa. REad about it.
n=701;
numerator=vpa(1);
for i=n:-2:2
numerator=numerator*i;
end
denominator=vpa(1);
for i=n-1:-2:1
denominator=denominator*i;
end
%percision 10^-4
digits(6);
%calculate r
R=numerator/denominator;
disp(R)
Catégories
En savoir plus sur NaNs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!