How to integrate over a discrete 2D surface in MATLAB?

前端 未结 2 1974
无人及你
无人及你 2020-12-30 17:20

I have a function z = f(x, y), where z is the value at point (x, y). How may I integrate z over the x-y plan

2条回答
  •  时光取名叫无心
    2020-12-30 17:59

    If you have a discrete dataset for which you have all the x and y values over which z is defined, then just obtain the Zdata matrix corresponding to those (x,y) pairs. Save this matrix, and then you can make it a continuous function using interp2:

    function z_interp = fun(x,y)
    
        z_interp = interp2(Xdata,Ydata,Zdata,x,y);
    
    end
    

    Then you can use integral2 to find the integral:

    q = integral2(@fun,xmin,xmax,ymin,ymax)
    

    where @fun is your function handle that takes in two inputs.

提交回复
热议问题