Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.