Computation's with large numbers.

조회 수: 10 (최근 30일)
Yuechuan Chen
Yuechuan Chen 2019년 12월 9일
댓글: Yuechuan Chen 2019년 12월 9일
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!

채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 12월 9일
n=sym('94315998522576010519588224930693232398146802027362761139521');
answer=vpa((n-1)/2^143)
  댓글 수: 1
Yuechuan Chen
Yuechuan Chen 2019년 12월 9일
Perfect! Thank you so much!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by