$\require{HMacros}$ $\require{eqn-number}$
$\require{HMacros}$ $\require{eqn-number}$
The integral in Gauss' Law does not depend on the shape of the surface being used. So let's replace the sphere in the previous example with a cube. Suppose the charge is at the origin, and the length of each side of the cube is $2$. What is the flux through one face? We have \begin{eqnarray*} \hbox{flux} = \Int_{-1}^1\Int_{-1}^1 {1\over4\pi\epsilon_0} {q\,\rhat\over r^2} \cdot \kk\,dx\,dy = {q\over4\pi\epsilon_0} \Int_{-1}^1\Int_{-1}^1 {dx\,dy\over\sqrt{x^2+y^2+1}} \end{eqnarray*}
This integral can be computed with the help of integral tables. Alternatively, the worksheet
$\qquad\qquad\qquad\qquad$ Flux Maple Worksheet
can be used to compute the answer. Does the result agree with the previous computation for the sphere? Now suppose the charge is not at the origin. Maple can still do the integrals numerically; try some examples. Finally, suppose the charge is on a face or an edge of the cube. What answer do you expect? Check and see.