Elliptic integrals using complex analysis I wonder if there is any way using complex analysis to solve the following integral
$$\int_0^{2\pi}\sqrt{1+\cos^2\theta}d\theta$$
My first question is:

is it correct to substitute $z=e^{i\theta}$ to obtain$$\oint_{|z|=1}{1\over iz}\sqrt{1+{1\over 4}(z+z^{-1})^2}dz$$

In case of affirmative answer to the first one, my second question is:

How can we find the singularities of the integrand of the first question and find the residues in them to solve the elliptic integral?

My last question:

What can be said about$$\int_0^{2\pi}\sqrt{1+\sum_{n=1}^{\infty}a_n\cos n\theta}d\theta$$when $\{a_n\}$ are proper real values such that the integrand is defined over $\Bbb R$?

 A: With $z= e^{i \theta}, dz= ie^{i \theta}d\theta, d\theta= i dz/z$  you get
$$\int_0^{2\pi}\sqrt{1+\cos^2\theta}d\theta= \int_{|z|} \sqrt{1+\frac14(z+z^{-1})^2}\frac{idz}{z}$$
Where by definition $\int_{|z|=1} f(z)dz=  \int_0^{2\pi} f(e^{it}) i e^{it}dt$
We need to be careful with the branch of $\sqrt{.}$, with the one making the integrand continuous on $|z|=1$, we have to locate the zeros/poles of $1+\frac14(z+z^{-1})^2$ to find if the integrand is analytic on $|z|=1$ or not.
For the poles there is only one at $0$ of order $2$ thus $\sqrt{1+\frac14(z+z^{-1})^2}$ is meromorphic at $0$. For the zeros 
$$(z+z^{-1})^2 +4=0, z+z^{-1} = \pm 2i, z^2\pm 2i z+1= 0, z = \frac{\pm 2i\pm \sqrt{(2i)^2-4}}{2}=\pm i \pm i\sqrt{2}$$
Thus there are two simple zeros inside the unit disk at $\pm i(\sqrt{2}-1)$. This is a major problem which means the integrand is analytic on $\sqrt{2}-1<|z|\le 1$ but not on $|z|= \sqrt{2}-1$ and
$$\int_{|z|=1} \sqrt{1+\frac14(z+z^{-1})^2}\frac{idz}{z}=\lim_{r \to \sqrt{2}-1}\int_{|z|=r} \sqrt{1+\frac14(z+z^{-1})^2}\frac{idz}{z}$$
$$\ne\lim_{r \to 0}\int_{|z|=r} \sqrt{1+\frac14(z+z^{-1})^2}\frac{idz}{z}= 2i\pi Res(\sqrt{1+\frac14(z+z^{-1})^2}\frac{i}{z},z=0)$$

So your integral cannot be solved using the residue theorem

