フィルターのクリア

'setprecision', 24

8 ビュー (過去 30 日間)
Beat Aebischer
Beat Aebischer 2021 年 1 月 21 日
コメント済み: Beat Aebischer 2021 年 1 月 26 日
Why are the two results below the same? I would like to simulate single precision with system_dependent('setprecision' , 24).
>> system_dependent('setprecision', 64)
>> 10000*sqrt(exp(pi))-48104
ans =
0.773809653510398
>> system_dependent('setprecision', 24)
>> 10000*sqrt(exp(pi))-48104
ans =
0.773809653510398

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 25 日
system_dependent('setprecision')... I seem to recall that it only ever had effect on windows and only for some of the older releases. You could find more information on Yair's undocumented-matlab site.
  1 件のコメント
Beat Aebischer
Beat Aebischer 2021 年 1 月 26 日
Thanks. This means one cannot rely on 'system_depedent' or 'feature'. Anyway in the ML version I currently use (9.5.0), 'setprecision' does not seem to work - it is also asking a lot as it would have to be "system independent".
Instead I have tried casting the input with the command 'single', this seems to work.

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

その他の回答 (1 件)

Gaurav Garg
Gaurav Garg 2021 年 1 月 25 日
Hi,
On running the same code, and then verifying the variable precision being used, I could see that the variable precision was never changed.
You can verify the variable precision using the digits.
digits
In your case, if you need to change the precision, you can use the below piece of code -
digitsOld = digits(64);
vpa(10000*sqrt(exp(pi))-48104)
digits
digitsOld = digits(24);
vpa(10000*sqrt(exp(pi))-48104)
digits
You can also follow the documentation here.
  3 件のコメント
Beat Aebischer
Beat Aebischer 2021 年 1 月 25 日
Yes, Gaurav's suggestion is very nice, but I was trying to do it without a Symbolic Math TB.
Walter Roberson
Walter Roberson 2021 年 1 月 25 日
The solution with vpa needs modification to prevent the argument from being evaluated in double precision before it gets to vpa.
Q = @(v) sym(v) ;
digitsOld = digits(64);
vpa(10000*sqrt(exp(Q(pi)))-48104)
digits
digitsOld = digits(24);
vpa(10000*sqrt(exp(Q(pi)))-48104)
It would need further modifications to emulate step by step evaluation at the chosen digits the way that setting system_dependent('precision') would

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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by