I have the following Matlab function:
function in_out = in_or_out(x)
sum = 0;
for i = 1 : length(x)
sum = sum + (x(i) - 1/2).^2;
end
if sum <= 1/4
in_out = 1;
else
in_out = 0;
end
end
If I pass as input [.8, .1]
, sum = 0.250000000000000
after the for loop terminates. However, the if sum <= 1/4
check fails and 0
is returned (i.e. according to Matlab 0.250000000000000
is not <=
1/4
). Why is this happening?