How can I avoid a small value ignored during calculation?
Afficher commentaires plus anciens
z is a small value, and wen a1 is added by z, it doesn't show any difference. Why is that? And how can I aviod this?

Réponse acceptée
Plus de réponses (1)
Patrik Forssén
le 20 Nov 2022
Modifié(e) : Patrik Forssén
le 20 Nov 2022
@John D'Errico explained why this happens. If you really need to avoid this, you must therefore use an arbitrary-precision numerical class for your calculations. MATLAB does not have one, but you can interface Java’s. Here is what your example would look like,
z1 = java.math.BigDecimal('1.111111e-19');
a1 = java.math.BigDecimal('-0.0581375401465599531136696498379023978486657142639160156250000000000000');
a2 = a1.add(z1);
disp(char(z1.toPlainString()))
disp(char(a1.toPlainString()))
disp(char(a2.toPlainString()))
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!