Calculate the volume integral of the unit cube in the first octant. The problem asks to find $$ \int_V d^3 r \vec{\nabla} \cdot \vec{E} $$ over the volume V given by the unit cube in the first octant. Where, $$ \vec{E} = (x^3 - x^2) y \, \hat{i} + (y^3 - 2 y^2 + y) x \, \hat{j} + (z^2 - 1) \, \hat{k} $$
Now, by the divergence theorem $$ \int_V d^3 r \vec{\nabla} \cdot \vec{E} = \int_S d^2 r \vec{E} \cdot \hat{n}$$ we can evaluate this problem as a surface integral.
Here I pick my unit normal vector to be in the x-direction. $$ \hat{n} = \frac{x \hat{i}}{x} $$
Finding $$ \vec{E} \cdot \hat{n}$$ gives
$$ (x^3 - x^2)y$$
Also noting that the surface area of a cube is $$6r^2$$.
But since were restricted to a single octant and our length is 1,
$$ d^2 r = \frac{6}{8}$$
Then surface area integral becomes
$$ \int_S d^2 r \vec{E} \cdot \hat{n} = \frac{6}{8}(x^3 - x^2)y$$
Now, I am not certain I did this correctly. Should I have computed the integral surface for each of the 6 surfaces along the volume segment or would this have been better suited as a volume integral? Any guidance is appreciated.
 A: I assume the unit cube to be placed in the first octant with faces aligned to coordinate planes and one of the vertices at $(0, 0, 0)$.
$\vec E = (x^3 - x^2) y \, \hat{i} + (y^3 - 2 y^2 + y) x \, \hat{j} + (z^2 - 1) \, \hat{k} $
You can of course find the divergence of the vector field and then do the volume integral. But if you are using surface integral, note that there are $6$ surfaces in planes $x = 0, x = 1, y = 0, y = 1, z = 0$ and $z = 1$.
For $x = 0$, the unit normal vector is $(-1, 0, 0)$ and for $x = 1$, the unit normal vector is $(1, 0, 0)$ but $\hat i$ component of the vector field $ (x^3 - x^2) y = 0$ for both $x = 0$ and $x = 1$. So there is no flux through these two surfaces.
Similarly for $y = 0$ and $y = 1$, $y^3- 2y^2 + y = 0$ and again the surface integral for both faces in planes $y = 0$ and $y = 1$ is zero.
For $z = 1, z^2 - 1 = 0$ so for the given vector field, we have flux only through the surface in plane $z = 0$. The unit normal vector is $(0, 0, -1)$.
$ \vec E \cdot \hat n = ((x^3 - x^2) y, (y^3 - 2y^2 + y) x, -1) \cdot (0, 0, -1) = 1$
So the surface integral is simply the area of the surface in the plane $z = 0$, which is $1$ given it is unit cube.
Hence the net flux through the unit cube is $1$.
