【发布时间】:2017-04-08 23:47:14
【问题描述】:
如何使用 Matlab 绘制单变量正态分布,当它具有未知均值但均值也正态分布且均值已知且均值方差已知时?
例如。 N(mean, 4) 和均值 ~N(2,8)
【问题讨论】:
-
意思,意思,意思,鸡蛋,培根,意思
如何使用 Matlab 绘制单变量正态分布,当它具有未知均值但均值也正态分布且均值已知且均值方差已知时?
例如。 N(mean, 4) 和均值 ~N(2,8)
【问题讨论】:
使用law of total probability,可以写
pdf(x) = int(pdf(x | mean) * pdf(mean) dmean)
所以,我们可以在Matlab中计算如下:
% define the constants
sigma_x = 4;
mu_mu = 2;
sigma_mu = 8;
% define the pdf of a normal distribution using the Symbolic Toolbox
% to be able to calculate the integral
syms x mu sigma
pdf(x, mu, sigma) = 1./sqrt(2*pi*sigma.^2) * exp(-(x-mu).^2/(2*sigma.^2));
% calculate the desired pdf
pdf_x(x) = int(pdf(x, mu, sigma_x) * pdf(mu, mu_mu, sigma_mu), mu, -Inf, Inf);
pdfCheck = int(pdf_x, x, -Inf, Inf) % should be one
% plot the desired pdf (green) and N(2, 4) as reference (red)
xs = -40:0.1:40;
figure
plot(xs, pdf(xs, mu_mu, sigma_x), 'r')
hold on
plot(xs, pdf_x(xs), 'g')
请注意,我还检查了计算出的pdf的积分确实等于1,这是成为pdf的必要条件。
绿色图是请求的 pdf。添加红色图作为参考,表示恒定均值(等于平均均值)的 pdf。
【讨论】: