# numerical integration – How to define a polygonal region in 2D to subsequently integrate over it?

Here is an example in 12.2.

``````poly = Polygon({{0, 0}, {1/2, Sqrt(3)/2}, {1, 1/Sqrt(3)}, {1, 0}});
NIntegrate(Log(x + y + 1), {x, y} (Element) poly)
``````

`0.366623`

Let us verify it by

``````Integrate(Log(x + y + 1), {x, y} (Element) poly)
``````

`-((36 - 12 Sqrt(3) + 12 Log(2) + 228 Sqrt(3) Log(2) + 138 Log(3) + 54 Sqrt(3) Log(3) + 9 Log(4) - 3 Sqrt(3) Log(4) + 48 Sqrt(3) Log(6) - 2 Log(8) - 2 Sqrt(3) Log(8) + 2 Sqrt(3) Log(9) - 48 Sqrt(3) Log(2 - 2/Sqrt(3)) + 90 Log(2 - Sqrt(3)) + 54 Sqrt(3) Log(2 - Sqrt(3)) - 90 Log(3 - Sqrt(3)) - 54 Sqrt(3) Log(3 - Sqrt(3)) - 180 Log(-1 + Sqrt(3)) - 108 Sqrt(3) Log(-1 + Sqrt(3)) + 72 Log(1 + Sqrt(3)) - 48 Sqrt(3) Log(1 + Sqrt(3)) - 36 Log(2 + Sqrt(3)) + 24 Sqrt(3) Log(2 + Sqrt(3)) - 18 Log(3 + Sqrt(3)) - 90 Sqrt(3) Log(3 + Sqrt(3)) - 48 Log(6 + Sqrt(3)) - 52 Sqrt(3) Log(6 + Sqrt(3)) - 72 Log(3 + 2 Sqrt(3)) + 48 Sqrt(3) Log(3 + 2 Sqrt(3)) + 36 Log(9 + 5 Sqrt(3)) - 24 Sqrt(3) Log(9 + 5 Sqrt(3)))/(8 Sqrt( 3) (19 + 11 Sqrt(3)) (-45 + 26 Sqrt(3))))`

``````N(%)
``````

`0.366623`

Addition. `NIntegrate` produces a different result if the vertices are taken couunter-clockwise as

``````poly1 = Polygon({{1, 1/Sqrt(3)}, {1/2, Sqrt(3)/2}, {0, 0}, {1, 0}});
NIntegrate(Log(x + y + 1), {x, y} (Element) poly1)
``````

`0.17812`

shows. `Integrate` produces the same:

``````Integrate(Log(x + y + 1), {x, y} (Element) poly1)
``````

`(-18 - 18 Sqrt(3) + 117 Log(2) + 88 Sqrt(3) Log(2) + 297 Log(3) + 141 Sqrt(3) Log(3) - 417 Log(4) - 209 Sqrt(3) Log(4) - 574 Log(8) - 287 Sqrt(3) Log(8) - 396 Log(27) - 228 Sqrt(3) Log(27) + Log(216) + Sqrt(3) Log(216) + 6 Log(1728) + 4 Sqrt(3) Log(1728) - 6 Log(46656) - 4 Sqrt(3) Log(46656) + 4 Log(452984832) + 2 Sqrt(3) Log(452984832) - 594 Log(18 - 8 Sqrt(3)) - 342 Sqrt(3) Log(18 - 8 Sqrt(3)) - 288 Log(11 - 5 Sqrt(3)) - 144 Sqrt(3) Log(11 - 5 Sqrt(3)) + 594 Log(9 - 3 Sqrt(3)) + 342 Sqrt(3) Log(9 - 3 Sqrt(3)) + 1188 Log(5 - Sqrt(3)) + 684 Sqrt(3) Log(5 - Sqrt(3)) + 288 Log(-8 (-2 + Sqrt(3))) + 144 Sqrt(3) Log(-8 (-2 + Sqrt(3))) - 591 Log(6 + Sqrt(3)) - 279 Sqrt(3) Log(6 + Sqrt(3)) + 1179 Log(7 + Sqrt(3)) + 567 Sqrt(3) Log(7 + Sqrt(3)) + 297 Log(15 + 8 Sqrt(3)) + 141 Sqrt(3) Log(15 + 8 Sqrt(3)) - 297 Log(17 + 9 Sqrt(3)) - 141 Sqrt(3) Log(17 + 9 Sqrt(3)))/(8 Sqrt( 3) (-3 + 2 Sqrt(3)) (9 + 5 Sqrt(3)))`

``````N(%)
``````

`0.17812`