how to use large numbers
古いコメントを表示
i would like to use extremely large numbers in my matlab code for testing. so to say, a number like: 10^100. i tried the vpi but the numbers are still smaller than i need. this is for school work not just to test matlabs ability
2 件のコメント
Guillaume
2019 年 11 月 4 日
What does use mean?
The maximum value of a double is:
>> realmax
ans =
1.79769313486232e+308
And you can certainly enter 1e100. Of course at this magnitude, the precision is of the order of:
>> eps(1e100)
ans =
1.94266889222573e+84
The governing principle of floating point is that at that magnitude you don't need more precision.
As far as I know vpi has no restriction to the number of digits:
>> digits = '0':'9';
>> n = vpi(digits(randi(10, 1, 1000))); %integer with 1000 digits
>> ceil(log10(n)) %how many digits
ans =
1000
As you can see I just created a number of the order of 1e1000.
John D'Errico
2019 年 11 月 4 日
VPI (HPF too) has no explicit restriction, except for the limits of your computer and the speed of it. Huge numbers can become highly computationally expensive to work with, of course. For example, in order to validate my tools, I used them to compute a million digits of pi. It took a little while though. And I can use tools like VPI to search for huge primes.
採用された回答
その他の回答 (1 件)
Steven Lord
2019 年 11 月 4 日
Use Symbolic Math Toolbox. Be careful not to perform computations in double that result in values greater than flintmax and then convert the results to sym. Convert exact quantities to sym and perform the calculations symbolically. In some cases you'll get the results you expect, but in others you won't. This is especially important if you're working with numbers too big to store in double precision.
>> tenTo100 = sym(10)^100
tenTo100 =
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
>> twoTo2000 = sym(2)^2000
twoTo2000 =
114813069527425452423283 % ... snip a whole bunch of digits, ending in ... 9376
>> twoTo2000_doubleFirst = sym(2^2000)
twoTo2000_doubleFirst =
Inf
カテゴリ
ヘルプ センター および File Exchange で Number Theory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!