1
$\begingroup$

Let's define a region as r=Polygon[{{-a,0},{a,0},{a,h}}]. I want to integrate some function over that area. Say x^2. So, Assuming[a>0&&h>0,Integrate[x^2,Element[{x,y},r]]] I get a^3h/3, as expected.

But, what if I want to have a four-sided polygon instead? If I redefine the region as r=Polygon[{{-a,0},{a,0},{a,h},{0,h}}], and then do Assuming[a>0&&h>0,Integrate[x^2,Element[{x,y},r]]], it can't do the integral.

$\endgroup$
2
  • 5
    $\begingroup$ r = Polygon[{{-a, 0}, {a, 0}, {a, h}, {0, h}}]; Area[r, Assumptions -> h > 0 && a > 0] $\endgroup$
    – cvgmt
    Apr 27 at 22:40
  • $\begingroup$ This works for areas. What if I want to integrate some function over the region, like x^2? I've modified the question to reflect this. $\endgroup$ Apr 29 at 15:37

1 Answer 1

1
$\begingroup$
Clear["Global`*"]

r = Polygon[{{-a, 0}, {a, 0}, {a, h}, {0, h}}];

As pointed out by cvgmt in a comment, the area is

area = Assuming[a > 0 && h > 0, Area[r]]

(* (3 a h)/2 *)

As a workaround to do the integral, break the region r into three triangular regions

enter image description here

r21 = Polygon[{{-a, 0}, {0, 0}, {0, h}}];
r22 = Polygon[{{0, 0}, {0, h}, {a, 0}}];
r23 = Polygon[{{0, h}, {a, h}, {a, 0}}];

The integral can be done over the subregions

area == Assuming[a > 0 && h > 0, 
  Total[Integrate[1, {x, y} ∈ #] & /@ {r21, r22, r23}]]

(* True *)

EDIT: For a more complicated integrand

f[x_, y_] := (x^2 + 3) (x + y)

Assuming[a > 0 && h > 0, 
 Total[Integrate[f[x, y], {x, y} ∈ #] & /@ {r21, r22, r23}] // 
  Simplify]

(* 1/60 a h (60 a + 12 a^3 + 120 h + 11 a^2 h) *)

EDIT 2: The subdivisions do not need to be only triangles; however, there are limitations. Arbitrary polygons cannot be handled. Even a Polygon representing a Rectangle fails.

r31 = Polygon[{{0, 0}, {0, h}, {a, h}, {a, 0}}];

Assuming[a > 0 && h > 0, 
 Total[Integrate[f[x, y], {x, y} ∈ #] & /@ {r21, r31}] // Simplify]

enter image description here

However, the equivalent Rectangle works

r32 = Rectangle[{0, 0}, {a, h}];

Assuming[a > 0 && h > 0, 
 Total[Integrate[f[x, y], {x, y} ∈ #] & /@ {r21, r32}] // Simplify]

(* 1/60 a h (60 a + 12 a^3 + 120 h + 11 a^2 h) *)
$\endgroup$
3
  • $\begingroup$ My edit yesterday specifically addressed an integral other than an area calculation. $\endgroup$
    – Bob Hanlon
    Apr 29 at 15:41
  • $\begingroup$ Breaking it up works, but are we really limited only to triangular regions? $\endgroup$ Apr 29 at 15:41
  • $\begingroup$ Hmm. That's a bummer. $\endgroup$ May 4 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.