From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help with discrete double integral
Date: Mon, 9 Aug 2010 21:07:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <i3pqlo$ctg$>
References: <i3p629$8oh$> <i3p9ap$9ih$> <i3pfrd$aca$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1281388024 13232 (9 Aug 2010 21:07:04 GMT)
NNTP-Posting-Date: Mon, 9 Aug 2010 21:07:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:660500

"Chen Chen" <> wrote in message <i3pfrd$aca$>...
>     I just simplify the problem i want to solve to this imple double mathematical problem. I thought it would be confusing if I explained the whole thing. 
>     Sorry I didn't state the problem clearly. Here is a specific version.
>     These numbers are given sets of data. That is: x and y are two sets of data which are given at the first place. Let's say both the x and y are 1 X N vectors. f(x,y) is given too and it's an N X N matrix. q(x) is a function depending on x only and I know the function already. So q(x) is a 1 X N vectors with known numbers. 
>     My problem is that I don't know how to integrate f(x,y)*f(x) over x and y numerically. I hope I expained it clearly this time.
> Chen
- - - - - - - - - -
  With discrete-valued variables you cannot use any of matlab's "quad" type integration routines which require functions.  However you can use an iterated form of trapz which does trapezoidal integration.  Let X be a column vector of monotone x values in which X(1) = a and X(N) = b.  Let Y be a column vector of monotone y values for which Y(1) = c and Y(M)= d.  Let F be an N x M array in which

 F(i,j) = f(X(i),Y(j)).  (Your f(x,y) )

Let Q be a column vector in which Q(i) = q(X(i)) (your q(x) ).  Then do this:

 I = trapz(X,Q.*trapz(Y,F.').');

This will give the two-dimensional "trapezoidal" approximation to your desired double integral over the stated rectangle.

  The approximation made is this.  In each rectangular cell with corners at

 (X(i),Y(j), (X(i+1),Y(j), (X(i),Y(j+1), and (X(i+1),Y(j+1),

the integral is approximated by the average of the integrand q(x)*f(x,y) evaluated at these four corners multiplied by the (signed) area of the rectangle.  The final value I is the sum of these.

  This integration can be considered as a first-order approximation to the exact double integral.  I think if you look hard enough there may be some higher order integration routines listed on the file exchange which could possess higher accuracy, though if so, I don't remember where they are located.

Roger Stafford