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
T = 3500000
tau = 50
tau = 50
k = 0.4
k = 0.4000
Do = 3^sqrt((16*T)/(tau*pi*((1-k)^4)))
Do = Inf
Di = D0*k
Unrecognized function or variable 'D0'.

回答(1 个)

John D'Errico
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
T = 3500000
tau = 50
tau = 50
k = 0.4
k = 0.4000
k = 0.4000
k = 0.4000
Do = 3^sqrt((16*T)/(tau*pi*((1-k)^4)))
Do = Inf
So you are trying to raise the number 3 to what power?
sqrt((16*T)/(tau*pi*((1-k)^4)))
ans = 1.6586e+03
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)))
ans = 4.9757e+03
  2 个评论
Steven Lord
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)
numDigits1 = 791.0670
How many would be required to write the largest finite double precision number?
numDigits2 = log10(realmax)
numDigits2 = 308.2547
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)
ans = 8.3219e+10
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)!)
ans = 1×2
Inf Inf
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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)
ans = 1×5
80.0000 99.7500 132.6667 198.5000 396.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
nck(400, 5)
ans = 8.3219e+10
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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by