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 个)
Walter Roberson
2012-3-9
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 );
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!