% Problem 3
clc; clear all;
r = 1;
A1 = 4*r*r/2; % Area of the rectangle with sides 2r, r/2
C1x = 2*r; C1y = 0.25*r; % Centroid of the rectangle
A2 = pi*r^2;  % Area of the circle with radius r
C2x = r; C2y=-r; % Centroid of the first circle
A3 = pi*r^2;  % Area of the circle with radius r
C3x = 3*r; C3y=-r;  % Centroid of the second circle
Cx=(A1*C1x+A2*C2x+A3*C3x)/(A1+A2+A3);
Cy=(A1*C1y+A2*C2y+A3*C3y)/(A1+A2+A3);
Centroid = [Cx,Cy]

% Centroid =  2.0000   -0.6982 (m)  (D)
Centroid =

  Column 1

   2.000000000000000

  Column 2

  -0.698183741243470