Why can't we use Gauss' law on a rod of length $2L$? Suppose we have a rod of length $2L$, and we want to compute the electric field in at P, which is on the perpendicular bisector of the rod, as shown below:

Why isn't Gauss' law applicable here? My professor stated that this is because there is electric field at the rod's ends, and also brought up a an example of a infinite length rod, with a cylinder placed around it and said that Gauss' law was applicable there because we didn't have any electric field parallel to our surface. However none of these examples helped me. Can anyone elaborate on them, or give me another example?
 A: Gauss's law can only be used to find the electric field of a charge configuration when the configuration exhibits some symmetry that allows you to break up the integral $\oint_S \mathbf{E}\cdot\text{d}\mathbf{S}$ into a product (or a sum of products). This fact is often not stressed strongly enough in introductory courses in Electromagnetism. If you think about it, the statement $$\oint_S \mathbf{E}\cdot\text{d}\mathbf{S} = \frac{Q_\text{enc}}{\epsilon_0}$$ is not in itself useful to calculate the electric field, since there is no way to "invert" the left hand side!
The standard technique is to find a Gaussian surface over which the electric field should be constant because of the symmetries of the problem. Then, one does not have to explicitly work out the integral with $\mathbf{E}$ inside it, but simply has to integrate over the area. To see this, let's actually consider what we do when we apply Gauss's law to an infinite wire. In this case, since the wire is infinite along the (say) $z-$axis, the electric field cannot depend on $z$ (since all points in the $z$ direction are equivalent). A simple way to understand this is to imagine that you look away for a while, and somebody comes by and shifts the entire wire "upwards" by some amount. Since the wire is infinite, when you come back, there would be no way for you to tell that it had been shifted!
Similarly, all points at a given distance $r$ from the wire are equivalent, since the wire also has a symmetry in the $\varphi$ direction. (Imagine you look away again, and somebody comes by and rotates the wire about the $z$ axis by some angle $\varphi_0$. When you return, you would still not be able to tell that the wire had been rotated!)
As a result, the electric field can only depend on the $r$ coordinate and direction. So we assume an electric field of the form $$\mathbf{E} = E(r)\hat{\mathbf{r}}$$ purely on grounds of symmetry. Since all points at a distance $r$ are equivalent, a good guess for the Gaussian surface $S$ would be a cylinder of some radius (say, $s$). Along the curved surface of this cylinder, the electric field will be a constant. Therefore, $$\oint_S\mathbf{E}\cdot\text{d}\mathbf{S} = \int_\text{curved} E(r)\, \hat{\mathbf{r}}\cdot\text{d}\mathbf{S} + \int_\text{caps}E(r)\, \hat{\mathbf{r}}\cdot\text{d}\mathbf{S}.\tag{1}\label{1}$$
Now, along the curved surface, $\text{d}\mathbf{S} = \hat{\mathbf{r}}\,s\,\text{d}\theta$, and along the flat caps $\text{d}\mathbf{S} = \hat{\mathbf{z}}\,\text{d}z$. As a result, you should easily be able to show that for a Gaussian cylinder of some radius $s$ and length $\ell$, $$\oint\mathbf{E}\cdot\text{d}\mathbf{S} = 2\pi s E(s)\times \ell = \frac{Q_\text{enc}}{\epsilon_0},$$ from which you can find the form of $E(s)$ and therefore you can infer $\mathbf{E}$.
Now notice that the fact that the wire was infinite helped us in a couple of ways:

*

*Since the wire was infinite in the $z$ direction, we could assume that $\mathbf{E} = E(r) \hat{\mathbf{r}}$. If this were no longer true, the field could depend both on the radial distance $r$ as well as the $z$ coordinate (as indeed it does for a finite wire). As a result, the electric field would not be constant on the cylinder, and you would need to find a new surface over which the field has to be constant, which is a non-trivial task if you don't know $\mathbf{E}$ in the first place!


