0

Why when run this loop:

while gamma <=3
    tab_gamma(j)=gamma;
    if gamma <0.0001
        gamma=gamma+0.00001;
    elseif gamma <0.001
        gamma=gamma+0.0001;
    elseif gamma <0.01
        gamma=gamma+0.001;
    elseif gamma<0.1
        gamma=gamma+0.01;
    elseif gamma <1.0
        gamma=gamma+0.1;
    elseif gamma <2.0
        gamma=gamma+0.1;
    elseif gamma <=3.0
        gamma=gamma+0.2;
    end
    j=j+1; 
end

I get this: Result Why it can't understand changing 0.1 is greater than 0.1 and less than 1, so it should change inrementation.

I want it to make there 0.1, 0.2, 0.3 etc. I tried changing digits with "digits" function, but It didn't work for me.

  • 2
    This is a well-known issue with floating point numbers. Don't do naive comparisons on float values. Instead, do something like `abs(gamma - 0.0001) – Adriaan Dec 19 '22 at 14:12

0 Answers0