Big integer and Precision

16 次查看(过去 30 天)
saima
saima 2014-7-12
Hi,
I am trying to work on some problems which deal with really large integers (much larger than intmax('uint64')). How do I deal with such integers in MATLAB? I got some stuffs online based on 'vpa'. Is there any alternative to symbolic toolbox and vpa? Using an easy example, say I am trying to calculate the value of 2^2317. How is it possible to do it?
And how do I increase the precision of calculation? Say, I am trying to calculate sqrt(3) upto 15 digits precision. How can I do it?
Thanks :-)
  3 个评论
Image Analyst
Image Analyst 2014-7-12
编辑:Image Analyst 2014-7-12
Is there some link that gives the answer for how many digits you can expect for single or double precision? [edit] http://www.mathworks.com/help/matlab/matlab_prog/floating-point-numbers.html seems to indicate that the number of places depends on the number you're considering, but it's accurate through about 14 decimal places (7.1e-15 so the 15th place can be inaccurate by as much as 7) for doubles and through 6 places (+/- 4.7684e-07, the 7th place varies by around +/-4) for singles.
Star Strider
Star Strider 2014-7-12
编辑:Star Strider 2014-7-12
eps:
  • eps(X) = 2^(E-23) if isa(X,'single')
  • eps(X) = 2^(E-52) if isa(X,'double')
Also: flintmax.

请先登录,再进行评论。

回答(3 个)

Star Strider
Star Strider 2014-7-12
编辑:Star Strider 2014-7-12
The vpa function in the Symbolic Math Toolbox is probably your only option. You can adjust the precision with the digits function.
From the documentation:
  • digits lets you specify any number of significant decimal digits from 1 to 2^29 + 1. ’
  1 个评论
Image Analyst
Image Analyst 2014-7-12
Wow, 536,870,913 digits of precision. I never would have guessed that you could get that much precision. And I thought 20 or 30 would have been a lot.

请先登录,再进行评论。


James Tursa
James Tursa 2014-7-12
编辑:James Tursa 2014-7-12
In addition to the Symbolic Toolbox, for extended precision integer and floating point arithmetic, you can use these FEX submissions by John D'Errico:

Christopher Creutzig
编辑:Christopher Creutzig 2014-9-1
You can compute with exact integers and rationals using the symbolic toolbox, just make sure they are not cut off by computing in doubles first:
>> sym(2)^2317
ans =
30654903508108357077958654144825937585978808922337901521692741170911447076693116235513237095579066485773937279334784139954181575840986269850991750398202331213943274278112396793424683275528507127617356737974156212114985333650793917021532655353073330339869206521452698460733186617040160262848093715277704279290680230304150547684590960276420040187406068172642162633162861058913834479146788713758308941909711983231722076836272997428595743463045969399361824711110350992834115834375631290260030543671026084690659491964528746134305444576187523233231429766154483330868291973263704666586462246580637588991629908758131771642269031718471782924220000298094429698919484347691856871276393621193756312248959107072
>> (sqrt(sym(2))+1/sym(7))^23
ans =
(2^(1/2) + 1/7)^23
>> expand((sqrt(sym(2))+1/sym(7))^23)
ans =
(36964502873561444765593*2^(1/2))/3909821048582988049 + 359084438788642488468527/27368747340080916343

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by