MATLAB Answers

Big integer and Precision

조회 수: 78(최근 30일)
saima 12 Jul 2014
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
Star Strider
Star Strider 12 Jul 2014
  • eps(X) = 2^(E-23) if isa(X,'single')
  • eps(X) = 2^(E-52) if isa(X,'double')
Also: flintmax.

댓글을 달려면 로그인하십시오.


Star Strider
Star Strider 12 Jul 2014
편집: Star Strider 12 Jul 2014
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 12 Jul 2014
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 12 Jul 2014
편집: James Tursa 12 Jul 2014
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 1 Sep 2014
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 =
>> (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

Community Treasure Hunt

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

Start Hunting!

Translated by