Solution:
Key idea: We write 1+sin2x as a perfect square, (cosx+sinx)2. The numerator is then the derivative of cosx+sinx, and the substitution t=cosx+sinx gives ∫t2dt.
Step 1 — Write the denominator as a square.
We replace 1 by sin2x+cos2x and sin2x by 2sinxcosx.
1+sin2x=sin2x+cos2x+2sinxcosx
sin2x+cos2x+2sinxcosx=(cosx+sinx)2
Step 2 — Substitute.
We put the expression inside the square equal to t.
t=cosx+sinx
Differentiating both sides gives the new differential, which is the numerator times dx.
dt=(cosx−sinx)dx
Step 3 — Integrate in terms of t.
The integral becomes ∫t−2dt, and the power rule gives −1t−1.
∫1+sin2xcosx−sinxdx=∫t2dt
∫t2dt=−t1+C
Step 4 — Return to x.
We put back t=cosx+sinx.
−t1+C=−cosx+sinx1+C
Therefore, ∫1+sin2xcosx−sinxdx=−cosx+sinx1+C.