9 views (last 30 days)

Hi

I have a small query, and will appreciate your help.

I am supposed to find the integral of the product of two probability density functions, and I request for advice on how to do this numerically (on matlab).

Please see below the simple code I wrote.

Pr is p(x1) i.e the pdf of x1 over a defined space. M is p(x2|x1) is the Markov pdf over the same space.

I need to evaluate int {p(x2|x1).p(x1)}dx1

can you please help me with this? The code is below

% Initialization of target state and covariance

% P(x1)

x1=-2;P=16;

Pr=1/(sqrt(2*pi*det(P))) * exp(-(space-x1).^2/(2*det(P)));

% Markov transition density: x=Fx+v,

% v is zero mean Gaussian with covariance 4, and F=-2

% P(x2|x1)

Q=4; F=-2;

x2=F*x1;

M=1/(sqrt(2*pi*det(Q))) * exp(-(space-(-2*x2)).^2/(2*det(Q)));

Thanks

P

Tom Lane
on 10 Oct 2012

Here's an example that you may be able to adapt to your problem.

Suppose [x1;x2] have a multivariate normal distribution with mean [2;3] and variance matrix [1 .6;.6 1]. Then we know theoretically that the marginal distribution of x1 is normal(2,1), the marginal distribution of x2 is normal(3,1), and the distribution of x2 conditional on x1 is normal with mean 3+.6*(x1-2) and standard deviation sqrt(1-.6^2). Let's see if we can verify that.

% Marginal distribution of x2 computed directly at four points

normpdf(1:4,3,1)

ans =

0.0540 0.2420 0.3989 0.2420

% Same computed by integrating the marginal of x1 and conditional of x2

for j=1:4

quad(@(x)normpdf(x,2,1).*normpdf(j,3+.6*(x-2),sqrt(1-.6^2)),-10,10)

end

ans =

0.0540

ans =

0.2420

ans =

0.3989

ans =

0.2420

Tom Lane
on 8 Oct 2012

What is the "space" variable intended to represent?

Based on your integral expression, I'd expect the result to be a function of x2. I might expect your code to have calls to quad() with the upper bound of integration being the value of x2, and perhaps a loop over different possible x2 values.

You seem to use x1 to represent a variable in your text and a mean in your code. I probably would have expected to see x1,m1,P in the first density and maybe x2,x1,Q in the second.

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 0 Comments

Sign in to comment.