gpt4 book ai didi

matlab - 概率密度函数的理论图

转载 作者:行者123 更新时间:2023-12-02 03:31:50 25 4
gpt4 key购买 nike

我正在使用概率密度函数图:

y = zeros(1,10000);
for j=1:10000
r = rand(100,1);
for i=1:100
y(j) = y(j) + r(i) - 0.5;
end
y(j) = y(j)/sqrt(100);
end
[n,x] = hist(y,100);
plot(x,n/10000/diff(x(1:2)));
hold on;

但是我也想打印理论。我似乎已经管理的最好的是:

plot(x,normpdf(x,0,1),'r');

但这根本不符合实际。我在这里错过了什么?这是我的情节目前的样子。蓝色是实际的,红色是理论的。

enter image description here

最佳答案

您的 y 不是来自均匀分布;它们来自均匀分布的 i.i.d(独立同分布)随机变量之和的分布,均值为 0,方差为 1/12。 sum approaches normal distribution随着求和变量的数量(在您的情况下为 100)变大。使用您的代码,我能够非常适合 normpdf,正确的方差为 1/12(sigma 是该数字的平方根):

y2=normpdf(x,0,sqrt(1/12));
plot(x,y2,'r');

顺便说一句,将前 8 行替换为:

r=rand(100,10000)-0.5;
y=sum(r)/sqrt(100);

关于matlab - 概率密度函数的理论图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26166743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com