Solving this path integral "the hard way" First let me say I have already read this thread concerning the exact same problem I'm talking about. Nevertheless, my question is different, fully mathematical.
We want to get the electric field $\textbf{E}$ at a height $z$ over a uniformly charged line $\lambda$ of length $2L$. We know that, for a position vector $\textbf{p}$, the displacement vector $\textbf{r}$ and the Coulomb's constant $k_c$ we face the path integral
$$ \textbf{E}(\textbf{p}) = k_c \lambda \int_\Gamma\frac{\hat{\textbf{r}}}{r^2}\cdot d\textbf{l}$$
We realize that the non-vertical components of the vectors $\textbf{r}$ will cancel out, but that the vertical component will conspire, so we can solve this problem studying only the vertical component of $\textbf{E}$, $E_z$. 
Nevertheless, I wonder how would we solve the problem without anticipating this mutual cancellation of the $\textbf{r}$ vectors. Particularly I think that we should have
$$d\textbf{l} = dx \hat{\textbf{x}} \Rightarrow \frac{\hat{\textbf{r}}}{r^2}\cdot d\textbf{l} = \frac{x}{(x^2+z^2)^{\frac{3}{2}}}dx$$
But this would lead to
$$k_c\lambda\int_{-L}^{L}\frac{x}{(x^2+z^2)^{\frac{3}{2}}}dx = 0$$
which is a definitely incorrect result. So, I have two questions:


*

*What is wrong with my reasoning? Have I correctly translated $d\textbf{l}$ to Cartesian differentials?

*How would this problem be solved without anticipating, simply by solving the path integral. Specifically I'm interested in seeing a correct parametrization. 


Thank you in advance.
 A: The basic form of the integral is, 
$$\vec{E}(p) = \int \frac{k \hat{r} dq}{r^2}$$
Where $dq$ is an increment of charge in the distribution, $\vec{r}$ is a displacement vector which points from the charge element $dq$ to the point $p$, and $k$ is a constant. To perform this integration we need expressions for the following. 


*

*A parameterization of the charge distribution which describes the locations of all the elements of charge. 

*$dq$ in terms of the differentials of the parameter variables used for part (1). 

*$\hat{r}$ as a function of the location of $dq$ and the point $p$. 

*$r$ as a function of the location of $dq$ and the point $p$. 


In this particular problem our charges are distributed along a line of length $2L$ with a linear charge density $\lambda$. To perform the integral it would be helpful to specify some coordinates. Without loss of generality place the charged line on the $x$-axis in the interval $[-L,L]$. 
Our increment of length is $dl = \sqrt{dx^2+dy^2+dz^2}$. To make sense of this we need to parameterize the line. I will choose the parameterization $(s,0,0)$ where $s$ ranges from $-L$ to $L$. Then $dl = ds$ because, 
$$ dl = \left[ \sqrt{ (dx/ds)^2 + (dy/ds)^2 + (dz/ds)^2} \right]  ds.$$
We use $\lambda = dq/dl$ to get $\boxed{dq = \lambda ds}$. 
The displacement vector from the point $(s,0,0)$ to the point $p=(p_x,p_y,p_z)$ is given by subtracting the coordinates for these points, 
$$ \vec{r} = (p_x-s,p_y,p_z),$$
from this we get $r=\|\vec{r}\|$, 
$$r = \sqrt{(p_x-s)^2 + p_y^2 + p_z^2},$$
and we can now compute $\hat{r} = \vec{r} / r $, 
$$ \hat{r} = \frac{(p_x-s,p_y,p_z)}{\sqrt{(p_x-s)^2 + p_y^2 + p_z^2}},$$
the electric field at the point $p$ is given by, 
$$ \vec{E}(p) = \int_{-L}^L k \frac{(p_x-s,p_y,p_z)}{\left[ (p_x-s)^2 + p_y^2 + p_z^2 \right]^{3/2} } \lambda ds $$
We want to evaluate this at the particular point $p=(0,0,z)$ which is at a height $z$ above the midpoint of the line. 
$$ \vec{E}(p) = \int_{-L}^L k \frac{(-s,0,z)}{\left[ s^2 + z^2 \right]^{3/2} } \lambda ds $$
This involves two integrals, one for $E_x$ and the other for $E_z$. $E_y$ is clearly $0$. 

First lets evaluate the integral for $E_x$. Clearly this is $0$ because it is the integration of an odd function over a symmetric interval. However we want to be "less clever" and solve it without exploiting that particular symmetry. 
$$ E_x = \int_{-L}^L k \frac{-s}{\left[ s^2 + z^2 \right]^{3/2} } \lambda ds $$
Note the following, 
$$ \frac{d}{ds} \left[ s^2 + z^2 \right]^{-1/2} = 2s \left[ s^2 + z^2 \right]^{-3/2}$$
which means our integrand can be rewritten as,  
$$ E_x = -\frac12 \int_{-L}^L k \frac{d}{ds} \left[ \frac{1}{\left[ s^2 + z^2 \right]^{1/2} } \right] \lambda ds $$
$$ = -\frac{k\lambda}{2} \int_{-L}^L  \frac{d}{ds} \left[ \frac{1}{\left[ s^2 + z^2 \right]^{1/2} } \right]  ds $$
$$ = -\frac{k\lambda}{2}  \left[ \frac{1}{\left[ s^2 + z^2 \right]^{1/2} } \right]_{-L}^L   $$
$$ = -\frac{k\lambda}{2}  \left[ \frac{1}{\left[ L^2 + z^2 \right]^{1/2} } - \frac{1}{\left[ L^2 + z^2 \right]^{1/2} } \right]   $$
$$ = 0 $$
Thus $E_x=0$. 

Now consider $E_z$. 
$$ E_z = \int_{-L}^L k \frac{z}{\left[ s^2 + z^2 \right]^{3/2} } \lambda ds $$
To solve this let $s=z\tan(\theta)$. Then we have $ds = z \sec^2(\theta) d\theta$. 
$$ E_z = \int_{-\tan^{-1}(L/z)}^{\tan^{-1}(L/z)} k \frac{z}{\left[ z^2\tan^2(\theta) + z^2 \right]^{3/2} } \lambda \sec^2(\theta)d\theta $$
$$= k z \lambda  \int_{-\tan^{-1}(L/z)}^{\tan^{-1}(L/z)}  \frac{1}{\left[ z^2 \sec^2(\theta) \right]^{3/2} }  \sec^2(\theta)d\theta $$
$$=\frac{ k z \lambda}{z^3}  \int_{-\tan^{-1}(L/z)}^{\tan^{-1}(L/z)}  \frac{\sec^2(\theta)}{  \sec^3(\theta) } d\theta $$
$$=\frac{ k \lambda}{z^2}  \int_{-\tan^{-1}(L/z)}^{\tan^{-1}(L/z)}  \frac{1}{  \sec(\theta) } d\theta $$
$$=\frac{ k \lambda}{z^2}  \int_{-\tan^{-1}(L/z)}^{\tan^{-1}(L/z)}  \cos(\theta) d\theta $$
$$=\frac{ k \lambda}{z^2}  \left[ \sin(\theta) \right]_{-\tan^{-1}(L/z)}^{\tan^{-1}(L/z)} $$
$$=\frac{ 2k \lambda}{z^2}  \sin\left(\tan^{-1}(L/z) \right)$$
$$ =\frac{ 2k \lambda}{z^2}  \frac{L}{\sqrt{L^2+z^2}} $$
$$ E_z = \frac{ 2k \lambda}{z^2}  \frac{L}{\sqrt{L^2+z^2}} $$
