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)

답변 (1개)

KSSV
KSSV 2022년 1월 19일

0 개 추천

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)
21.1326

카테고리

도움말 센터File Exchange에서 NaNs에 대해 자세히 알아보기

태그

질문:

2022년 1월 19일

답변:

2022년 1월 19일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by