matlab equal does not work

1.3k Views Asked by At

 How to judge whether two whatever is equal? alphat and alpha are two kind big vectors. Why it turns 0, which means they are not equal?

How to judge whether two whatever is equal? alphat and alpha are two kind big vectors. Why it turns 0, which means they are not equal?

1

There are 1 best solutions below

0
On

Floating point numbers are notoriously difficult to compare with eq(), == or any other direct bitwise comparison. This is because finite precision arithmetic rarely allows us to compute exact values. If two different algorithms compute the same result differently, it is nearly guaranteed that the numerical result will differ by some small amount.

Your best bet is to do an "almost equals" comparison:

epsilon = 1e-8; % Or some other suitably small number
if abs(alphat(16108)-alpha(16108)) < epsilon
.... % equality is met
end