2D integration from irregular data

How to integrate discrete 2D data?

octave:#> int2d=sum(sum(zdata)).*dx.*dy

But this assumes that the zdata is in a regular mesh with uniform grid spacing dx and dy. If they are irregular, use griddata.

N=100; %number of points;
xreg=linspace(0,max(x),N);
yreg=linspace(0,max(y),N);
dx=xreg(2)-xreg(1);
dy=yreg(2)-yreg(1);
zdatareg=griddata(x,y,zdata,xreg,yreg);
int2d=sum(sum(zdatareg)).*dx.*dy

Advertisements

One Response

  1. If it is 1-D, then just do an interpolation

    xreg=linspace(minx,maxx,N);
    dx=xreg(2)-xreg(1);
    ydatareg=interp1(x,ydata,xreg);
    int1d=sum(ydatareg).*dx;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: