如何使用带有指定分布的“Monte-Carlo”方法使用Matlab生成随机数(介于最小和最大限制之间)?
我们解决问题的步骤是:
1-使用mark allfitist()指定样本分布('generalized extreme value'distribution“)
2-查找样本数据的参数
3-制作所需分发的对象
4-按数据的最小值和最大值
截断分布5-生成n个样本
6-绘制曲线
7-比较平均值,标准差和参数
以下是代码:
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
和
Data=[104.24
62.58
96.9
63.12
62.8
23.64
61.06
23.62
61.42
23.6
61.68
23.64
62.32
23.6
62.5
23.1
68.16
27.36
72.9
27.3
76.4
27.28
76.48
26.58
76.54
27.38
76.78
27.48
76.82
27.32
76.82
26.96
79.86
26.86
80.36
26.92
80.44
27.9
80.56
24.38
80.6
26.68
81.62
26.58
80.9
26.88
82
23.76
84.78
29.14
88.24
29.04
95.28
28.54
96.28
27.26
99.72
28.48
101.06
28.82
102.84
28.72
103.52
28.18
103.76
28.5
103.88
28.86
104.02
28.68
104.04
28.46
104.66
29.3
105.52
28.48
105.64
25.18
25.65
25.65
25.8
29.23
69.33
69.29
69.25
69.07
68.3
]
这是正确的吗?
比较Mu,Sigma和样本数据的参数以及生成的数字(Data_Mean& Gen_Mean),(Data_Standard_Diviation& Gen_Standard_Diviation),(Data_K& Gen_k),(Data_sigma& Gen_sigma),(Data_mu) & Gen_mu)他们发现不同的尺寸非常不同。
提前致谢