<s>[INST] To compute $\frac{1}{2\pi i}\int_\mathcal{C} |1+z+z^2|^2 dz$ where $\mathcal{C}$ is the unit circle in $\mathbb{C}$ 
Let $\mathcal{C}$ denote the unit circle in $\mathbb{C}$ centred at the origin taken anticlockwise. Compute the value of the integrtal $$\frac{1}{2\pi i}\int_\mathcal{C} |1+z+z^2|^2 dz$$

I don't recon we can use the residue theorem to compute this integral because the integrand is not analytic anywhere.
I then tried substituting $z=e^{i\theta}$ and integrating it the traditional way but cant make much of the integrated $|1+e^{i\theta}+e^{2i\theta}|^2$.
Any help would be much appreciated. Thanks.
 [/INST] We want the integral
$$\frac{1}{2\pi i}\int_C |1+z+z^2|^2dz=\frac{1}{2\pi}\int_0^{2\pi}|1+z+z^2|^2z~d\theta$$
since $z=e^{i\theta}$.
Now consider the absolute value portion,
$$
\begin{align}
|1+z+z^2|^2
&={(1+z+z^2)(1+z+z^2)^*}\\
&={(1+z+z^2)(1+z^{-1}+z^{-2})}\\
&={(1+z+z^2)(1+z^{-1}+z^{-2})\frac{z^2}{z^2}}\\
&={\left(\frac{1+z+z^2}{z} \right)^2}\\
&={\left(\frac{1}{z}+1+z \right)^2}\\
&={(1+2\cos\theta)^2}\\
\end{align}
$$
We can return to solve the integral
$$
\begin{align}\frac{1}{2\pi i}\int_C |1+z+z^2|^2dz
&=\frac{1}{2\pi}\int_0^{2\pi}(1+2\cos\theta)^2(\cos\theta+i\sin\theta)~d\theta\\
&=\frac{1}{2\pi}\int_0^{2\pi}(1+2\cos\theta)^2\cos\theta~d\theta\\
&=2
\end{align}$$
This is in agreement with our own numerical solution.
</s>