function pdf=dfray(a, samples) % dfray(a, samples) Generates a Rayleigh pdf with parameter a. samples % sets the size of the numerical representation, and is optional. The % default sample size is 1000. if nargin==1 samples=1000; end if a<=0 error('invalid value for a') end V=sqrt((pi-2)/(2*(a^2))); X=5*V; while (a^2)*X*exp(-((a*X)^2)/2) > 1e-6 X=X+V; end x=[0:X/samples:X]; p=(a^2).*x.*exp(-((a*x).^2)./2); pdf=[0 1; x' p']; if ispf(pdf)==0 p=p./ttlprob(pdf); pdf=[0 1; x' p']; end