*Since the field only depends on the radial coordinate, and must be oriented along $\hat{\mathbf{r}}$, the second term in Equation (\ref{1}) is trivially zero, since $\mathbf{E}\cdot \text{d}\mathbf{z}=0$. However, if the field could point in the $z$ direction, this would no longer be the case, and you would have to explicitly calculate this integral, which again is not obvious unless you already know the form of $\mathbf{E}$!
As a result, the finite wire does not possess enough symmetries for you to compute the field purely using Gauss's law. That being said, if you knew the field and didn't mind some heavy duty integral, you could always plug it into the integral and show that it is equal to the enclosed charged over $\epsilon_0$, since Gauss's law would still hold.
A: in the first look, I thought there may be a chance to use Gauss's theorem for there is a region near the point P, the electric field is in the $z$ direction. What if we make Gaussian surface, the tin-can so shallow, as shown in the following figure:

Applying Gauss's theorem to this surface
$$ \tag{1}
   2\pi r \Delta x E(r) = \frac{\lambda \Delta x}{\epsilon_o};\\
E(r) = \frac{\lambda}{2\pi \epsilon_o r}
$$
Where $\lambda$ is the linear charge density.
Now we will compute the electric field by direct integration to check the result.
$$
E(r) = \frac{\lambda}{4\pi \epsilon_o} 
\int_{-L}^L \frac{r dx}{\left( r^2 + x^2 \right)^{3/2} }.
$$
Change variable to $\tan \theta = \frac{x}{r}$, we can carry out the integration:
$$ \tag{2}
E(r) = \frac{\lambda}{2\pi \epsilon_o r} \frac{L}{\sqrt{L^2 + r^2}}\approx \frac{\lambda}{2\pi \epsilon_o r} \left( 1 - \frac{r^2}{2 L^2}\right).
$$
Comparing Eq.(1) and Eq.(2), we conclude that a vicinity of point P having electric field in the outward $r$ direction is not good enough to apply Gauss's theorem in the finite length of line charge. Its validity requires additional condition, either $L\to\infty$, or the point P is very close to the line charge, $r \ll L$.
A: Gauss's law can be applied to any surface completely surrounding a volume. If the electric field is perpendicular to the surface and equal in magnitude over the surface, or something similar, the law can be used to find the magnitude of the field. But if these very special conditions are not met, the law can't be used to find the strength of the field, even though the law applies!
For your problem the most promising surface is a cylinder coaxial with the rod, and whose curved surface passes through P. How long should the cylinder be?
(a) Let the cylinder be infinitely long, that is cylinder length >> L. This has the advantage that $\mathbf E$ through the (plane) ends of the cylinder will be negligible. Now, using G's law:
$$\int \mathbf E.d\mathbf S_{ends}+\int \mathbf E.d\mathbf S_{curved}=\frac{Q}{\epsilon_0}$$
The first of these integrals being zero, we have $$\int \mathbf E.d\mathbf S_{curved}=\frac{Q}{\epsilon_0}.$$ But alas! $\mathbf E$ will not be constant in magnitude or direction over the curved surface. It will be strongest in magnitude and, by symmetry, normal to the surface, at point P and on the circle containing P, but will fall off in magnitude and acquire components parallel to the axis, as we move away from the central circle that includes P. This is clear by considering qualitatively the vector sums of the fields due to the different parts of the rod. Therefore G's theorem doesn't help us to find the value of $\mathbf E$ at P, because we can't work back from the known value of the integral to find values of $\mathbf E$ at particular points.
(b) If we make the cylinder shorter, perhaps so that its flat ends touch the ends of the rod, things are if anything worse. Now G's law gives us
$$\int \mathbf E.d\mathbf S_{ends}+\int \mathbf E.d\mathbf S_{curved}=\frac{Q}{\epsilon_0}$$
and the first integral is non-zero because there will be a field with component parallel to the rod axis passing through the ends of the cylinder.
