我有一个直方图
hist(A, 801)
当前类似于法线,但最大值在y = 1500,平均值在x = 0.5。我想对其进行归一化,所以我尝试了
h = hist(A, 801)
h = h ./ sum(h)
bar(h)
现在我得到了一条最大值为y = .03的法线曲线,但是平均值为x = 450。
如何降低频率,使总和为1,同时保持相同的x范围?
A源自
A = walk(50000, 800, .05, 2, .25, 0)
在哪里
function [X_new] = walk(N_sim, N, mu, T, sigma, X_init)
delt = T/N;
up = sigma*sqrt(delt);
down = -sigma*sqrt(delt);
p = 1./2.*(1.+mu/sigma*sqrt(delt));
X_new = zeros(N_sim,1);
X_new(1:N_sim,1) = X_init;
ptest = zeros(N_sim,1);
for i = 1:N
ptest(:,1) = rand(N_sim,1);
ptest(:,1) = (ptest(:,1) <= p);
X_new(:,1) = X_new(:,1) + ptest(:,1)*up + (1.-ptest(:,1))*down;
end
根据您的代码,总和为1。
您可能希望积分等于1(以便可以与理论pdf进行比较)。在这种情况下:
[h, c] = hist(A, 801); %// c contains bin centers. They are equally spaced
h = h / sum(h) / (c(2)-c(1)); %// normalize to area 1
trapz(c,h) %// compute integral. Should be approximately 1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句