Why do I get an error when I try to use the DBLQUAD function with the QUADGK specified as the method in MATLAB 7.8 (R2009a)?

1 view (last 30 days)
I want to numerically evaluate a double integral over the limits -INF to INF for my objective function. Since only the QUADGK function allows limits as INF, I use it with the function DBLQUAD.
I get an error when I try to execute it.
The objective function is:
function z = obj_fun(x,y,rho_g,p_x,p_y)
p1x = sqrt((1-p_x)/p_x);
p0x = -1/p1x;
p1y = sqrt((1-p_y)/p_y);
p0y = -1/p1y;
tx = normcdf(x);
zx = (tx > p_x).*p0x + (tx < p_x).*p1x;
ty = normcdf(y);
zy = (ty > p_y).*p0y + (ty < p_y).*p1y;
xy = zeros(numel(x),2);
xy(:,1) = x(:);
xy(:,2) = y(:);
ze = reshape(mvnpdf(xy,zeros(size(xy)),[1 rho_g; rho_g 1]),size(x));
z = ze .* zx .* zy;
I call it using:
a = dblquad(@(x,y) obj_fun(x,y,0.5,0.25,0.75),-inf,inf,-inf,inf,1e-5,@quadgk)
??? Error using ==> quadgk at 148
Parameters must be a character.
Error in ==> dblquad at 60
Q = quadf(@innerintegral, ymin, ymax, tol, trace, intfcn, ...

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 12 Apr 2012
This enhancement has been incorporated in Release 2012a (R2012a). For previous product releases, read below for any possible workarounds:
To use the function DBLQUAD with the method QUADGK, a wrapper function needs to be used. This is because the calling sequence is different for the function QUADGK than what is passed from the function DBLQUAD.
The wrapper code would look like:
myquad = @(fun,a,b,tol,trace,varargin)quadgk(@(x)fun(x,varargin{:}),a,b,'AbsTol',tol);
a = dblquad(@(x,y)obj_fun(x,y),-inf,inf,-inf,inf,1e-5,myquad);
As a side note, using INF as function limits introduces a singularity at the end points. The example objective function also has discontinuities in the objective function that are not efficient for the integration.
It is recommended that, if possible, specify finite limits for the integration and break the interval into smaller parts, integrate each continuous part using the method QUAD2D and then add the results up.
The attached MATLAB-file demonstrates how to accomplish the above for the given objective function.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!