Below is a long-form of the suggestion I showed in comments, where I am afraid I was not clear. I meant to suggest that you should do two things: 1. do the replacement within Integrate
; 2. apply First to the result of Solve
so you get an expression, rather than a single-element list containing your expression, from the replacement:
Clear[exact]
exact[Mx_, Ny_] :=
c + Integrate[g'[y] /. First@Solve[D[Integrate[Mx, x] + g[y], y] == Ny, g'[y]], y]
Let's try it out on something simple:
exact[2 x + 2 y, 2 x + 2 y]
(* Out: c + y^2 *)
This seems to be what you wanted. Reconstructing piece by piece:
Integrate[Mx, x]
becomes Integrate[2 x + 2 y, x]
, which returns 2 (x^2/2 + x y)
;
- Add
g[y]
to get 2 (x^2/2 + x y) + g[y]
;
- Take the derivative wrt $y$ and set it equal to
Ny
: 2 x + g'[y] == 2 x + 2 y
- Solving for
g'[y]
returns {{g'[y] -> 2 y}}
; take the first part, to give {g'[y] -> 2 y}
Summarizing, you then apply the replacement within Integrate
:
g'[y] /. First@Solve[D[Integrate[2 x + 2 y, x] + g[y], y] == 2 x + 2 y, g'[y]]
(* Out: 2 y *)
- Finally, find the antiderivative wrt $y$, which is
y^2
, and add c
. This confirms the result obtained with your exact
function.
Integrate[g'[y] /. First@Solve[...], y]
$\endgroup$Integrate[a[y], y] + c /. (a[y] -> g'[y] /. Solve[D[Integrate[Mx, x] + g[y], y] == Ny, g'[y]][[1]])
. Still I'm hoping a better solution will arrive. $\endgroup$