I want to verify that random numbers generated by exprnd match the exponential distribution. I used Matlab's ksdensity function – here's the code:
R = exprnd(10,1000,1);
[f,xi]=ksdensity(R);
x = 0.01:0.01:60;
y = 0.1.*exp(-x./10);
plot(xi,f,x,y);
legend('exprnd','exp')
But the resulting plot shows that they do not match.
I checked and no random number is below zero, however the plot of ksdensity shows some points below zero that have probability. Why is that?
By default
ksdensityassumes that the support of the distribution is unbounded, i.e., a two-sided distribution. You can specify positive support via the'Support'parameter: