Hi,
I have a bivariate normal distribution as follows f(x):
m = 0; c = [0.5 0.8; 0.8 2.0]; x1 = -4:0.2:4; x2 = -4:0.2:4; [X1, X2] = meshgrid(x1,x2); X = X1(:)'; Y = X2(:)'; fun = @(X, Y) 1/(2*pi*(det(c))^(0.5))* exp(-(0.5)*sum(([X; Y]-m).*(inv(c)*([X; Y]-m)))); i = @(X)integral(@(Y)fun(X,Y),-inf,inf,'ArrayValued',true); fplot(i)
And this gives output:
I want to find the f(x / y = 1.5)
I have tried to find f(x) and f(y) and then filter out y = 1.5 to get the x values from the distribution. but this method is not working and giving errors as follows:
mu_x = 0; c = [0.5 0.8; 0.8 2.0]; x1 = -4:0.2:4; x2 = -4:0.2:4; [X1,X2] = meshgrid(x1,x2); X = X1(:)'; Y = X2(:)'; fun = @(X, Y) 1/(2*pi*(det(c))^(0.5))* exp(-(0.5)*sum(([X; Y]-mu_x).*(inv(c)*([X; Y]-mu_x)))); px = @(X)integral(@(Y)fun(X,Y),-inf,inf,'ArrayValued',true); py = @(Y)integral(@(X)fun(X,Y),-inf,inf,'ArrayValued',true); %vq1 = interp1(-3:0.2:3,px,-3:0.2:3)
px = px([-3:0.2:3]) p = [px([-3:0.2:3]); py([-3:0.2:3])] fplot(py)
The error :
Error using vertcatDimensions of arrays being concatenated are not consistent.Error in pg2>@(X,Y)1/(2*pi*(det(c))^(0.5))*exp(-(1/2)*sum(([X;Y]-mu_x).*(inv(c)*([X;Y]-mu_x)))) (line 109) fun = @(X, Y) 1/(2*pi*(det(c))^(0.5))* exp(-(1/2)*sum(([X; Y]-mu_x).*(inv(c)*([X; Y]-mu_x))));Error in pg2>@(Y)fun(X,Y) (line 110) px = @(X)integral(@(Y)fun(X,Y),-inf,inf,'ArrayValued',true);Error in integralCalc/iterateArrayValued (line 156) fxj = FUN(t(1)).*w(1);Error in integralCalc/vadapt (line 130) [q,errbnd] = iterateArrayValued(u,tinterval,pathlen);Error in integralCalc (line 103) [q,errbnd] = vadapt(@minusInfToInfInvTransform,interval);Error in integral (line 88)Q = integralCalc(fun,a,b,opstruct);Error in pg2>@(X)integral(@(Y)fun(X,Y),-inf,inf,'ArrayValued',true) (line 110) px = @(X)integral(@(Y)fun(X,Y),-inf,inf,'ArrayValued',true);Error in pg2>dist (line 113) px = px([-4:0.2:4])
How do i get the values f(x) and f(y) from px and py in range -4:0.2:4 so that i can find f(x / y = 1.5)?
Best Answer