From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help with discrete double integral
Date: Tue, 10 Aug 2010 03:07:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 30
Message-ID: <i3qfon$2h5$>
References: <i3p629$8oh$> <i3p9ap$9ih$> <i3pfrd$aca$> <i3pqlo$ctg$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1281409623 2597 (10 Aug 2010 03:07:03 GMT)
NNTP-Posting-Date: Tue, 10 Aug 2010 03:07:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2440204
Xref: comp.soft-sys.matlab:660543

Hi Roger,

   Thank you for your reply. I tried your method and it seems like not working right. 
I tried this:
f(x,y) = cos(x).*sin(y) and q(x) = cos(x).x is from 0 to pi/2,y is from pi/2 to 2*pi. The exact integral value of f(x,y)*q(x) over x and y is - pi/4.

  The code is :
%%% Integration test

x = linspace(0,pi/2,100);
y = linspace(pi/2,2*pi,100);

% method 1,using quad2d
func = @(x,y) cos(x).^2.*sin(y);
I1 = quad2d(func,0,pi/2,pi/2,2*pi);

% method 2,using double trapz
[X Y] = meshgrid(x,y);
f = cos(X).*sin(Y);
q = cos(x);
I2 = trapz(x,q.*trapz(y,f.').');

%%%%% End of code %%%%%%%%%

The results are: I1 = -0.7854(which is - pi/4) and I2 = 5.2042e-017 (which is zero actually).

Did I understand your method wrong?
Thanks a lot