Fix NaN error when n>300
3 ビュー (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
回答 (1 件)
KSSV
2022 年 1 月 19 日
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)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numbers and Precision についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!