Generate a sample $X_1, ..., X_n$, of size $n = 1000$ from the beta law and, draw their histogram.
Draw on the same graph the probability density. using Matlab
I can't plot them on the same graph
here is my code
function [ X] = Beta( a,b, n )
X=zeros(n,1);
for i=1:n
u1 = rand(a,1);
Y1=-(1/b)*log(prod(u1));
u2 = rand(a,1);
Y2=-(1/b)*log(prod(u2));
X(i,1)=Y1/(Y1+Y2);
end
x = 0:0.01:1;
y1 = betapdf(x,2,2);
hist(X)
hold on
plot(x,y1)
hold off