matlab equal does not work

$\begingroup$

 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?

$\endgroup$ 2

1 Answer

$\begingroup$

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
$\endgroup$

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like