Problem using dblquad
Show older comments
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!
Answers (1)
Walter Roberson
on 9 Mar 2012
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 Comment
ignacio rios
on 12 Sep 2012
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!