The title says it all: I want to calculate an exponent in matlab with big numbers, but I get overflow and it just returns infinity.
>> 100^1000
ans =
Inf
Last time I checked, 100^1000 is decidedly smaller than infinity :)
The title says it all: I want to calculate an exponent in matlab with big numbers, but I get overflow and it just returns infinity.
>> 100^1000
ans =
Inf
Last time I checked, 100^1000 is decidedly smaller than infinity :)
To deal with large numbers there is also the class High Precision Float, with which the result can be achieved by writing
which gives
c = 1.e2000
. A call tostruct(c)
provides informations on how the number is internally stored.As Daniel has already pointed out, it's too big a number to be even outputted by MATLAB itself. This number is obtained with
realmax
for different datatypes. As an alternative to represent/use such huge numbers, you can use the correspondingmantissa
andexponent
withbase-10 representation
instead, which is the usual MATLAB representation. The function to get those two is listed here -Few example runs and comparisons with actual MATLAB runs for validation are listed next.
Ex #1
Output -
Ex #2 (problem discussed in the question)
Output -
Working with 64bit floating point arithmetic,
100^1000
isinf
because it is larger than the largest possible value. If the symbolic math toolbox is available, usevpa
orsym
to work with large numbers:or