\documentclass[12pt]{amsart}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}

\setlength{\topmargin}{-0.5in}
\usepackage{amssymb,amsmath,amsfonts,graphicx,psfrag}

%\pagestyle{empty}
\newcommand{\dis}{\displaystyle}
\newcommand{\bd}{\partial}
\begin{document}
{\Large

\begin{center}
{\bf Exact First Order Differential Equations}
\end{center}

This Lecture covers material in Section 2.6. A first order differential 
equations is {\bf exact} if it can be written in the form
\[
M(x,y) + N(x,y)\frac{dy}{dx} = 0,
\]
where
\[
\frac{\bd M}{\bd y} = \frac{\bd N}{\bd x}.
\]

Before showing how to solve these we need to review some multivariable calculus, 
especially the {\bf two-variable chain rule}. This will also help to motivate 
why equations of this form are important in physics. 

Let $\psi(x,y)$ be a function of two variables. Then we can think of 
\[z = \psi(x,y) \]
as a surface in three-dimensional space where $z$ is the height above 
the $xy$-plane. Now suppose the $x$ and $y$ are functions of $t$ (time) 
so that $( x(t), y(t) )$ gives a curve in the $xy$-plane.
Then $z(t) = \psi(x(t),y(t))$ gives a curve in three-dimensional space.
Suppose we desire to know the rate of change of $z$ with respect to $t$. 
According to the two-variable chain rule the answer is
\[
\frac{dz}{dt} = \frac{\bd \psi}{\bd x}\frac{dx}{dt} + \frac{\bd \psi}{\bd y}\frac{dy}{dt}. \hspace{1in} (*)
\]
This formula is derived in Calculus III. Here I will give an intuitive motivation for why it works. 

Suppose $\psi(x,y)$ is just a plane. Then we have
\[
z = \psi(x,y) = Ax + By + C
\]
for some constants $A$, $B$ and $C$. Here $A$ is the slope of the plane with respect 
to the $x$ direction, $B$ is the slope of the plane with respect to the $y$ direction and $C$ is the intercept with the $z$-axis.


\begin{center}
\includegraphics[height=2in]{Figs/planeinR3.pdf}

$z = -\frac{1}{2}x-\frac{3}{4}y+3$
\end{center}

\vspace{.25in}
We want to compute the change in $z$ as $t$ changes from $t_0$ to 
$t_0 + \Delta t$. Let $\Delta x = x(t_0 + \Delta t) - x(t_0)$ and 
$\Delta y = y(t_0 + \Delta t) - y(t_0)$ be the changes in $x$ and $y$, respectively. 
For convenience let $x_0 = x(t_0)$ and $y_0 = y(t_0)$. Then the change in $z$ is
\[
\Delta z = \psi(x_0+\Delta x, y_0 + \Delta y) - \psi(x_0, y_0) =
A\Delta x + B \Delta y.
\]
We divide both sides by $\Delta t$ to obtain
\[
\frac{\Delta z}{\Delta t} = A \frac{\Delta x}{\Delta t} + B \frac{\Delta y}{\Delta t}.
\]
Now we can find the derivative of $z$ with respect to $t$ by taking limits as $\Delta t \to 0$. This gives
\[
\frac{dz}{dt} = A\frac{dx}{dt} + B \frac{dy}{dt}.
\]
But notice that $A = \bd_x \psi$ and $B=\bd_y \psi$. Thus we have
\[
\frac{dz}{dt} = \frac{\bd \psi}{\bd x}\frac{dx}{dt} + \frac{\bd \psi}{\bd y}\frac{dy}{dt}
\]
which is $(*)$. 

This shows that the two-variable chain rule works for planes. In general if $\psi(x,y)$ is reasonably 
smooth it can be approximated near each point by a tangent plane. It can be shown that this 
gives the two-variable chain rule for any function of two variables that is smooth enough that 
its graph has a tangent plane at each point in an open set containing the point of interest. 


Now, let $z=\psi(x,y)$ be a surface. But suppose $z$ is some quantity that is conserved, like energy. 
That is we now have 
\[
\psi(x,y) = C.
\]
The slice of the surface through $z=C$ is called {\bf level curve}.

Example: Let $z = \psi(x,y) = x^2 + y^2$. Then the level curve for $z=1$ is a
circle of radius 1 that floats one unit above the $xy$-plane.

Example: Let $z = \psi(x,y) = 3x+y-3$. The level curve for $z=2$ is the line 
$3x+y-3 = 2$, or $y=-3x + 5$, that is it floating two units above the $xy$-plane. 


For now suppose $y$ is a function of $x$ (at least implicitly). As we change 
$x$ we cause $y$ to change so that $z=\psi(x,y)$ stays on the same level curve. Since 
$z$ is not changing we have $dz/dx = 0$. The two-variable chain rule, using 
$x$ for $t$, gives
\[
0 = \frac{dz}{dx} = \frac{\psi(x,y(x))}{dx} = \frac{\bd \psi}{\bd x}\frac{dx}{dx} + \frac{\bd \psi}{\bd y}\frac{dy}{dx}.
\]
Therefore,
\[
\frac{\bd \psi}{\bd x} +  \frac{\bd \psi}{\bd y} y' = 0.
\]
If $\psi_x$ and $\psi_y$ are  known functions what we have is a differential equation in $y$. 

We will be doing the inverse of this process. That is, given at differential equation in the
form
\[
M(x,y) + N(x,y) \frac{dy}{dx} = 0
\]
we will solve it for $y(x)$ (or at least a relation between $x$ and $y$) by finding a surface
$\psi(x,y)$ such that $M= \psi_x$ and $N=\psi_y$, and then using an initial condition to find
the desired level curve. In many applications $\left< M, N \right>$ is given as a force field
and then $\psi$ is a potential energy function. If energy is conserved, the dynamics are 
restricted to a level curve of $z=\psi(x,y)$. 


Enough talk, let's do some examples.

{\bf Example 1.} Solve $(2x+y) + (x+2y)y'=0$, with $y(3)=1$.

\begin{proof}[Solution]
We want to find a function $\psi(x,y)$ such that
\[
\frac{\bd \psi}{\bd x} = 2x+y \hspace{.5in}\&\hspace{0.5in}\frac{\bd \psi}{\bd y} = x+2y.
\]
So, we integrate.
\[ \psi = \int \psi_x \, dx = \int 2x+y \, dx = x^2 + xy + C_1(y),\]
where $C_1(y)$ an arbitrary function of $y$. The idea is we are finding the class
of all functions whose partial derivative with respect to $x$ gives $2x+y$.  

But we also need for $\psi_y = x+2y$. So, we integrate.
\[ \psi = \int \psi_y \, dy = \int x+2y \, dy =  xy + y^2 + C_2(x),\]
where $C_2(x)$ can be any function of $x$. 

We now have two classes of functions, each satisfying one of the two conditions. If we
could find a function that is in both class that would do the trick. The answer is obvious.
Let
\[
\psi(x,y) = x^2 + xy + y^2.
\]
This function is in both classes and thus satisfies both the needed conditions. Now we consider
the initial condition, $y(3)=1$, that is, $x=3$ $\implies$ $y=1$. Then
\[
\psi(3,1) = 9+3+1=13.
\]
Thus, the level curve we want is
\[
x^2 +xy + y^2 = 13.
\]
We will leave as a relation. Below are plots of the surface $z=x^2 +xy + y^2$ with the 
level 13 curve and a projection of this curve into the $xy$-plane.
\end{proof}


\begin{center}
\includegraphics[width=2in]{Figs/surface1.jpg}
\hspace{0.5in}
\includegraphics[width=2in]{Figs/levelcurve1.jpg}
\end{center}

{\bf Extra Credit.} Prove that this curve $x^2+xy+y^2=13$ is an ellipse and find its focal points.
You can do this by reviewing how to rotate graphs with rotation matrices and the properties of ellipses. Then rotate 
the graph $45^o$ so that its major axis lies along the x-axis. 

\vspace{.25in}

{\bf Example 2 (Not!).} Solve  $(2x+2y) + (x+2y)y'=0$, with $y(3)=1$. We integrate.
\[
\psi = \int 2x+2y \, dx = x^2 + 2xy + C_1(y).
\]
\[
\psi = \int x+2y \, dy = xy + y^2 + C_2(x).
\]
Now look closely. Since $2xy \neq xy$ there is no function that meets both 
conditions. The method fails! What this means in physical terms is that the 
force field $\left< 2x+2y, x+2y \right>$ does not arise from a potential 
function; in such a system energy is {\bf not conserved}. 

\vspace{.1in}
Note: This example can be converted to a separable equation because it is homogeneous. We work through this in the Appendix at
the end of these notes. It is optional reading.
\vspace{.1in}

What we need is a quick test to see if $\psi$ exists for a given equation so 
that we don't waste a lot of time barking up the wrong tree. 

\vspace{.1in}


{\bf Theorem!} Given two functions $M(x,y)$ and $N(x,y)$, there exists 
a function $\psi(x,y)$ such that
\[
\frac{\bd \psi}{\bd x} = M(x,y) \hspace{0.5in}\&\hspace{0.5in} \frac{\bd \psi}{\bd y} = N(x,y),
\]
if and only if 
\[
\frac{\bd M}{\bd y} = \frac{\bd N}{\bd x},
\]
in an open rectangle containing the point of interest. 


Check this for the two examples above. This is Theorem 2.6.1 in your textbook. 
Your textbook gives a proof, but another prove is covered in Calculus III that 
uses Green's Theorem. If you are a Math major read both and compare them. 
However, one direction is easy: if $\psi$ exists, then 
$\psi_{xy} = \psi_{yx} \implies M_y = N_x$. This theorem is the motivation for the
definition we gave at the beginning of an exact first order differential equation.

\vspace{.25in}
{\bf Example 3.} Find the general solution to 
\[
y \cos x + y e^{xy} + (\sin x + x e^{xy}) y' = 0.
\]

\begin{proof}[Solution]
Let $M= y \cos x + y e^{xy}$ and $N=\sin x + x e^{xy}$. Then
\[
M_y = \cos x + e^{xy} + xy e^{xy} = N_x.
\]
Thus, it is exact. We integrate.
\[
\psi = \int M \, dx = y \sin x + e^{xy} + C_1(y)
\]
and 
\[
\psi = \int N \, dy = y \sin x + e^{xy} + C_2(x).
\]
We let $\psi(x,y) =  y \sin x + e^{xy}$. The general solution is then
\[
y\sin x + e^{xy} = C.
\]
\end{proof}

{\bf Example 4.} Solve $4x^3 + 4y^3 y' = 0$, with $y(1) = 1$.

\begin{proof}[Solution]
It is exact since $(4x^3)_y = 0$ and $(4y^3)_x = 0$. Then
\[
\psi = \int 4x^3 \, dx = x^4 + C_1(y)
\]
and 
\[
\psi = \int 4y^3 \, dy = y^4 + C_2(x).
\]
We let $\psi = x^4 + y^4$. Since (1,1) is our initial condition
we see that our solution is 
\[
x^4 + y^4 = 2.
\]
Below is a graph of this curve projected into the $xy$-plane.
\end{proof}

\begin{center}
\includegraphics[width=2in]{Figs/x4y4.jpg}
\end{center}

{\bf Example 5.}  Solve $4x^4 + 4xy^3 y' = 0$, with $y(1) = 1$.

\begin{proof}[Solution]
We check for exactness. $(4x^4)_y = 0$ while $(4xy^3)_x = 4y^3$. Thus it is not exact.
But wait! Notice that this example is exactly the same as Example 4, but that we have 
multiplied through by $x$. So, if we now multiple through by $\frac{1}{x}$ we get
\[
4x^3 + 4y^3 y' = 0.
\]
Thus, the solution is same as in Example 4! 
\end{proof}

\vspace{.25in}
{\bf Integrating factors.}
\vspace{.25in}

This last example motivates the following idea. Suppose we have 
a differential equation of the form
\[ 
M + N y' = 0
\]
which is not exact. Can we find a function $\mu(x,y)$ such that
\[
\mu M + \mu N y' = 0
\]
is exact?

The answer is, not always, but sometimes you can. When this works
we call $\mu$ an {\bf integrating factor}. Finding such as $\mu$
can be tricky. Here we show three special cases where an integrating factor $\mu$
can be found. Each relies on an assumption about $\mu$ that can be tested for.

\vspace{.25in}

{\bf Case 1.} Suppose a suitable $\mu$ exists and that it is a function of $x$ only.

\vspace{.25in}

{\bf Case 2.} Suppose a suitable $\mu$ exists and that it is a function of $y$ only.

\vspace{.25in}

{\bf Case 3.} Suppose a suitable $\mu$ exists and that it can be written as a function 
dependent only on the product $xy$.

\vspace{.25in}
In all cases we need to find $\mu$ such that
\[
(\mu M)_y = (\mu N)_x
\]
so that we have exactness. By the product rule this is equivalent to
requiring
\[
\mu_y M + \mu M_y =  \mu_x N + \mu N_x. \hspace{1in} (*)
\]

\vspace{.25in}

{\bf Case 1.} If Case 1 holds then $\mu_y =0$ and we can think of $\mu_x$ as $\mu'$. Then $(*)$
becomes
\[
\mu M_y = \mu' N + \mu N_x
\]
or
\[
\frac{\mu'}{\mu} = \frac{M_y - N_x}{N}.
\]
If our assumption is correct then, since $\mu'/\mu$ depends only on $x$, we know that
$(M_y -N_x)/N$ depends only on $x$. Then the integrals below are well defined.
\[
\int \frac{1}{\mu} \, d\mu = \int \frac{M_y - N_x}{N} \, dx
\]
Thus,
\[
\mu = e^{\int \frac{M_y - N_x}{N} \, dx }.
\]
In fact, this gives us a test to determine when this method will work. If $ \frac{M_y - N_x}{N}$ depends
only on $x$ it follows that $\mu$ depends only on $x$. 

\vspace{.25in}

{\bf Example 6.} Find the general solution to $y^2 + x^3 + xy y' = 0$.

\begin{proof}[Solution]
Since $(y^2+x^3)_y = 2y$  and $(xy)_x = y$ are not equal, this equation is not exact. But
\[
\frac{2y - y}{xy} = \frac{1}{x}
\]
depends only on $x$. Thus we let
\[
\mu = e^{\int \frac{1}{x}\, dx} = x. 
\]
So, we multiply through by $x$ to get
\[
xy^2 + x^4 + x^2y y' = 0.
\]
Let $M=xy^2 + x^4$ and $N=x^2y$. Then $M_y =2xy = N_x$, so we have exactness. Now we find $\psi$ as before.
\[
\psi = \int M \, dx = \frac{1}{2}x^2y^2 + \frac{1}{5}x^5 + C_1(y)
\]
\[
\psi = \int N\, dy = \frac{1}{2}x^2y^2 + C_2(x)
\]
Thus, we let $\psi =  \frac{1}{2}x^2y^2 + \frac{1}{5}x^5$, so the general solution is
\[
\frac{1}{2}x^2y^2 + \frac{1}{5}x^5 = C,
\] 
or if you prefer
\[
5x ^2y^2 + 2x^5 = C.
\]
Solving for $y$ gives
\[
y = \pm \sqrt{\frac{C-2x^5}{5x^2}}.
\]
\end{proof}

\vspace{.25in}

{\bf Case 2.} This is so similar to Case 1 that we leave it to you to develop the method and find the 
formula for $\mu(y)$.

\vspace{.25in}

{\bf Case 3.} Recall equation $(*)$: $\mu_y M + \mu M_y = \mu_x N + \mu N_x$. Let $v=xy$ and remember
we are assuming $\mu$ can be rewritten as a function of $v$. Thus,
\[
\mu_y = \frac{\bd \mu(v)}{\bd y} = \frac{d \mu}{dv} \frac{\bd v}{\bd y} = \frac{d\mu}{dv} \, \cdot x = x \mu',
\] 
and
\[
\mu_x = \frac{\bd \mu(v)}{\bd x} = \frac{d \mu}{d v} \frac{\bd v}{\bd y} = \frac{d\mu}{dv} \, \cdot y = y \mu',
\]
where $\mu'$ means the derivative with respect to $v$. Now $(*)$ becomes
\[
x\mu'M + \mu M_y = y\mu'N + \mu N_x,
\]
which gives
\[
\frac{\mu'}{\mu} = \frac{N_x - M_y}{xM-yN}.
\]
If the right hand side depends only on $v=xy$ then the assumption we are making is valid, and thus
\[
\mu = e^{\int \frac{N_x - M_y}{xM-yN} \, dv}.
\]

Perhaps an example would help.



\vspace{.25in}

{\bf Example 7.} Solve 
\[
5x^3 + \frac{1}{x}\cos xy + \frac{x^4 + \cos xy}{y} \frac{dy}{dx} = 0,
\]
with $y(1)=\pi$.

\begin{proof}[Solution]
Let $M = 5x^3 + \frac{1}{x}\cos xy$ and $N=\frac{x^4 + \cos xy}{y}$. Then
\[
M_y = -\sin xy \hspace{0.5in}\&\hspace{0.5in} N_x = \frac{4x^3 - y \sin xy}{y}
\]
Thus, the given equation is not exact. We now search for an integration factor.

\[
\mbox{Case 1.} \:\: \frac{M_y-N_x}{N} = \frac{-\frac{4x^3}{y}}{\frac{x^4+\cos xy}{y}} = \frac{-4x^3}{x^4 + \cos xy} \:\:\:\mbox{No good!}
\]
\[
\mbox{Case 2.} \:\: \frac{N_x-M_y}{M} = \frac{\frac{4x^3}{y}}{\frac{5x^4+\cos xy}{x}} = \frac{4x^4}{5x^4y + y \cos xy} \:\:\:\mbox{Rats!!}
\]

\[
\mbox{Case 3.} \:\: \frac{N_x-M_y}{xM-yN} = \frac{\frac{4x^3}{y}}{5x^4 + \cos xy -(x^4 + \cos xy)}
= \frac{1}{xy}!   \:\:\:\mbox{Eureka!!!} 
\]

Let $v=xy$. Now, 
\[
\mu(v) = e^{\int \frac{1}{v} \, dv} = e^{\ln |v|+C} = C|v| = C|xy|;
\]
we will use $\mu = xy$

On ward! We multiply the original equation by $xy$ to get
\[
5x^4y + y \cos xy + (x^5 + x \cos xy)y' = 0.
\]
Let $M= 5x^4y + y \cos xy$ and $N=x^5 + x \cos xy$. 
We double check that it is in fact exact.
\[
M_y = 5x^4 + \cos xy - xy \sin xy = N_x.
\]
Now the hunt is on for $\psi$! 
\[
\psi = \int M \, dx = x^5y + \sin xy + C_1(y)
\]
and
\[
\psi = \int N \, dy = x^5y + \sin xy + C_2(x).
\]
Thus, $\psi =  x^5y + \sin xy$ and the general solution is $x^5y + \sin xy =C$.
Since $y(1) = \pi$ you can check that $C=\pi$. Thus, the solution is
\[
x^5y + \sin xy = \pi.
\]
\end{proof}

\vspace{.2in}

\begin{center}
  {\sc Appendix A: More On Example 2.}\\{\sc [Optional Reading]}
\end{center}

Recall that Example 2 was not exact, but that it was noted that it
is homogeneous. Here we will solve it and study the solution.

\[
y' = \frac{-2x-2y}{x+2y} =\frac{-2-2y/x}{1+2y/x} = \frac{-2-2v}{1+2v},\]
where v = y/x. It follows that $y' = v + xv'$. Now we have
\[
x\frac{dv}{dx} =  \frac{-2-2v}{1+2v} - v =\frac{-2-2v}{1+2v} - v \frac{1+2v}{1+2v} = \frac{-2-3v-2v^2}{1+2v}. 
\]
Thus,
\[
-\int\frac{1+2v}{2+3v+2v^2} \, dv = \int\frac{1}{x}\,dx.
\]
We rewrite the left integrand as
\[
\frac{1}{2} \frac{4v+3-1}{2v^2+3v+2} = \frac{1}{2}\left(\frac{4v+3}{2v^2+3v+2}-\frac{1}{2v^2+3v+2} \right).
\]
Now,
\[
\int \frac{4v+3}{2v^2+3v+2}\, dv = \ln|2v^2+3v+2| + C,
\]
and
\[
\int \frac{1}{2v^2+3v+2}\, dv =\int \frac{1}{\left(\sqrt{2}v+\frac{3}{2\sqrt{2}}\right)^2 +7/8} \, dv.
\]
Let $u=\sqrt{2}v+\frac{3}{2\sqrt{2}}$. Then $du =\sqrt{2} dv$. The last integral becomes
\[
\frac{1}{\sqrt{2}} \int \frac{du}{u^2+7/8} = \frac{4\sqrt{2}}{7} \int\frac{du}{8u^2/7 + 1}. 
\]
Next let $w=\frac{2\sqrt{2}u}{\sqrt{7}}$. Then $dw = \frac{2\sqrt{2}du}{\sqrt{7}}$. Thus, the last integral becomes
\[
\frac{2}{\sqrt{7}} \int \frac{dw}{w^2+1} = \frac{2}{\sqrt{7}} \arctan (w)  + C.
\]
Putting all this together gives
\[
\ln|x| + C = -\frac{1}{2} \ln|2v^2+3v+2| +\frac{1}{\sqrt{7}}\arctan\left(\frac{4v+3}{\sqrt{7}}\right).
\]
Now we find $C$, Recall we were given $y(1)=1$. Since $v=y/x$ we get $v=1$.
Thus,
\[
0+C = \ln \left( \frac{1}{\sqrt{7}}\right) +  \frac{1}{\sqrt{7}}\arctan \left(\sqrt{7}\right).
\]
Thus, our solution is given by the relation
\[
\ln x = -\frac{1}{2} \ln (2v^2+3v+2) + \frac{1}{\sqrt{7}} \arctan\left( \frac{4v+3}{\sqrt{7}}\right)
\]\[-\ln \left(\frac{1}{\sqrt{7}}\right) - \frac{1}{\sqrt{7}} \arctan\left( \sqrt{7}\right),
\]
where $v=y/x$.

\vspace{.2in}
I tried to plot this, and some simplifications, using {\tt implicitplot} in Maple 17 and using WolframAlpha online. Neither could do anything with it. So, I punted and used Maple to numerically plot the solution curve. Here is the command and the plot it produced.

\vspace{.2in}
$>${\tt DEplot(diff(y(x),x)=(-2*x-2*y(x))/(x+2*y(x)),y(x),}\\{\tt x=1.0..2.0,[[y(1)=1]],y=-2.0..1.0,arrows=line,color=black,}\\{\tt linecolor=red);}
\vspace{.2in}

\begin{center}\vspace*{-0.5in}
\includegraphics[height=7in]{Figs/ExactEx2Plot.pdf}
\end{center}

\vspace*{-3in}
It also produced this warning: ``Warning, plot may be incomplete, the following errors(s) were issued:
cannot evaluate the solution further right of 1.9201778, probably a singularity''.

If you look at the original differential equation you may notice that $y'(x)$ is undefined when $x=-2y$. Study the graph. At $x$ equal about 2, $y$ is just about $-1$. Our solution curve ends and is not valid passed this point. 

}\end{document}
