% n=15;
% N=100000;
% for k=1:N
%     x=randn(1,n);
%     y=randn(1,n);
%     c=corrcoef(x,y);
%     r(k)=c(2,1);
% end
clf
tr=r./sqrt(1-r.^2)*sqrt(n);
[t,xx]=hist(tr,50);
hist(tr,50);
xlim=(xx(1:49)+xx(2:50))/2;
x(1)=tp(xlim(1),n);
x(50)=1-tp(xlim(end),n);
for k=2:49
    x(k)=tp(xlim(k),n)-tp(xlim(k-1),n);
end
x=x*N;
s=sum((x-t).^2)
hold on
plot(xx,x,'r','linewidth',3);
hold off