Solution:
Key idea: For a product of a polynomial and cosx, use integration by parts, ∫udv=uv−∫vdu, with the polynomial as u. Each application lowers the power of x by one, so x2 needs two applications.
Step 1 — First integration by parts.
We take u=x2 and dv=cosxdx, so du=2xdx, and v=sinx.
I=x2sinx−∫2xsinxdx
Step 2 — Second integration by parts.
For ∫2xsinxdx, we take u=2x and dv=sinxdx, so du=2dx, and v=−cosx.
∫2xsinxdx=−2xcosx+∫2cosxdx
∫2xsinxdx=−2xcosx+2sinx
Step 3 — Substitute back.
We put this result into Step 1, taking care with the minus sign in front of the integral.
I=x2sinx−(−2xcosx+2sinx)+C
I=x2sinx+2xcosx−2sinx+C
Step 4 — Check by differentiating.
Differentiating gives 2xsinx+x2cosx+2cosx−2xsinx−2cosx. Every term cancels except x2cosx, the integrand.
Therefore, ∫x2cosxdx=x2sinx+2xcosx−2sinx+C.