Problem using dblquad

Hi everyone, I'm trying to use the function dblquad but I'm having some problems. This is my code:
mu = [2,1];
sigma = [0.2,0;0,0.1];
df=@(x1,x2)mvnpdf([x1,x2],mu,sigma);
Q = dblquad(df, 0, 2, 0, 1)
And Matlab throws me the error: X and mu must have the same number of columns, where X is the first input of the mvnpdf function. Anyone can help me? Regards!

回答(1 个)

fun(x,y) must accept a vector x and a scalar y and return a vector of values of the integrand.
You do not know ahead of time how long the vector x is going to be, and there is no explicit statement about whether it is a row vector or a column vector. [x,y] might break on incompatible dimensions or it might not -- but [x,y] is very unlikely to be the same size as your mu.
Possible workaround:
df = @(x,y) arrayfun( @(x1,y) mvnpdf([x1,y],mu,sigma), x );

1 个评论

When I try to do this I get another error: Input argument "y" is undefined. How can I fix it? Regards!

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by