Constructing a potential energy function from a conservative force field Given:
$F(x,y,z)=(x-y,-x-y+z,y+z)$
Find a potential energy that corresponds to this force field. Check your answer by taking its gradient.
I've already shown that this force field is conservative by 
$$\nabla \times  F =0$$
Now, I used $\nabla U=-F$ to find the potential function. I did so by
$$U=-\int F \cdot \vec{dr}$$
$$=-\left [\int (x-y)dx + \int(-x-y+z)dy + \int (y+z)dz \right ]$$
$$=\frac{1}{2}(-x^2+y^2-z^2)+2xy-2yz$$
Now I need to check it by taking its gradient, but its not resulting in the original force field.
$$\nabla U=-F$$
$$F=-\nabla U$$
$$=- \left [\frac{\partial U}{\partial x}+\frac{\partial U}{\partial x}+\frac{\partial U}{\partial x} \right ]$$
$$=- \left [ (-x+2y)+(y+2x-2z)+(-z-2y)\right ]$$
$$=(x-2y)+(-2x-y+2z)+(2y+z)$$
What did I miss?
 A: You started out OK by setting up $U=-\int\mathbf F\cdot d\mathbf r$, but then you appear to have confused this line integral with an indefinite integral. Perhaps you made this mistake because of leaving out an important detail: the path along which the line integral is to be taken (the integral’s bounds, as it were). I.e., it’s properly something like $U=-\int_\Gamma\mathbf F\cdot d\mathbf r$, which is like a definite integral from elementary calculus—it produces a number, not a function. This error is akin to saying that if $f={dF\over dx}$, then $F(x)=\int_a^b f(t)\,dt$.  
You can in fact use a line integral to find a function $U:\mathbb R^n\to\mathbb R$ such that $\nabla U=-\mathbf F$, but you have to proceed a little differently. Recall from elementary calculus that $F(x)=\int_0^x f(t)\,dt$ is an antiderivative of $f$, that is, that ${dF\over dx}=f$. Note the difference between this integral and the one in the previous paragraph: the upper bound is variable. We can do a similar thing for a conservative vector field: Let $U(0)=0$ and set $U(\mathbf r)=-\int_{\Gamma_{\mathbf r}}\mathbf F\cdot d\mathbf r$, where $\Gamma_{\mathbf r}$ is a differentiable path from the origin to $\mathbf r$. Since $\mathbf F$ is conservative, the value of this integral depends only on its endpoints, not on the specific path taken, so this function is well-defined (as long as the integral exists, of course). A convenient choice for $\Gamma$ is the line segment joining the point $\mathbf r$ to the origin, which we can parameterize in the obvious way as $\gamma: t\mapsto t\,\mathbf r$ for $t\in[0,1]$. We then get $$U(\mathbf r)=-\int_0^1F(\gamma(t))\cdot\gamma'(t)\,dt=-\int_0^1\mathbf F(t\,\mathbf r)\cdot\mathbf r\,dt.\tag{*}$$ Applying this to your example, $$\begin{align} U(x,y,z) &= -\int_0^1\mathbf F(tx,ty,tz)\cdot(x,y,z)\,dt \\ &= -\int_0^1x(tx-ty)+y(-tx-tz+tz)+z(ty+tz)\,dt \\ &=-\int_0^1(x^2-2xy-y^2+2yz+z^2)\,t\,dt \\ &= -\frac12(x^2-2xy-y^2+2yz+z^2).\end{align}$$ You can verify for yourself that $\nabla U=-\mathbf F$. If we take $U(0)$ to be some value other than $0$, this amounts to changing the constant of integration, i.e., (*) becomes $$U(\mathbf r)=U(0)-\int_0^1\mathbf F(t\,\mathbf r)\cdot\mathbf r\,dt.$$
A: we have
$\frac{\partial U}{\partial x}=-x+y$
so
$U=\frac{-x^2}{2}+xy+C_1(y,z)$
$\frac{\partial U}{\partial y}=x+y-z$
so
$U=xy+\frac{y^2}{2}-zy+C_3(x,z)$
$\frac{\partial U}{\partial z}=-y-z$
so
$U=-yz-\frac{z^2}{2}+C_3(x,y)$
and  finally
$U=-\frac{x^2}{2}+xy-yz+\frac{y^2}{2}-\frac{z^2}{2}+C$
$C$ is a constant.
A: Since you know that $F$ is conservative, you know that $F=\nabla U$ for some $U$. Using the definition of $\nabla U$ this tells you that:
$$
\begin{align}
\frac{\partial U}{\partial x}&= x-y \\
\frac{\partial U}{\partial y}&= -x-y+z \\
\frac{\partial U}{\partial z}&=y+z 
\end{align}
$$
You can begin integrating with any of these. If we start with the first we get:
$$
\begin{align}
\frac{\partial U}{\partial x}&= x-y \\
\implies U&=\frac{1}{2}x^2-xy+h(y,z)
\end{align}
$$
for some function $h(y,z)$. Differentiating this with respect to $y$ and comparing to $\frac{\partial U}{\partial y}= -x-y+z$ yields:
$$
\frac{\partial U}{\partial y}=-x+\frac{\partial h}{\partial y}
$$
So $\frac{\partial h}{\partial y}=-y+z$ and hence $h=-\frac{1}{2}y^2+zy+g(z)$ for some function $g(z)$. Finally differentiating $U$ with respect to $z$ and comparing to $\frac{\partial U}{\partial z}=y+z$ yields:
$$
\frac{\partial U}{\partial z}=y+\frac{dg}{dz}
$$
so $\frac{dg}{dz}=z$. This gives us $U=\frac{1}{2}x^2-\frac{1}{2}y^2+\frac{1}{2}z^2-xy+yz+C$ for some constant $C$. You want $-U$ for your solution. 
