There are two problems with your code:
- "==" doesn't work well with floating point precision (EDIT: understatement)
- "if (final(1,:) == final(2,:))" should read "if all(final(1,:) == final(2,:))"
--- EDIT ---
Make sure you read the link provided by Walter and Floating points by Cleve Moler. The simple rule is: never test if two floating point values are equal. --- EDIT ---
The internal representation and what is displayed differ. With Matlab the display format can be controlled with the function, FORMAT. With format('hex') the full internal precision is shown. Try
>> v1 = 1/3;
>> v2 = 0.333;
>> v3 = 0.3333;
>> format('hex')
>> v1
v1 =
3fd5555555555555
>> v2
v2 =
3fd54fdf3b645a1d
>> v3
v3 =
3fd554c985f06f69
>>
>> format('short')
Best Answer