When i try the code below in matlab, a and b is not equal shouldn't they be that?
a = 0.3
b = 0.1*3
a == b
Is this a bug or am I using the wrong operator to compare the number with?
When i try the code below in matlab, a and b is not equal shouldn't they be that?
a = 0.3
b = 0.1*3
a == b
Is this a bug or am I using the wrong operator to compare the number with?
Both are not equal, because floating point arithmetic has a certain precision. Check the difference (a-b)
it should be really small.
For most programming languages, the answer is simply "deal with it, compare with a tolerance", but matlab has a symbolic toolbox. This also includes rational numbers and allows to eliminate this issue for some functions. Don't expect this to be a simple solution.