So, I understand that one can solve for scalar function $f$ given a conservative gradient vector.
As an example, find $f(x,y)$ such that $∇f = F$, given:
$F(x,y) = <xy^2, x^2y>$
$\int\frac{\partial f}{\partial x} = \int xy^2 dx$
$f = \frac{x^2y^2}{2} + g(y)$
$\frac{\partial f}{\partial y} = \frac{\partial}{\partial y}[\frac{x^2y^2}{2} + g(y)]$
$= x^2y + g'(y) = x^2y$
$g'(y) = 0$
$g(y) = 0 + C$
$f(x,y) = \frac{x^2y^2}{2} + C$
Now, my main question is for what purpose do we need $g(y)$ after integrating $xy^2$ with respect to $x$? I understand the general process of finding the scalar function, but can anyone maybe explain it a bit more in-depth?
This is how I understand it:
We have a function $f(x,y)$ such that $\nabla f(x,y) = (\frac {\partial f}{\partial x}, \frac {\partial f}{\partial y}) = (xy^2, x^2y)$.
This gives us the two equations:
$\frac {\partial f}{\partial x} = xy^2$
$\frac {\partial f}{\partial y} = x^2y$
Let's consider the first equation. $\frac {\partial f}{\partial x}$ is the derivative of $f$ with respect to $x$. It represents how much the variable $x$ affects the function $f$ given some fixed $y$.
Normally, when we integrate with respect to one variable, we add a constant $C$, because there may have been a constant that wouldn't have affected the derivative. In the multivariate case, rather than a constant $C$, we add a function $g(y)$ because the constant at a fixed $y$ may depend on the value of $y$.
So now we know that $f(x,y) = \frac {x^2y^2}{2} + g(y)$. But we can improve this answer by finding out what $g(y)$ is. As you did, we take the derivative with respect to $y$ on both sides:
$\frac {\partial f}{\partial y} = \frac {1}{\partial y} [\frac {x^2y^2}{2} + g(y)]$.
Using our second equation, we get:
$x^2y = x^2y + g'(y)$. So $g'(y)=0$.
Now, we integrate $g'(y)$. But since this time, $g$ is a single variable function, the best we can do is add a constant $C$ to get $g(y)=0 + C$. This should leave you with the answer that you got.