how to decrease precision

18 ビュー (過去 30 日間)
Juan Getino
Juan Getino 2019 年 2 月 17 日
編集済み: John D'Errico 2019 年 2 月 17 日
I am trying to show to my students examples on the effect of rounds error when performing Gauss elimination without pivoting. This question is very easy with Maple, simply by fixing the numbers of desired digits with Digits:=4, for instance. In this way, I can show the errors appearing in the solution when performing Gauss elimination without pivoting.
But I do not know haw to proceed in Matlab, I always get the exact solution.
Thank you in advance.
  1 件のコメント
Rik
Rik 2019 年 2 月 17 日
Are you using a numerical method, or are you using the symbolic toolbox? In the case of the first, you can use this:
digits=4;
data=(10^digits)*round(data/(10^digits));% round to n digits

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

採用された回答

John D'Errico
John D'Errico 2019 年 2 月 17 日
編集済み: John D'Errico 2019 年 2 月 17 日
You cannot tell MATLAB to use an arbitrary lower or higher precision. At most, you can work in single precision instead of double. But even there, you need to be careful, as all numbers by default are ALWAYS doubles. So it would be possible to introduce doubles into the problem, thus to accidentally suddenly start working in double precision. Luckily, singles tend to propagate.
A = single(2) + double(3)
A =
single
5
Can you do more than that? This is difficult if you choose to force yourself to work with the standard MATLAB numeric data types. I suppose you could download my HPF toolbox from the file exchange. So, in HPF, if I want to force all computations done in that tool to use EXACTLY 7 decimal digits, then I could do this:
DefaultNumberOfDigits 7 0
x = hpf(pi)
x =
3.141593
That will cause all numbers created as HPF to display and store only 7 digits, with no hidden (i.e., guard) digits carried in the background, and that setting will persist until you change it, even if you exit MATLAB and restart.
And, of course, you can also work with the symbolic toolbox.

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by