Finding the scalar potential of a vector-valued function I am trying to find the scalar potential of a particular vector-valued function
that I am working with, and I find that the function in question is
$$\mathbf{g}(x,y) = \left( \frac{2x+y}{1+x^2+xy} , \frac{x}{1+x^2+xy}\right)
.$$
My friends have suggested to me that most mechanisms designed to find
scalar potentials is simply a guess-and-check, using clues in the function
to help guide potentialy candidates for the scalar potential. However, I
thought that it would be most reasonable if I could find a more fleshed-out
mechanism for solving for scalar potentials in these problems. We can see that
we are looking for an $f$ such that
$$\frac{\partial f}{\partial x} = g_1(x,y) \wedge
\frac{\partial f}{\partial y} = g_2(x,y).$$
Note that
$$f(x,y) - f(x,0) = \int_0^y g_1(x,t) dt= \int_0^y \frac{x}{1+x^2+xt} dt,$$
Which after some manipulation leaves us with the result
$$f(x,y) = \log\left(\frac{1+x^2+xy}{1+x^2}\right) + f(x,0).$$
The problem is, I can't seem to figure out a reasonable mechanism for solving
for $f(x,0).$ Any suggestions?
 A: Perhaps all of the examples that your friends have seen seemed like “guess and check,” but there is in fact a systematic way to find a scalar potential. The system of differential equations that you’ve written down is the key. Start with either one of these equations, say the one for ${\partial f\over\partial x}$, and solve it by integrating: $$
f(x,y) = \int g_1(x,y)\,dx = f_1(x,y)+h(y).$$ Notice that the “constant” of integration is an as yet unknown function of $y$ only. Now differentiate this with respect to $y$: $${\partial f\over\partial y}=g_2(x,y)=\frac\partial{\partial y}f_1(x,y)+h'(y)$$ or $$h'(y)=g_2(x,y)-\frac\partial{\partial y}f_1(x,y).$$ If you’ve done everything correctly this will also be a function of $y$ only. Integrate this with respect to $y$, add the result of that to $f_1$ and you’re done. This method generalizes to higher-dimensional spaces—just keep going back and forth between integration and differentiation, eliminating a variable at each step.  
In your case, we have $$
\int{2x+y\over1+x^2+xy}\,dx = \log(1+x^2+xy)+h(y) \\
h'(y) = {x\over1+x^2+xy}-\frac\partial{\partial y}\log(1+x^2+xy) = 0,
$$ therefore $$f(x,y) = \log C(1+x^2+xy),$$ where I’ve taken the constant of integration to be $\log C$ in order to absorb it into the expression inside the logarithm.  
There’s a different method that gets you an antiderivative in a single step. Choose a convenient point $P_0$ define $f(0)=0$ and $f(P)=\int_\Gamma g\cdot d\mathbf r$, where $\Gamma$ is a conveniently chosen path joining $P_0$ to $P$. Since $g$ is conservative, this integral depends only on the endpoints and not on the specific path. It shouldn’t be hard to convince yourself that this scalar function fits the bill.  
Assuming that the region is star-shaped with respect to the origin, choose $P_0=0$. Choose $\Gamma$ be the line segment joining the origin and $P=(x,y)$ parametrized as $t\mapsto(tx,ty)$ for $0\le t\le1$. Then $$f(x,y) = \int_0^1 xg_1(tx,ty)+yg_2(tx,ty)\,dt.$$ Choosing a different $P_0$ amounts to changing the constant of integration. This integral can sometimes be easier or faster to compute than the back-and-forth method. It can easily be adapted to any star-shaped region, or to any region that’s contractible to a point. (With a few additional steps, this method can be extended to finding antiderivatives of $k$-forms.)  
Applying this method to your example, we have $$\begin{align}
\int_0^1x{2tx+ty\over1+t^2x^2+t^2xy}+y{tx\over1+t^2x^2+t^2xy}\,dt &= \int_0^1{2tx^2+2txy\over1+t^2x^2+t^2xy}\,dt \\
&= \log(1+t^2x^2+t^2xy)\Big|_0^1 \\
&= \log(1+x^2+xy).
\end{align}$$  
Going back to your original attempt, what you’ve effectively done is compute the line integral of $g$ on the line segment from $(x,0)$ to $(x,y)$, but by the above reasoning what you really needed was a path from $(0,0)$ to $(x,y)$ instead. So, add a segment from $(0,0)$ to $(x,0)$: $$\int_0^x g_1(t,0)\,dt = \int_0^x{2t\over1+t^2}\,dt=\log(1+x^2).$$ This will cancel the $1+x^2$ in the denominator of the integral that you computed.
