How to avoid rounding error

6 ビュー (過去 30 日間)
Jiapeng
Jiapeng 2022 年 9 月 17 日
編集済み: Chris 2022 年 9 月 17 日
If I want to get the value of sqrt(10001),and it should to be 100.00499...
However, MATLAB shows 100.005.
How should I write the code to get 100.00499...
THANK YOU

採用された回答

Chris
Chris 2022 年 9 月 17 日
編集済み: Chris 2022 年 9 月 17 日
Matlab is simply truncating the displayed value for ease of reading.
format longG
sqrt(10001)
ans =
100.004999875006
In both cases, the actual value matlab holds in memory is within +/- epsilon of the true value. Epsilon can be calculated like so:
eps(sqrt(10001))
ans =
1.4210854715202e-14

その他の回答 (0 件)

カテゴリ

Find more on Get Started with MATLAB in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by