$title maximum area of an N-gon option limrow=0, limcol=0; set vertices/1*20/; alias (vertices, i, j); scalar N "number of vertices (max 20)" /8/; variable rho(vertices) "polar radius" theta(vertices) "polar angle" area; scalar pi; pi = 4.0 * arctan(1.0); rho.lo(vertices) = 0.0; rho.up(vertices) = 1.0; theta.lo(vertices) = 0.0; theta.up(vertices) = pi; equations inscribe(i,j) "ensure that each vertex pair no more than 1 apart" monotonic(vertices) "enforce monotonic increase in polar angles" objective "area of polygon"; inscribe(i,j)$(ord(i) < ord(j) and ord(j) <= N).. rho(i)**2 + rho(j)**2 - 2*rho(i)*rho(j)*cos(theta(i) - theta(j)) =l= 1; monotonic(vertices)$(ord(vertices) < N).. theta(vertices) =l= theta(vertices+1); objective.. area =e= .5*sum(i$(ord(i)