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
>
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