Path: news.mathworks.com!not-for-mail
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$1@fred.mathworks.com>
References: <i3p629$8oh$1@fred.mathworks.com> <i3p9ap$9ih$1@fred.mathworks.com> <i3pfrd$aca$1@fred.mathworks.com> <i3pqlo$ctg$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1281409623 2597 172.30.248.38 (10 Aug 2010 03:07:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 10 Aug 2010 03:07:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2440204
Xref: news.mathworks.com 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

-Chen