Hi guys, I am new using Matlab and I've been posting some questions in the recent time and I hope you be patient with me. I am having a trouble with the code
c = 2;
n = 100;
x = zeros(1,n);
xy = zeros(1,n);
rej = zeros(1,n);
rejy = zeros(1,n);
irv = 1;
irej = 1;
while irv <= n
y = rand(1);
u = rand(1);
if u <= 2*y/c
x(irv) = y;
xy(irv) = u*c;
irv = irv+1;
else
rej(irej) = y;
rejy(irej) = u*c;
irej = irej + 1;
end
end
plot(x,xy)
plot(rej,rejy)
plot(0:1,2*y)
I wanted the result to be as follows : the graph of 2*y which is a segment and under this segment the accepted values and above the rejected ones. What is missing here? Thank you in advance