vpa doesn't seem to work

9 ビュー (過去 30 日間)
Jacob Kelley
Jacob Kelley 2019 年 11 月 14 日
コメント済み: Walter Roberson 2019 年 11 月 14 日
So I am trying to figure out how to use vpa(#,d) to do calculations with massive numbers on the magnitude of 1 x 10^(233) and need to know exactly down to the ones place. I have symbolic toolbox (syms x works). I have the student package if that helps.
When I do:
n = vpa(26666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666,300);
disp(n)
I get
26666666666666664495576118479230905243264565232272359586606331654070606440955821114246602026241719460353816553395244433385163782965564092296761476436932581062453237774063919113395968897415818722241311296600328363621654143835408695296.0
Why does it look like it is still having roud off error after 16 digits?

採用された回答

James Tursa
James Tursa 2019 年 11 月 14 日
編集済み: James Tursa 2019 年 11 月 14 日
You are passing a double into vpa( ), so your precision is lost before you even call it. You could pass in a string instead:
n = vpa('26666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666',300);
Bottom line is don't do any extended precision stuff in double ... even typing it in will ruin your result.
  3 件のコメント
Jacob Kelley
Jacob Kelley 2019 年 11 月 14 日
Another question you might know, Why does it attach the .0 to the end? I also can't have it do that with what I am trying to do. example:
s = vpa('35524',50);
disp(s)
gives
35524.0
Walter Roberson
Walter Roberson 2019 年 11 月 14 日
(answered in the question you posted about this)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion 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