你能帮助我理解为什么情节不会收敛吗?我在代码中遗漏了什么?我正在根据试验次数绘制均值和方差。 THX
samplesize = 10;
trialsize = 1000;
firstvector = [1:trialsize];
vectorB = zeroes(trialsize,1);
vectorC = zeroes(trialsize,1)
for i=1:trialsize
v1 = rand(samplesize, 1)
vectorB(i) = mean(v1);
vectorC(i) = var(v1);
end
plot(firstvector,vectorB)
plot(firstvector,vectorC)
答案 0 :(得分:0)
这是你想做的吗?基本上一次取10个样本的平均值和变量?所以第一个循环需要10个,接下来的20个,接下来的30个...... 1000次?
在你一次只取10个随机样本的平均值和变量之前......你永远不会收敛。
samplesize = 10;
trialsize = 1000;
firstvector = [1:trialsize];
vectorB = zeros(trialsize,1);
vectorC = zeros(trialsize,1);
v1 = rand(trialsize*samplesize, 1);
for i=1:trialsize
vectorB(i) = mean(v1(1:i*samplesize));
vectorC(i) = var(v1(1:i*samplesize));
end
subplot(2,1,1);plot(firstvector,vectorB)
subplot(2,1,2);plot(firstvector,vectorC)