Indefinite Integration

Evaluate $\displaystyle \int 3^x \; \sin^2 x \; dx$


$\begin{aligned} \text{Let } I & = \int 3^x \; \sin^2 x \; dx \\\\ & = \int 3^x \left[\dfrac{1 - \cos \left(2x\right)}{2}\right] \; dx \;\;\; \left[\text{Note: }\sin^2 \theta = \dfrac{1 - \cos \left(2 \theta\right)}{2} \right] \\\\ & = \dfrac{1}{2} \int 3^x \; dx - \dfrac{1}{2} \int 3^x \; \cos \left(2 x\right) \; dx \\\\ & = \dfrac{1}{2} I_1 - \dfrac{1}{2} I_2 \;\;\; \cdots (1) \end{aligned}$

Now, $I_1 = \displaystyle \int 3^x \; dx = \dfrac{3^x}{\log 3} + c_1$ $\;\;\; \cdots (2)$

$\begin{aligned} \text{and } I_2 & = \int 3^x \; \cos \left(2 x\right) \; dx \\\\ & \left[\begin{aligned} \text{Note: } & \int u \; v \; dx = u \int v \; dx - \int \left\{\int v \; dx \times \dfrac{d}{dx} \left(u\right) \right\} \; dx \\ & \text{Here } u = \cos \left(2x\right) \text{ and } v = 3^x \end{aligned} \right] \\\\ \therefore \; I_2 & = \cos \left(2x\right) \int 3^x \; dx - \int \left\{\int 3^x \; dx \times \dfrac{d}{dx} \left[\cos \left(2x\right)\right] \right\} \; dx \\\\ & = \dfrac{3^x \; \cos \left(2x\right)}{\log 3} + \dfrac{2}{\log 3} \int 3^x \; \sin \left(2x\right) \; dx \\\\ & = \dfrac{3^x \; \cos \left(2x\right)}{\log 3} + \dfrac{2}{\log 3} \left[\sin \left(2x\right) \int 3^x \; dx - \int \left\{\int 3^x \; dx \times \dfrac{d}{dx} \left[\sin \left(2x\right)\right] \right\} \; dx\right] \\\\ & \left[\text{Note: Here } u = \sin \left(2 x\right) \text{ and } v = 3^x\right] \\\\ i.e. \; I_2 & = \dfrac{3^x \; \cos \left(2x\right)}{\log 3} + \dfrac{2}{\log 3} \left[\dfrac{3^x \; \sin \left(2 x\right)}{\log 3} - \dfrac{2}{\log 3} \int 3^x \; \cos \left(2 x\right) \; dx\right] + c'_2 \\\\ & = \dfrac{3^x \; \cos \left(2x\right)}{\log 3} + \dfrac{2}{\left(\log 3\right)^2} \times 3^x \; \sin \left(2 x\right) - \dfrac{4}{\left(\log 3\right)^2} \int 3^x \; \cos \left(2 x\right) \; dx + c'_2 \\\\ & = \dfrac{3^x \; \cos \left(2x\right)}{\log 3} + \dfrac{2}{\left(\log 3\right)^2} \times 3^x \; \sin \left(2 x\right) - \dfrac{4}{\left(\log 3\right)^2} I_2 + c'_2 \end{aligned}$

$\begin{aligned} i.e. \; \left[1 + \dfrac{4}{\left(\log 3\right)^2}\right] \; I_2 & = \dfrac{3^x \; \cos \left(2x\right)}{\log 3} + \dfrac{2}{\left(\log 3\right)^2} \times 3^x \; \sin \left(2 x\right) + c'_2 \\\\ i.e. \; \left[\dfrac{\left(\log 3\right)^2 + 4}{\left(\log 3\right)^2}\right] \; I_2 & = \dfrac{3^x \; \cos \left(2x\right)}{\log 3} + \dfrac{2}{\left(\log 3\right)^2} \times 3^x \; \sin \left(2 x\right) + c'_2 \end{aligned}$

$\begin{aligned} i.e. \; I_2 & = \dfrac{\left(\log 3\right) \times 3^x \times \cos \left(2 x\right)}{\left(\log 3\right)^2 + 4} + \dfrac{2 \times 3^x \times \sin \left(2 x\right)}{\left(\log 3\right)^2 + 4} + c_2 \;\;\;\; \cdots (3) \end{aligned}$

where $c_2 = \left[\dfrac{\left(\log 3\right)^2}{\left(\log 3\right)^2 + 4}\right] \times c'_2$

Substituting equations $(2)$ and $(3)$ in equation $(1)$ gives

$I = \dfrac{3^x}{2 \; \log 3} - \dfrac{3^x}{2 \left[\left(\log 3\right)^2 + 4\right]} \left[\left(\log 3\right) \cos \left(2 x\right) + 2 \sin \left(2 x\right)\right] + c$

where $c = \dfrac{c_1}{2} - \dfrac{c_2}{2}$