I have a matrix of points F(x,y) = z, but I have no expression for F(x,y). x is from [0-2pi] and y is from [0-pi]. For each pair of "coordinates", I have a value of z.
I would like to perform a double integration from 0-2pi and 0-pi of F. Can I do this computationally (MatLab) without having an analytical expression?
Thanks!
Assuming that the (x,y) grid is uniform, you can approximate the integral by a 2D-Riemman sum as follows:
result = sum(z(:))*delta_x*delta_y;
where delta_x
, delta_y
are the grid spacings in the x and y directions. In your case these can be computed as
delta_x = 2*pi/numel(x); %// or 2*pi/(numel(x)-1)
delta_y = pi/numel(x); %// or pi/(numel(x)-1)
A perhaps more intuitive interpretation: compute the mean value of the function and multiply by the area of the (x,y) domain:
result = sum(z(:))/(numel(x)*numel(y)) * 2*pi^2; %// or replace numel(x)*numel(y)
%// by numel(z)