HI, while doing a small calculation part, from my class note, in matlab, im getting the result as inf, can i know how to convert the inf value into realnumbers.
조회 수: 2 (최근 30일)
이전 댓글 표시
T = 3500*10^3
tau = 50
k = 0.4
Do = 3^sqrt((16*T)/(tau*pi*((1-k)^4)))
Di = D0*k
댓글 수: 2
Torsten
2024년 11월 10일
편집: Walter Roberson
2024년 11월 11일
T = sym('3500e3')
tau = sym('50')
k = sym('0.4')
Do = vpa(3^sqrt((16*T)/(tau*pi*((1-k)^4))))
disp(char(Do))
답변 (1개)
John D'Errico
2024년 11월 11일
편집: John D'Errico
2024년 11월 11일
Of course D0 is undefined. You created the variable Do. There is a difference between the number 0 and the letter o.
That Do is inf is another issue.
T = 3500*10^3
tau = 50
k = 0.4
k = 0.4000
Do = 3^sqrt((16*T)/(tau*pi*((1-k)^4)))
So you are trying to raise the number 3 to what power?
sqrt((16*T)/(tau*pi*((1-k)^4)))
What is 3^1658 power? A REALLY LARGE NUMBER. Do you understand just how large?
vpa(sym(3)^sqrt((16*T)/(tau*pi*((1-k)^4))))
Are you absolutely certain that you wanted to compute this? Vastly more than the number of elementary particles in the known universe.
Possibly your intent was to multiply that by 3, and not raise 3 to that power. We don't know, at least not until we can get the mind reading toolbox in working order. It is just such a buggy thing. ;-)
3*sqrt((16*T)/(tau*pi*((1-k)^4)))
댓글 수: 2
Steven Lord
2024년 11월 11일
What is 3^1658 power? A REALLY LARGE NUMBER. Do you understand just how large?
In case the original poster doesn't understand, let's look at how many digits would be required to write out that number.
numDigits1 = 1658*log10(3)
How many would be required to write the largest finite double precision number?
numDigits2 = log10(realmax)
So yes, this definitely overflows to infinity. Using Symbolic Math Toolbox would be one approach you could use to compute that number, but depending on what you're planning to do with it (dividing by another number of similar magnitude?) you may be able to avoid computing such large numbers. For example,
nchoosek(400, 5)
Now if we computed nchoosek naively, we'd be dividing Inf by Inf as two of the three factorials involved overflow.
factorial([400 395]) % nchoosek(n, k) = n!/(k!*(n-k)!)
But we don't. Recognize that we could compute n!/(n-k)! without actually computing each of the factorials in full, the numerator in nckhelper below.
nckhelper = @(n, k) (n:-1:(n-k+1))./(k:-1:1);
nck = @(n, k) prod(nckhelper(n, k));
nckhelper(400, 5)
nck(400, 5)
If you describe how you're hoping to use this number we may be able to suggest an alternate way to reach your goal without using nearly 800-digit long numbers.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!