I'm trying to create values for a variable (called r2 in my code) using random numbers on [0,1] and an if/else statement. However, I keep getting complex values for r2 when that shouldn't happen. Is there an issue with the way I wrote my code? Here it is:
r = rand(25,1)
if r < 0.5
r2 = 0.5-sqrt(0.25-(r/2));
else
r2 = 0.5+sqrt((r/2)-0.25);
end
Best Answer