Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
double integral with discrete data - not a function

Subject: double integral with discrete data - not a function

From: Amritpal Singh

Date: 8 Mar, 2002 03:35:55

Message: 1 of 2

Hi!


Integrating a two (or more) dimensional integral numerically is not
harder than a 1D integral, as long as the integration intervals are
independent.


Example:


x=linspace(x1,x2,Nx);
y=linspace(y1,y2,Ny);
[X,Y]=meshgrid(x,y);
% Note that the columns in X and rows in Y are constant
Z=f(X,Y)


% Evaluate the integral in two steps using trapz
% given a matrix trapz will integrate each column, therefore
% we begin by integrating over y (ofocurse, you could integrate
% over x first by transposing Z)


Iy=trapz(y,Z);
% Now integrating also over x we get the answer


I=trapz(x,Z);


%--------------


I tried with


f(x,y)=x^2+y
integrated over -2<=x<=2 and -3<=y<=1


Analytic answer: I=16/3=5.3333...


Using the above procedure with Nx=Ny=100: I=5.3377...
                          with Nx=Ny=500: I=5.3337...


Hope this is useful for you!


Regards
Amrit


John B. Smith wrote:
>
>
> I have a 20 x 250 matrix (describing pressure in a
> bearing). To
> calculate the load that the bearing will carry, I have to
> double
> integrate the pressure. (Obviously, the end result will be
> one
> number.) I know how to double integrate a function, but I
> dealing
> with numerical data here.
>
> How do I do this double integral? Thanks for your help.
>
> JBS
>

Subject: double integral with discrete data - not a function

From: Shen

Date: 3 Aug, 2009 20:58:02

Message: 2 of 2

"Amritpal Singh" <Amritpal.Singh@telia.com> wrote in message <eeab122.0@WebX.raydaftYaTP>...
> Hi!
>
>
> Integrating a two (or more) dimensional integral numerically is not
> harder than a 1D integral, as long as the integration intervals are
> independent.
>
>
> Example:
>
>
> x=linspace(x1,x2,Nx);
> y=linspace(y1,y2,Ny);
> [X,Y]=meshgrid(x,y);
> % Note that the columns in X and rows in Y are constant
> Z=f(X,Y)
>
>
> % Evaluate the integral in two steps using trapz
> % given a matrix trapz will integrate each column, therefore
> % we begin by integrating over y (ofocurse, you could integrate
> % over x first by transposing Z)
>
>
> Iy=trapz(y,Z);
> % Now integrating also over x we get the answer
>
>
> I=trapz(x,Z);
>
>
> %--------------

I believe the last line of code should be
> I = trapz(x,Iy);
instead of what you have there! Just a minor note. Also, a separate function must be written as such:
> function Z = f(X,Y)
> Z = X.^2+Y;
> end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us