Do you think possibly it was the "i" that was already in the integral: \(\displaystyle (cos^2 \theta)(\underline{i} e^{i\theta})\)?

I don't think this is the case (though it appears likely),

\(\displaystyle \int ( cos^2 \theta ) ( i e^{ i \theta } ) d \theta \)

We need to get to the above from

\(\displaystyle i \int ( \frac{1}{2} [ e^{i \theta } + e^{-i \theta} ]^2 )( i e^{ i \theta} ) d\theta \)

Let's look at

\(\displaystyle \frac{1}{2} [ e^{i \theta } + e^{-i \theta} ]^2 \)

\(\displaystyle ( \frac{1}{2} [ e^{i \theta } + e^{-i \theta} ] )^2 = ( \frac{1}{2} [ (cos \theta + i sin \theta ) + (cos \theta - i sin \theta) ] )^2 \)

\(\displaystyle ( \frac{1}{2} ( 2 cos \theta ) )^2 = cos^2 \theta \)

Which transforms

\(\displaystyle i \int ( \frac{1}{2} [ e^{i \theta } + e^{-i \theta} ]^2 )( i e^{ i \theta} ) d\theta = i \int cos^2 \theta (i e^{i \theta} ) d \theta \)

We have an extra i here....I don't know where it came from but I'm relatively sure it didn't come from what was already in the integral.