Computation's with large numbers.

11 views (last 30 days)
So, I'm trying to divide n-1( n=94315998522576010519588224930693232398146802027362761139521) by 2^143, I stored n has a symbolic variable to not lose precision, so:
n=sym('94315998522576010519588224930693232398146802027362761139521');
however, when I do n-1/2^143 it gives me a stupid answer 1051658525598479156308916018992636883668880484184809306202701679900748001639266703538773119682234810367/11150372599265311570767859136324180752990208 (the correct answer should be 8458551289020639 ) .
It seems like Matlab has treated n-1/2^143 as a string rather than a computation because it's outputing the / sign.
I've also tried vpa but I encountered the same problem.
Could someone shed a light on this please, how can I compute this without losing accuracy, i.e. preventing Matlab rounding n and my answer.
THANKS!

Accepted Answer

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH on 9 Dec 2019
n=sym('94315998522576010519588224930693232398146802027362761139521');
answer=vpa((n-1)/2^143)
  1 Comment
Yuechuan Chen
Yuechuan Chen on 9 Dec 2019
Perfect! Thank you so much!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by