I am trying to generate random numbers using Levy distribution in MATLAB. I am using the inverse transform method to generate random numbers and then plot its histogram for pdf estimation. Then I analytically plot the PDF of Levy distribution.
Problem: The estimated PDF and analytical PDF are not matching. I am putting my code here for reference where I have taken location parameter=5 and scale parameter=5.
clear all;
close all;
clc;
for loopr=1:1:10^8
X11(loopr)=5+5/(2*(erfcinv(rand))^2);
end
bin=[0:0.1:100];
l=0;
for loop1=5:0.1:100
l=l+1;
pdf12(l)=sqrt(5/(2*pi))*exp(-5/(2*(loop1-5)))/(loop1-5)^1.5;
end
loop1=5:0.1:100;
plot(loop1, pdf12)
hold on;
histogram(X11, bin, 'normalization', 'pdf');
hold off;