2

I am creating a list of combinations of 3 coefficients. The sum is 1 and the increment for each coefficient is 0.05:

s=0;
for x1 = 0 : 0.05 : 1
    for x2 = 0 : 0.05 : (1-x1)
        x3 = 1-x1-x2;
        s=s+1;
        fprintf('%0.2f %0.2f %0.2f \n',x1,x2,x3)
    end
end

The number expected is 231 but I got 229. Checking the result:

...
0.85 0.00 0.15 
0.85 0.05 0.10 
0.85 0.10 0.05 
0.90 0.00 0.10 
0.90 0.05 0.05 
0.90 0.10 -0.00 
0.95 0.00 0.05 
1.00 0.00 0.00

I found '0.85 0.15 0.00' and '0.95 0.05 0.00' were missing but I can't explain why. Could anyone give me some hint about this. Much appreciate for your time.

pughon
  • 19
  • 5

1 Answers1

4

You’re asking for hints, so I’ll give you some.

Read this Q&A: Why is 24.0000 not equal to 24.0000 in MATLAB?. Now think about what the upper limit for x2 (1-x1) exactly is and how you get there by incrementing 0 in steps of 0.05.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120