Integration Issue with Finding a Centroid I've been brushing up on my understanding of centroids in 2-dimensions, and I  chose to try to find $M_x$ of the region bounded by $$f(x) = \sin(x-\frac{\pi}{2})+3$$ and the x-axis, $g(x)=0$, from $x=\frac{\pi}{2}$ to $x=\frac{7\pi}{2}$.
This gives:
$$M_x=\int_\frac{\pi}{2}^\frac{7\pi}{2}((\frac 12)(\sin(x- \frac{\pi}{2})+3))(\sin(x- \frac{\pi}{2})+3)dx$$
$$=\frac12\int_\frac \pi2^\frac{7\pi}{2}(\sin(x- \frac{\pi}{2})+3)(\sin(x- \frac{\pi}{2})+3)dx$$
$$=\frac12\int_\frac \pi2^\frac{7\pi}{2}(\sin(x- \frac{\pi}{2})+3)^2dx$$
$$=\frac12\int_\frac \pi2^\frac{7\pi}{2}  (\sin^2(x- \frac{\pi}{2})  +6\sin (x- \frac{\pi}{2}) + 9)  \  dx$$
$$=\frac12 \left[
  {\sin^3(x- \frac{\pi}{2})\over 3\cos(x- \frac{\pi}{2})}
  + 6(-\cos (x- \frac{\pi}{2}) )
  + 9x
  \right]_ \frac{\pi}{2} ^ \frac{7\pi}{2}
  $$
$$=\frac12 \left[  \left( 
  0
  + 6
  + \frac{63\pi}{2}
  \right)
-  \left( 
  0
  - 6
  + \frac{9\pi}{2}
  \right)
  \right]
  $$
$$
  =\frac12 (12 + \frac{54\pi}{2})
  $$
$$
  =6 + \frac{27\pi}{2}
  $$
$$ \approx 48.4115$$
For the exact same integral Desmos gives: $M_x=50.7676953137$,
and Wolfram gives: $M_x  \approx 50.768 $.
I can't tell what I'm doing wrong. Would someone be able to point it out for me?
 A: The integral $$M_x = \frac{1}{2} \int_{x=\pi/2}^{7\pi/2} \left(\sin \left(x - \frac{\pi}{2}\right) + 3 \right)^2 \, dx$$ is more easily evaluated by first performing the substitution $u = x - \pi/2$, $du = dx$ to obtain
$$\begin{align}
M_x &= \frac{1}{2} \int_{u=0}^{3\pi} \sin^2 u + 6 \sin u + 9 \, du \\
&= \frac{1}{4} \int_{u=0}^{3\pi} 1 - \cos 2u + 12 \sin u + 18 \, du \\&= \frac{1}{4} \left[ -\frac{1}{2} \sin 2u - 12 \cos u + 19u \right]_{u=0}^{3\pi} \\
&= \frac{1}{4} \left( -0 + 12 + 19(3\pi) + 0 + 12 - 19(0)\right) \\
&= 6 + \frac{57\pi}{4}.
\end{align}$$

As to why your calculation is incorrect, it appears that you are asserting $$\int \sin^2 x \, dx = \frac{\sin^3 x}{3 \cos x} + C.$$  This is not at all correct, as differentiation of the RHS will show that $$\frac{d}{dx}\left[\frac{\sin^3 x}{3 \cos x}\right] = \frac{2 \sin^2 x + \tan^2 x}{3} \ne \sin^2 x.$$  I'm not sure how you arrived at such a claim; perhaps you thought more generally
$$\int (f(x))^2 \, dx = \frac{(f(x))^3}{3 \int f(x) \, dx}$$ in some kind of "reverse chain rule" sense?  This is not a valid identity.  To integrate $\sin^2 x$, you should employ the trigonometric identity $$\sin^2 x = \frac{1- \cos 2x}{2}.$$
