Reputation: 53
I am using contourf
to generate a contour plot for a 2 variable function.
My function is Z = f(x,y)
.
I generate x and y through meshgrid
function in matlab and generate values for Z
and then plot the contour using contour(x,y,z)
.
I want to be able to calculate the volume under this generated contour. Can anyone please help ?
Thanks in advance
Upvotes: 0
Views: 1268
Reputation: 2469
couldn't you simply use a integral approximation like a riemann sum? Assuming uniform spacing for x and y something like this should work
delta_x = x(2) - x(1);
delta_y = y(2) - y(1);
vol = sum(Z(:)) * delta_x * delta_y;
This will not be the EXACT volume, but an approximation. Since you know your function you would get a more accurate answer by performing the integration of the function. But if you did not know the function you would use this method or any other numerical integration method.
From calculus we know that an actual integral is just a reimann sum where the width of each interval is infinitely small, so this should be a valid approximation
Upvotes: 1