How to check equality of very small numbers ?

7 vues (au cours des 30 derniers jours)
Sajid Afaque
Sajid Afaque le 16 Fév 2022
Modifié(e) : Stephen23 le 16 Fév 2022
Hey Community !!
I have two very closely related numbers
A = 1.309998142150646e-09
B = 1.309998162564509e-09
now if i need to compare two numbers only upto 5 precision points , i.e.
A = 1.309998e-09 %how can i get this from above mentioned A
B = 1.309998e-09
now my condition A == B will satisfy,
so what can i do to check if both numbers are equal upto 5 precision points, keeping the exponential part ?

Réponse acceptée

Stephen23
Stephen23 le 16 Fév 2022
Modifié(e) : Stephen23 le 16 Fév 2022
A = 1.309998142150646e-09;
B = 1.309998162564509e-09;
Method one: compare the absolute difference against a tolerance:
tol = 1e-14;
abs(A-B)<tol
ans = logical
1
Method two: use ISMEMBERTOL (the 3rd argument specifies the relative tolerance):
ismembertol(A,B,1e-5)
ans = logical
1
Do NOT round the values, as this introduces artifacts into the data:

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by