# Confusion with treatment of unit vectors in electrostatics

I am reading Griffiths’ Introduction to Electodynamics and there are two problems where the methodology for treating unit vectors in integrals seems inconsistent to me.

When we are trying to find the electric field $$\mathbf{E}$$ at some point $$P$$ around a static line charge with a uniform charge per unit length of $$\lambda$$, we need to use Coulomb’s law, which in this case is $$\mathbf{E}(\mathbf{r}) = \frac{1}{4\epsilon_0\pi}\int \frac{\lambda}{r^2}\mathbf{\hat{r}}dl$$, where $$\mathbf{\hat{r}}$$ is the unit vector in the direction of the separation vector from a point on the line charge to $$P.$$ It is this unit vector that is giving me trouble. Because in one situation, where $$P$$ lies above the midpoint of the line charge, we include the unit vector in the integrand:

But in another situation, where $$P$$ lies above an endpoint of the line charge, we do not include unit vectors in the integrand:

Why is this? It seems like it might have something to do with how we only need to work with one component of $$\mathbf{E}$$ to find it in the first situation, but when we have two components the situation is different, and we can just add in the unit vectors later. But I can’t figure out why this is.

In problem 2.3 you're evaluating $$z$$ and $$x$$-components of the electric field independently, while in example 2.2 you're evaluating the whole field.

Thus, in problem 2.3 you're including not the whole unit vector $$\mathbf{\hat{n}} = \cos \theta \mathbf{\hat{z}} - \sin \theta \mathbf{\hat{x}}$$ but its $$z$$ and $$x$$-components, namely $$\cos \theta$$ and $$-\sin \theta$$.

Why is this?

There isn't some profound reason here that dictates to do it one way or the other. The choice is really yours, and made out of convenience or preference.

I think you'd benefit from a refresher on vectors, so here goes. Any vector can be written as

$$\mathbf{v} = v_x\mathbf{\hat{x}} + v_y\mathbf{\hat{y}} + v_z\mathbf{\hat{z}}$$

where $$v_x$$, $$v_y$$ and $$v_z$$ (the scalar components) are just real numbers; $$\mathbf{\hat{x}}$$, $$\mathbf{\hat y}$$ and $$\mathbf{\hat{z}}$$ are the corresponding basis vectors - these have length 1, are axis-aligned, and are variously denoted $$\{\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}\}$$, $$\{\mathbf{\hat{I}}, \mathbf{\hat{J}}, \mathbf{\hat{K}}\}$$, $$\{\mathbf{\hat{i}}, \mathbf{\hat{j}}, \mathbf{\hat{k}}\}$$, $$\{\mathbf{e_1}, \mathbf{e_2}, \mathbf{e_3}\}$$, etc. You can think of $$v_x\mathbf{\hat{x}}$$, $$v_y\mathbf{\hat y}$$ and $$v_z\mathbf{\hat{z}}$$ as of (axis aligned) vector components of $$\mathbf v$$, which are just separately scaled versions of the basis vectors (each by the corresponding scalar component of $$\mathbf v$$).

Denoting the length of $$\mathbf{v}$$ by $$v = \sqrt{v_x^2 + v_y^2 + v_z^2}$$, you can also write that vector as

$$\mathbf{v} = v\mathbf{\hat{v}}$$

where $$\mathbf{\hat{v}}$$ is a unit vector in the same direction. The right-hand side is just a resizing of a unit-length vector to the length $$v$$.
This unit vector $$\mathbf{\hat{v}}$$ will have components proportional to the original components; namely, it's the vector:

$$\mathbf{\hat{v}} = \frac{v_x}{v}\mathbf{\hat{x}} + \frac{v_y}{v}\mathbf{\hat{y}} + \frac{v_z}{v}\mathbf{\hat{z}}$$

(x-component: $$v_x/v,\$$ y-component: $$v_y/v,\$$ z-component: $$v_z/v$$; the squares of these sum up to 1).

For a vector that lies within the x-z plane, these are just going to be

$$\mathbf{v} = v_x\mathbf{\hat{x}} + v_z\mathbf{\hat{z}}$$

and

$$\mathbf{\hat{v}} = \frac{v_x}{v}\mathbf{\hat{x}} + \frac{v_z}{v}\mathbf{\hat{z}}$$

"seems like it might have something to do with how we only need to work with one component of E to find it in the first situation"

You're not working with a single component there. The book uses a curly r that I cannot reproduce here, so I'll use $$\mathbf{\rho}$$ instead. The $$\mathbf{\hat\rho}$$ vector has two components

$$\mathbf{\hat\rho}= \frac{\rho_x}{\rho}\mathbf{\hat{x}} + \frac{\rho_z}{\rho}\mathbf{\hat{z}}$$

where $$\rho_x = -x$$, and $$\rho_z = z\$$ (in terms of the labels in the diagram).

So you're really taking both of them into account simultaneously. The $$\mathbf{\hat{\rho}}$$ unit vector is actually changing direction as you move along the x-axis, from -L to L (as it keeps pointing at $$P$$) - the components are each a function of position $$x$$, and are both changing. But you can integrate the vector components separately (split the integral) due to linearity - i.e. because it's just addition. And as the basis vectors $$\mathbf{\hat{x}}$$ and $$\mathbf{\hat{z}}$$ are constant, you can pull them out of the integral.

But that also means that you can work with the scalar components on their own, and add the appropriate basis vectors back in when you're done (as long as you keep track of which component is which). Here, due to the symmetry of the setup in the Example 2.2, it turns out that the x-component of $$\mathbf{E}$$ is zero.

You can either choose to work with the vector itself, or temporarily ignore the vector nature of integrand, and work with the individual scalar components separately, adding the basis vectors back in at the end to reconstruct the vector quantity.

In other words, you can use both approaches on both problems.