# Understanding unit vectors

Trying to understand how the unit vector ${\mathcal{\hat{r}}}$ defined as $\frac{r' - r}{|r' - r|}$ (where $r'$ is the source point) works in this problem:

Work out the electric field, $E$, at point $P$ at height $z$ above a line of length $2L$ and charge $\lambda$ along the x-axis in the $x$-$z$ plane.

So I work it out to be: $$\frac{2}{4\pi \epsilon_0}\int_0^{L} \frac{\lambda dx}{\mathcal{|r' - r|^2}} \hat{r}$$

But the books tells me that there it is actually:$$\frac{2}{4\pi \epsilon_0}\int_0^{L} \frac{\lambda dx}{\mathcal{|r' - r|^2}} cos(\theta) \hat{z}$$

how is $\hat{r} = \cos(\theta) \hat{z}$? Can someone explain how the unit $z$ vector got in there?

-
Are you computing the electric field only along the z axis i.e (0,0,z)? Is the charged line positioned along x axis? That is what the solution you posted implies –  Gotaquestion Sep 22 '13 at 17:47
Yes that is what I mean. –  Lucidnonsense Sep 22 '13 at 17:51
The x-components will cancel, so only the z component remains: this is where the $cos\theta$ comes from: $\vec{E}=E\sin\theta \hat{x} +E\cos\theta\hat{z}$ –  Danu Sep 22 '13 at 18:06
Ok, I understand now, thanks! –  Lucidnonsense Sep 22 '13 at 18:28