I was evaluating the elementary integral: $$\int_0^{2\pi} \sec^2\frac{x}{2}dx$$ Evaluating the expression and substituting limits, we get, $$2\bigg[\tan\frac{x}{2}\bigg]_0^{2\pi}=2\bigg[\tan \frac{2\pi}{2}-\tan\frac{0}{2}\bigg]=2\bigg[0-0\bigg]=0$$ This seems like a valid solution, except, when I run it on Wolfram or Integral Calculator, it says the integral is divergent.
Where am I going wrong? How is the integral divergent?
Note that $\sec$ is not defined at $\pi$. So, your integral is really the sum of several improper integrals, the first one of which is$$\lim_{u\to\pi^-}\int_0^u\sec^2\left(\frac x2\right)\,\mathrm dx.$$This integral diverges.