Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Topic: Double integral on vector data
Replies: 1   Last Post: May 27, 2012 11:08 PM

 Messages: [ Previous | Next ]
 Roger Stafford Posts: 5,660 Registered: 12/7/04
Re: Double integral on vector data
Posted: May 27, 2012 11:08 PM

pmassicotte <pmassicotte@hotmail.com> wrote in message <709f2305-2da2-4e70-9bcb-3c2bea819160@ra8g2000pbc.googlegroups.com>...
> I would like to calculate a double integral using trapz function.
> You can find the code bellow to reproduce the calculations.
> Data:
> Ex1 = Excitation data. First column
> Step 1: Create the surface from witch I want to calculate the double integral
> Comp1 = Em1(:,2) * Ex1(:,2)';
> Step 2: Meshgrid
> [X,Y] = meshgrid(Ex1(:,1), Em1(:,1));
> Step 3: Integrate
> V1 = trapz( Y(:,1), (trapz(X(1,:),Comp1, 2)) )

- - - - - - - - - - -
I haven't reproduced your calculation, but it looks as though it would give you the correct answer. However, there are two respects in which your code could be simplified.

First, there is no need whatever to compute the 'meshgrid' function as you have. You could just as well have written:

V1 = trapz(Em1(:,1),trapz(Ex1(:,1),Comp1,2));

without doing the 'meshgrid' at all. It doesn't accomplish anything for you here.

Second, as you have defined 'Comp1' this problem doesn't have to be done as a double integral. The two vectors Ex1(:,2) and Em1(:,2) can be factored out separately in the integrals so as to obtain the product of two single integrals:

V1 = trapz(Em1(:,1),Em1(:,2)) * trapz(Ex1(:,1),Ex1(:,2));

which involves much less computation. This is true because in calculus

int( int(f(x)*g(y) dy) dx = int(f(x) dx) * int(g(y) dy)

over a rectangular x-y area.

Roger Stafford

Date Subject Author
5/23/12 Filoche
5/27/12 Roger Stafford