2
$\begingroup$

Consider the vector field defined by: $$\vec F(x,y)=\langle 2xy-\sin x,x^2+e^{3y}\rangle$$ We can check to see if the vector field is conservative with the following calculations: $$\begin{align*} \frac{\partial}{\partial x}(x^2+e^{3y})=2x\\ \frac{\partial}{\partial y}(2xy-\sin x)=2x\\ \end{align*}$$ Now, I am interested in looking at several different procedures for finding a scalar function $f(x,y)$ such that $\vec F(x,y)=\nabla f(x,y)$. Can folks share their ideas?

Update: Sure, students need to attack this by hand in class in the following manner.

$$\begin{align*} \vec F(x,y)&=\nabla f(x,y)\\ \langle 3+2xy, x^2-3y^2\rangle&=\langle\partial f/\partial x, \partial f/\partial y\rangle \end{align*}$$

They start by setting $$\frac{\partial f}{\partial x}=3+2xy,$$ then integrate with respect to $x$. $$f(x,y)=3x+x^2y+h(y)$$ The second step is to set: $$\begin{align*} \frac{\partial f}{\partial y}&=x^2-3y^2\\ \frac{\partial}{\partial y}(3x+x^2y+h(y))&=x^2-3y^2\\ x^2+h'(y)&=x^2-3y^2 \end{align*}$$ The last line gives us $$h'(y)=-3y^2,$$ then integrating gives us $$h(y)=-y^3.$$ Subbing this into $f(x,y)=3x+x^2y+h(y)$ gives the final answer. $$f(x,y)=3x+x^2y-y^3$$

So I am trying:

Clear[f, h, x, y, p, q]
p = 3 + 2 x y;
q = x^2 - 3 y^2;

Then I perform the conservative test:

D[p, y]
D[q, x]

Which gives:

(* 2x *)

(* 2x *)

So we do have a conservative vector field. Next:

f=Integrate[p,x]+h[y]

Which gives:

(* 3 x + x^2 y + h[y] *)

Next, I run:

Solve[D[f, y] == q, h'[y]]

Which gives:

(* {{Derivative[1][h][y] -> -3 y^2}} *)

Then I do this:

Integrate[-3 y^2, y]

Which gives:

(* -y^3 *)

Then I do this:

f = f /. h[y] -> -y^3

Which gives the final answer:

(* 3 x + x^2 y - y^3 *)

I love the answers I have received thus far, but would also like to see what folks do to purify my attempt.

$\endgroup$
2
  • $\begingroup$ See also 100521. $\endgroup$
    – bbgodfrey
    Nov 29, 2015 at 17:27
  • $\begingroup$ The approach in your update seems quite reasonable to me. $\endgroup$
    – bbgodfrey
    Nov 30, 2015 at 5:16

2 Answers 2

6
$\begingroup$

The typical approach is

DSolve[{D[f[x, y], x] == 2 x y - Sin[x], D[f[x, y], y] == x^2 + Exp[3 y]}, f[x, y], {x, y}]
(* {{f[x, y] -> E^(3 y)/3 + x^2 y + C[1] + Cos[x]}} *)

Note that, if the vector field were not conservative, DSolve would return unevaluated.

$\endgroup$
4
  • 2
    $\begingroup$ Short and simple; it gets my upvote. (But I am a little concerned that DSolve might be checking the political views of its arguments..) $\endgroup$ Nov 29, 2015 at 17:53
  • $\begingroup$ @bbgodfrey A very elegant approach. This is definitely an approach I will use in class tomorrow with my students. It will also give those students who will take differential equations next semester a nice introductory look to the DSolve command. $\endgroup$
    – David
    Nov 29, 2015 at 19:53
  • $\begingroup$ @bbgodfrey - this is a helpful piece of code. How would you extend it to (x,y,z), a 3 variable equation. I tried to play around with this code, which I got to work for 2D equations, but could't get it to work for 3-D when I added a z component where it seemed right. Thoughts? $\endgroup$
    – Abcderia
    Dec 24, 2020 at 2:11
  • $\begingroup$ @user27847 I believe that my approach does not generalize well to 3D. You might wish to ask a question based on your particular case. $\endgroup$
    – bbgodfrey
    Dec 24, 2020 at 2:24
4
$\begingroup$

Very elegant bbgodfrey; here is another method:

eq1 = Integrate[2 x y - Sin[x], x] // Expand;
eq2 = Integrate[x^2 + Exp[3 y], y] // Expand;
DeleteDuplicates@Flatten[List @@@ {eq1, eq2}] // Total

E^(3 y)/3 + x^2 y + Cos[x]
$\endgroup$
1
  • $\begingroup$ Another very interesting approach. This again helps me understand the @@@, the Flatten, and DeleteDuplicates commands. Extremely helpful. Thanks. $\endgroup$
    – David
    Nov 29, 2015 at 19:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.