# Integrating in regions

I have three rectangles of the same size:

s1 = Rectangle[{-(b/2), -(h/2)}, {b/2, h/2}]
s2 = Rectangle[{-(h/2), h/2}, {h/2, h/2 + b}]
s3 = Rectangle[{-(h/2), -(h/2)}, {h/2, -(h/2) - b}]


which I combine into a region:

r = RegionUnion[Region /@ {s1, s2, s3}]


This is a simple symmetrical I-beam-ish shape. When I integrate this:

Simplify[Integrate[1, {x, y} \[Element] r], {0 < b < h}]


I get 2 bh. I should get 3 bh. Also,

Simplify[Integrate[y, {x, y} \[Element] r], {0 < b < h}]


should be zero, since it's symmetric about the x-axis. Mathematica gives me:

1/2 b h (b + h)


Any ideas? Mathematica 12.0.0.0

Your original s3 was an incorrectly specified rectangle because -(h/2) - b = ymax < ymin = -(h/2). From the docs for Rectangle,

Rectangle[{xmin,ymin},{xmax,ymax}] represents an axis-aligned filled rectangle from {xmin,ymin} to {xmax,ymax}.

Therefore integrating over s3Broken gives Undefined. Reordering the corrdinates fixes this issue.

s1 = Rectangle[{-(b/2), -(h/2)}, {b/2, h/2}];
s2 = Rectangle[{-(h/2), h/2}, {h/2, h/2 + b}];
s3 = Rectangle[{-(h/2), -(h/2) - b}, {h/2, -(h/2)}];

s3Broken = Rectangle[{-(h/2), -(h/2)}, {h/2, -(h/2) - b}];

r = RegionUnion[Region /@ {s1, s2, s3}];

Simplify[Integrate[y, {x, y} \[Element] s3Broken], {0 < b < h}] // Print;
Simplify[Integrate[1, {x, y} \[Element] r], {0 < b < h}] // Print;
Simplify[Integrate[y, {x, y} \[Element] r], {0 < b < h}] // Print;


Try it online!

• Interesting. It plots correctly in Graphics. Thanks. Jul 18 '19 at 21:41