How to generate random numbers (in between minimum and maximum limits) using "Monte-Carlo" method with a specified distribution using Matlab ?
Our steps to solve the problem were:
1- Specify the sample distribution ('generalized extreme value' distribution "using mark allfitist()")
2- Find the parameters of the sample data
3- Make object of the required distribution
4- Truncate the distribution by Data's minimum and maximum
5- Generate n sample
6- Draw curve
7- Compare mean, standard deviation and parameters
Here's the code:
function [] = GenRand_gev(Data,size)
Minimum=min(Data);
Maximum=max(Data);
Data_Mean = mean(Data);
Data_Standard_Diviation = std(Data);
% get the parameters
LN= mle(Data,'distribution','generalized extreme value');
Data_K=LN(1);
Data_sigma=LN(2);
Data_mu=LN(3);
% make object of the required distribution
pd_gev = makedist('generalized extreme value','K',Data_K,'sigma',Data_sigma,'mu',Data_mu);
% Truncate the distribution by minimum and maximum
t= truncate(pd_gev,Minimum,Maximum);
% generate n sample
r = random(t,size,1);
% draw distribution curve
histfit(r,[],'generalized extreme value');
legend('Generated sample','distribution curve');
Gen_Mean = mean(r);
Gen_Standard_Diviation = std(r);
LN1 = gevfit(r);
Gen_k=LN1(1);
Gen_sigma=LN1(2);
Gen_mu=LN1(3);
end
Is this correct??
When comparing the Mu, Sigma and the parameters of the sample data and the generated numbers (Data_Mean & Gen_Mean), (Data_Standard_Diviation & Gen_Standard_Diviation), (Data_K & Gen_k), (Data_sigma & Gen_sigma), (Data_mu & Gen_mu) for different sizes they found to be very different.
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire