2017-04-06 61 views

回答

0

使用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的必要條件。

enter image description here

綠色劇情要求的PDF文件。紅色圖被添加爲參考,代表一個常數平均值的pdf(等於平均值​​)。

+0

謝謝;我試圖得到一個3D represantation。 – EKtee