The typical solution of such expressions proceeds as in the following example. Suppose
f[x, y] = Exp[x^2 + y^2] Cos[x + y] + x + y^3
(* x + y^3 + E^(x^2 + y^2)*Cos[x + y] *)
From these we construct p
and q
.
p[x, y] = D[f[x, y], x]
(* 1 + 2*E^(x^2 + y^2)*x*Cos[x + y] - E^(x^2 + y^2)*Sin[x + y] *)
q[x, y] = D[f[x, y], y]
(* 3*y^2 + 2*E^(x^2 + y^2)*y*Cos[x + y] - E^(x^2 + y^2)*Sin[x + y] *)
From p
and q
, we now wish to compute f
. This is possible, only if
D[p[x, y], y] == D[q[x, y], x]
True
and it is. To proceed, we compute the integrals
fx[x, y] = FullSimplify[Integrate[p[x, y], x]] + cy[y]
(* x + E^(x^2 + y^2)*Cos[x + y] + cy[y] *)
where cy[y]
, an arbitrary function of y
, has been added, because Integrate
does not do so. Similarly,
fy[x, y] = FullSimplify[Integrate[q[x, y], y]] + cx[x]
(* y^3 + E^(x^2 + y^2)*Cos[x + y] + cx[x] *)
To determine cx[x]
and cy[y]
, fx
and fy
are equated.
FullSimplify[fx[x, y] - fy[x, y]] == 0
(* x - y^3 - cx[x] + cy[y] == 0 *)
Hence, cx[x] = x + c
and cy[y] = y^3 + c
, with c
an arbitrary constant. Substituting these into fx
and fy
give for both
f[x, y] = Exp[x^2 + y^2]*Cos[x + y] + x + y^3 + c
as desired. A more formal but equivalent approach is available here.
Addendum
DSolve
has become more effective since this question first was posted and now can solve it directly. For instance, with the sample problem used earlier in this answer,
DSolveValue[
{D[f[x, y], x] == 1 + 2 E^(x^2 + y^2) x Cos[x + y] - E^(x^2 + y^2) Sin[x + y],
D[f[x, y], y] == 3 y^2 + 2 E^(x^2 + y^2) y Cos[x + y] - E^(x^2 + y^2) Sin[x + y]},
f[x, y], {x, y}] // FullSimplify
(* x + y^3 + C[1] + E^(x^2 + y^2) Cos[x + y] *)
as desired.