I am trying to figure out how gauss law would hold in an electric field configuration that varies with space. For simplicity, let us assume the classic XYZ coordinate system. Consider an electric field along the x axis that varies a follows E(x,y,z) = K/(x^2), (similar to the coloumbs inverse square law.) and assume the field vector to be along the positive direction of the X axis, the field lines are parallel and equally spaced, assumed to come from a very large distance.
Now, for simplicity, suppose I choose a cube of side a, whose center lies on the X axis, let us say at some point x= A. With this cube as my Gaussian surface, and with the given configuration of the electric field, my calculations are as follows (using the integral form of gauss law):
The only two planes that would contribute to the flux are the ones parallel to the YZ plane. Let P1 and P2 be the planes. If the electric field at P1 is E1, the flux of it will be E1A. Similarly the flux through P2 will be -E2A (assuming the direction of area vector). The area of the surfaces being the same, the field clearly is different at P1 and P2, because the two planes are seperated by a distance = a.
Thus if E1 = K/(x^2) then E2 must be K/(x±a)^2.
How can in this case the flux be equal to zero? Please point out if I have any mistakes in my math, or if my analysis is wrong anywhere.