I have a closed 2d surface as below:
r=1+0.1*sin(5*theta)+a*sin(6*theta);
x=r.*cos(theta);
y=r.*sin(theta);
plot(x,y);
I was wondering what would be the most efficient way to find its area?
From MATLAB documentation: http://www.mathworks.com/help/matlab/ref/polyarea.html
You can use polyarea
Sintax
A = polyarea(X,Y)
A = polyarea(X,Y,dim)
Description
A = polyarea(X,Y)
returns the area of the polygon specified by the vertices in the vectors X
and Y
.
If X
and Y
are matrices of the same size, then polyarea returns the area of polygons defined by the columns X
and Y
.
If X
and Y
are multidimensional arrays, polyarea returns the area of the polygons in the first nonsingleton dimension of X
and Y
.
A = polyarea(X,Y,dim)
operates along the dimension specified by scalar dim.
Example
L = linspace(0,2.*pi,9);
xv = 1.2*cos(L)';
yv = 1.2*sin(L)';
xv = [xv ; xv(1)];
yv = [yv ; yv(1)];
A = polyarea(xv,yv)
// Result A = 4.0729
plot(xv,yv);
title(['Area = ' num2str(A)])
axis image