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.
49 views (last 30 days)
Show older comments
T = 3500*10^3
tau = 50
k = 0.4
Do = 3^sqrt((16*T)/(tau*pi*((1-k)^4)))
Di = D0*k
2 Comments
Torsten
on 10 Nov 2024 at 18:27
Edited: Walter Roberson
on 11 Nov 2024 at 18:10
T = sym('3500e3')
tau = sym('50')
k = sym('0.4')
Do = vpa(3^sqrt((16*T)/(tau*pi*((1-k)^4))))
disp(char(Do))
Answers (1)
John D'Errico
on 11 Nov 2024 at 15:29
Edited: John D'Errico
on 11 Nov 2024 at 15:31
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 Comments
Steven Lord
on 11 Nov 2024 at 16:42
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.
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!