Electric field generated by a uniformly charged infinite line The topic in the subject line is a classical application of Gauss's theorem for the electric field.
The theorem itself states that, given a set of charges $q_i$ all located inside a closed surface, the flux of the electric field through the surface equals $\frac{\sum_i{q_i}}{\epsilon}$.
From that, we can construct a cylindrical surface around a section of the line so that we can equal Gauss's result with what we know to be the flux in that case:
$$
\frac{\sum_i{q_i}}{\epsilon} = E \cdot 2 \pi r l
$$
Where $r$ is the distance from the line (i.e. the radius of the cylindrical surface) and $l$ is the length of the section. When we introduce the linear charge density $\lambda$ we get:
$$
\lambda = \frac{\sum_i{q_i}}{l}
$$
$$
\frac{\lambda}{\epsilon} = E \cdot 2 \pi r
$$
$$
E = \frac{1}{2 \pi \epsilon} \cdot \frac{\lambda}{r}
$$
Now I'm trying to get the same result with a completely different process.
If we agree the following definition of Riemann's integral:
$$
\int_a^b{f \left( t \right) dt} = \lim_{n \rightarrow + \infty}{\sum_{i = 0}^n{h \cdot f \left( ih \right)}}
$$
where $h = \frac{b - a}{n}$, then we can compute the electric field through an approximation process.
To begin with, we take a finite line of length $l$, lay it on the X-coordinate axis, and divide it in $n$ parts of equal length $h = l / n$. Each part contains exactly one point charge $q_i$ located at the X coordinate $i \cdot h$.
If we measure the electric field at the (X,Y) coordinates $(0,r)$ we have:
$$
E_i = \frac{1}{2 \pi \epsilon} \cdot \frac{q_i}{r^2 + i^2 h^2}
$$
$$
E = \sum_i{E_i} = \frac{1}{2 \pi \epsilon} \cdot \sum_i{\frac{q_i}{r^2 + i^2 h^2}}
$$
Introducing $\lambda$:
$$
\lambda = \frac{q_i}{h}
$$
$$
q_i = \lambda \cdot h
$$
$$
E = \frac{\lambda}{2 \pi \epsilon} \cdot \sum_i{h \cdot \frac{1}{r^2 + i^2 h^2}}
$$
When the number $n$ of parts diverges and $h$ tends to $0$ the point charges get closer to each other and become a charged line of length $l$, and we can turn this sum into a Riemann integral:
$$
E = \frac{\lambda}{2 \pi \epsilon} \cdot \int_0^l{\frac{1}{r^2 + x^2}}{dx}
$$
To anti-derive that integral we can exploit $arctan$ as follows:
$$
\frac{d}{dx} \arctan{x} = \frac{1}{1 + x^2}
$$
$$
\frac{d}{dx} \frac{\arctan{\frac{x}{r}}}{r} = \frac{1}{r^2 + x^2}
$$
Thus:
$$
E = \frac{\lambda}{2 \pi \epsilon} \cdot \frac{\arctan{\frac{l}{r}} - 0}{r}
$$
The original goal is to find the electric field generated by an infinite line that extends in both directions, while this is the electric field of a finite segment that spans $[0, l]$; so we'll have to compute the above when $l$ diverges to positive infinity and multiply the result by $2$:
$$
E_{TOT} = 2 \cdot \lim_{l \rightarrow + \infty} \frac{\lambda}{2 \pi \epsilon} \cdot \frac{\arctan{\frac{l}{r}}}{r} = 2 \cdot \frac{\lambda}{2 \pi \epsilon} \cdot \frac{\pi}{2 r} = \frac{\lambda}{2 \epsilon r}
$$
This result differs from applying Gauss's theorem by a $\pi$ in the denominator. Where did I lose the missing $\pi$?
Thanks in advance!
 A: 
$$ E_i = \frac{1}{2 \pi \epsilon} \cdot \frac{q_i}{r^2 + i^2 h^2} $$

This is where the problem lies. Firstly, it should be $1/(4\pi)$, to account for the surface area of the sphere (it behaves like a point charge from a distance, even if it is an infinitesimal line segment!). The next problem is that the force is not all pointed towards the origin: it points at $(0,ih)$. It's clear that we only want the horizontal component of the force since the vertical components must eventually cancel out by symmetry. This gives
$$ \frac{1}{4\pi \epsilon} \frac{r}{\sqrt{r^2+i^2h^2}} \frac{q_i}{r^2+i^2h^2} $$
by considering the right-angled triangle. So as an integral, this becomes
$$ \frac{\lambda r}{4\pi \epsilon} \int_{-\ell}^{\ell} \frac{dy}{(r^2+y^2)^{3/2}} \to \frac{\lambda r}{4\pi \epsilon} \int_{-\infty}^{\infty} \frac{dy}{(r^2+y^2)^{3/2}}. $$
Putting $y=r\tan{\theta}$ gives $dy=r\sec^2{\theta}\, d\theta$, the limits become $\pm \pi/2$, and so
$$ E=\frac{\lambda r}{4\pi \epsilon} \int_{-\infty}^{\infty} \frac{dy}{(r^2+y^2)^{3/2}} = \frac{\lambda r}{4\pi \epsilon} \int_{-\pi/2}^{\pi/2} \frac{r\sec^2{\theta} \, d\theta}{r^3\sec^{3}{\theta}} = \frac{\lambda}{4\pi\epsilon r} \int_{-\pi/2}^{\pi/2} \cos{\theta} \, d\theta = \frac{\lambda}{2\pi\epsilon r}, $$
as it should be.
A: Assume that the line charge extends from $z=-\ell/2$ to $z=\ell/2$.  We partition the $z$-axis into $n$ subintervals each of length $h=\ell/n$.   The incremental charge in a subinterval is $\Delta q=\lambda h$.
Therefore, the incremental contribution to the electric field at $(r,0)$ from an infinitesimal charge $\lambda h$ at $(0,ih)$ is given by
$$\Delta \vec E=\frac{\lambda h}{4\pi \epsilon_0} \frac{\hat rr-\hat z(ih)}{(r^2+(ih)^2)^{3/2}}$$
whereupon exploiting symmetry and summing yields
$$\begin{align}
\vec E&=\hat r \frac{\lambda h}{2\pi \epsilon_0}\lim_{n\to \infty}\sum_{i=1}^n \frac{r}{(r^2+(ih)^2)^{3/2}}\\\\
&=\hat r \frac {\lambda r}{2\pi \epsilon_0} \int_0^{\ell/2}\frac{1}{(r^2+z^2)^{3/2}}\,dz\\\\
&=\hat r \frac{\lambda (\ell/2)}{2\pi \epsilon_0 r\sqrt{r^2+(\ell/2)^2}}
\end{align}$$
Letting $\ell \to \infty$ we find the electric field due to an infinitely long line charge is given by
$$\vec E=\frac{\lambda}{2\pi \epsilon_0}$$
as was to be shown!
