Answer
a)$x_{cm}=\frac{L}{2}$
b)$x_{cm}=\frac{2L}{3}$
Work Step by Step
a) The volume of the rod, V = AL, where A is cross-sectional area and L the length
Mass is given as density $\times$ volume, $M=\rho AL$
Also, M=$\int dm$
$x_{cm}=\frac{1}{M} \int x dm$ from 0 to L
$x_{cm} = \frac{\rho A}{M}\int xdx = \frac{\rho A L^{2}}{2M}$
Sub in $M=\rho AL$, we get
$x_{cm} = \frac{\rho A L^{2}}{2\rho A L} = \frac{L}{2}$ as shown
b) Now $\rho = \alpha x$, density is a function of length
$x_{cm}=\frac{1}{M} \int x dm$ from 0 to L
$x_{cm}=\frac{A\alpha}{M} \int x^{2} dx = \frac{A\alpha L^{3}}{3M} $
Sub $M =\int dm = \alpha A \int dx = \frac{\alpha A L^{2}}{2}$
$x_{cm}= \frac{A\alpha L^{3}}{3M} = \frac{A\alpha L^{3}}{3\frac{\alpha A L^{2}}{2}} = \frac{2L}{3}$