Cody

# Problem 43029. Area of polygon

Solution 1684544

Submitted on 1 Dec 2018
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
L=linspace(0,2.*pi,9); x = 1.2*cos(L)'; y = 1.2*sin(L)'; a_correct = 4.072935; assert( abs(polygon_area(x,y)-a_correct) < 1e-04 )

A = 0 A = 1.0182 A = 2.0365 A = 3.0547 A = 4.0729 A = 5.0912 A = 6.1094 A = 7.1276 A = 8.1459

Index exceeds the number of array elements (9). Error in polygon_area (line 4) A = A + det( [x(c:c+1) y(c:c+1)] ) Error in Test1 (line 5) assert( abs(polygon_area(x,y)-a_correct) < 1e-04 )

2   Fail
x = (1:10)'; y = [0,ones(1,9)]'; a_correct = 4; assert( isequal(polygon_area(x,y),a_correct) )

A = 0 A = 1 A = 0 A = -1 A = -2.0000 A = -3.0000 A = -4 A = -5 A = -6 A = -7

Index exceeds the number of array elements (10). Error in polygon_area (line 4) A = A + det( [x(c:c+1) y(c:c+1)] ) Error in Test2 (line 4) assert( isequal(polygon_area(x,y),a_correct) )

3   Fail
x=[0,5,3]'; y=[0,0,9]'; a_correct = 22.5; assert( abs(polygon_area(x,y)-a_correct) < 1e-04 )

A = 0 A = 0 A = 45

Index exceeds the number of array elements (3). Error in polygon_area (line 4) A = A + det( [x(c:c+1) y(c:c+1)] ) Error in Test3 (line 4) assert( abs(polygon_area(x,y)-a_correct) < 1e-04 )

4   Fail
x=[0,5,3,11]'; y=[0,0,9,126]'; a_correct = 162; assert( isequal(polygon_area(x,y),a_correct) )

A = 0 A = 0 A = 45 A = 324.0000

Index exceeds the number of array elements (4). Error in polygon_area (line 4) A = A + det( [x(c:c+1) y(c:c+1)] ) Error in Test4 (line 4) assert( isequal(polygon_area(x,y),a_correct) )