矩估计==最大似然估计
样本容量取 10~1000
n = 10:1:1000;
dsigma = zeros(length(n),1);
dmu = zeros(length(n),1);
for i = 1:length(n)
y = sigma.*randn(n(i),1) + mu;
[mu_, sigma_] =estimate(y , n(i));
dsigma(i) = abs(sigma - sigma_);
dmu(i) = abs(mu - mu_);
end
plot(n,dsigma)
hold on
plot(n,dmu)
legend('△σ','△μ')
hold off
矩估计、最大似然估计函数
function [mu_, sigma_] = estimate(y , n)
mu_ = sum(y)/n;
sigma_ = sum((y-mu_).^2)/n;
end