How to avoid rounding error
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Chris
am 17 Sep. 2022
Bearbeitet: Chris
am 17 Sep. 2022
Matlab is simply truncating the displayed value for ease of reading.
format longG
sqrt(10001)
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))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!