Borrar filtros
Borrar filtros

Test of Approximately Equality

28 visualizaciones (últimos 30 días)
John Miller
John Miller el 16 de Jun. de 2012
Comentada: Walter Roberson el 29 de Dic. de 2017
Hello,
I have a value b and c. b and c are approximatly equal (b~c). They have +-5% difference.
I want to test of approximately equality..like this:
if b~c (with +-5% difference)
return something...
end

Respuestas (3)

Jan
Jan el 17 de Jun. de 2012
You only have to decide if it should be 5% of the first or the second argument. Then:
if abs(b - c) < 0.05 * b
or
if abs(b - c) < 0.05 * max(b, c)
or
if abs(b - c) < 0.05 * min(b, c)
or
if abs(b - c) < 0.05 * (b + c) * 0.5
  2 comentarios
Walter Roberson
Walter Roberson el 17 de Jun. de 2012
Some of those expressions will have difficulty if "b" is negative.
Greg Heath
Greg Heath el 18 de Jun. de 2012
1. Try using "abs" on the RHS
2. Might also consider median(abs(b),abs(c))
Greg

Iniciar sesión para comentar.


Stephen Nagy
Stephen Nagy el 29 de Dic. de 2017
Your desired goal isn't entirely clear, but depending on the outcome you seek, the functions "uniquetol" and some of its related functions might be helpful.
  1 comentario
Walter Roberson
Walter Roberson el 29 de Dic. de 2017
ismembertol() and uniquetol() did not exist in 2012 though ;-)

Iniciar sesión para comentar.


per isakson
per isakson el 16 de Jun. de 2012
See isalmost(a,b,tol) in the File Exchange. There are more.

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by