\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}
%\newcommand{\R}{R}
\newcommand{\R}{\mathbb{R}}



\begin{document}
{%\Large

\begin{center}
  {\bf Part I. First Order Differential Equations}
\end{center}

\tableofcontents

\vfill\pagebreak

\section{Intro to First Order Differential Equations}

{\bf General Problem.} Let $F(x,y)$ be a given function of two variables. Find all functions $y(x)$ such that
\[
\frac{dy}{dx} = F(x,y).
\]

There are three special cases we shall consider.


\begin{itemize}
\item [A.] {\bf Separable.} This means $F(x,y)$ can be written in the
form $f(x)g(y)$. This is covered in Section 2.2 of the textbook.

\item [B.] {\bf Linear.} This means $F(x,y)$ can be written in the form 
  $f(x)y + g(x)$; so it is linear in the $y$ variable. This is covered in Section 2.1 of the textbook.

\item [C.] {\bf Exact.} This means $F(x,y)$ can be written in the form
  \[ F(x,y) = -\frac{M(x,y)}{N(x,y)},\]
  where
  \[ \frac{\bd M}{\bd y} = \frac{\bd N}{\bd x}.\]
  (The $\bd$ notation means partial derivatives. If you have not had this before see the Partial Derivatives handout.) This is covered in Section 2.6 of the textbook.
\end{itemize}

Sometimes when a first order differential equation is not in one of these forms it can be transformed into a differential equation in one of them using some algebraic tricks.

However, when none of these methods work we can use numerical methods to get approximate solutions. These are introduced in Section 2.7 of the textbook.

\vfill\pagebreak

\section{Separable Equations (Section 2.2 of textbook)}

{\bf Example 1.} Solve $y'(x) = x^3$. In this problem $F(x,y) = x^3$
and does not depend on $y$. Finding $y(x)$ is just a Calculus I exercise.
\[
y = \int x^3 \, dx = \frac{x^4}{4} + C.
\]
Recall that this means the solution set is
\[
\left\{  \frac{x^4}{4} + C \,\big|\, C \in \R \right\}.
\]
We say $y = \frac{1}{4}x^4+C$ is the {\em general solution}.

\vspace{1in}

{\bf Example 2.} Solve $y'(x) = 2 + \cos 2x$. We get that
\[
y = \int  2 + \cos 2x \, dx = 2x + \frac{1}{2} \sin 2x + C
\]
is the general solution.


%\vfill\pagebreak


{\bf Example 3.} Solve $y'(x) = \frac{x^2}{y}$. We write this as
\[
y \frac{dy}{dx} = x^2
\]
and then integrate both sides with respect to $x$.
\begin{eqnarray*}
  \int y \frac{dy}{dx} \, dx &=& \int x^2 \, dx \\
  \int y \, dy &=& \frac{1}{3}x^3 + C_1 \\
  \frac{1}{2}y^2 + C_2 &=& \frac{1}{3}x^3 + C_1.
\end{eqnarray*}
Thus,
\[
y = \pm \sqrt{\tfrac{2}{3}x^3 + C},
\]
is the general solution. (We consolidated the integration constants to $C = 2(C_1-C_2)$.) The solution set is

\[
\left\{ \sqrt{\tfrac{2}{3}x^3 + C} \, \Big|\, C\in \R \right\} \cup \left\{   -\sqrt{\tfrac{2}{3}x^3 + C} \, \Big|\, C\in \R \right\}.
  \]
  Notice that the domain of $x$ will be restricted so that we do not get the square roots of negative numbers.
  
  \vspace{.2in}
%\vfill\pagebreak

{\bf Example 4.} Solve $y'(x) = y^2x^3$. We rewrite this as $y^{-2}y' = x^3$ and then integrate both sides with respect to $x$.

\begin{eqnarray*}
  \int y^{-2} \frac{dy}{dx} \, dx &=& \int x^3 \, dx \\
  \int y^{-2} \, dy &=& \tfrac{1}{4}x^4 + C_1 \\
  -y^{-1} + C_2 &=& \tfrac{1}{4}x^4 + C_1 .
\end{eqnarray*}  
Thus,
\[
y = \frac{-1}{\frac{1}{4}x^4 + C}.
\]
This is equivalent to
\[
y  = \frac{4}{C - x^4}.
\]


\vspace{.2in}

{\bf Example 5.} Solve $y'(x) = \frac{\sin x}{y+1}$. As a shortcut we write
\[
\int y+1 \, dy = \int \sin x \, dx.
\]
This gives
\[
\tfrac{1}{2}y^2 + y = -\cos x + C.
\]
We can solve for $y$ using the quadratic formula. First, rewrite the last equation as
\[
y^2 + 2y + 2 \cos x + C = 0.
\]
(The new $C$ is $-2$ times the original $C$.) Using $a=1$, $b=2$ and $c =2\cos x +C$ in the quadratic formula gives us
\[
y = \left(-2 \pm \sqrt{4-8\cos x - 4C}\right)\big/2,
\]
or
\[
y = -1 \pm \sqrt{C-2\cos x}.
\]
(How was this new $C$ derived?)
This is the general solution, meaning the solution set is
\[
\left\{-1 + \sqrt{C-2\cos x} \Big| \, C\geq 2\right\} \cup \left\{-1 + -\sqrt{C-2\cos x} \Big| \, C\geq 2\right\},
\]
assuming we only want real valued solutions. 

%\vfill\pagebreak
\vspace{.2in}

{\bf Example 6. [Important for many applications.]}
Find the general solution to $\tfrac{dy}{dx} = y$.

\begin{proof}[Solution.]
  The problem can be rewritten as
  \[
\int \tfrac{1}{y} \, dy = \int \, dx.
\]
We get, $\ln |y| = x + C$. Thus, $|y|=e^{x+C} = e^C e^x$. Finally,
\[y = \pm e^C e^x = Ce^x.\]
Note: This new $C$ can be any real number besides zero. However, we observe that $y(x)=0$ is indeed a solution since, $0'=0$. Thus, $C$ can be any real number. 
  \end{proof}

%\vfill\pagebreak


\section{Initial Value Problems}

An {\em initial value problem} is a problem of the form
\[y' = F(x,y) \:\:\mbox{and}\:\:y(x_0)=y_0.\]
Again $F$ is a given function, but $x_0$ and $y_0$ are given real numbers. 
In other words, we are seeking only those solutions to $y'=F(x,y)$ that also satisfy the condition that $y(x_0)=y_0$. Some examples will help.

\vspace{.2in}

{\bf Example $\mathbf 1^{\mathbf o}$.}
Find the solution to $y'=x^3$ and $y(1)=4$.

\begin{proof}[Solution.]
  We know from Example 1 that the general solution is $y=\tfrac{x^2}{4}+C$.  Since we are given $y(1)=4$ and we see that $y(1)=\tfrac{1}{4}+C$, it must be that $C=3\tfrac{3}{4}$. Thus,
  \[
  y = \frac{x^4+15}{4}.
  \]

  This is called a {\em particular solution}.
\end{proof}


\vspace{.2in}

{\bf Example $\mathbf 5^{\mathbf o}$.}
Find the solution to $y'=\tfrac{\sin x}{y+1}$ and $y(0)=17$.

\begin{proof}[Solution.]
  We know from Example 5 that the general solution is $y=-1\pm\sqrt{C-2 \cos x}$. Thus,
  \[
  y(0) = -1 \pm \sqrt{C-2} = 17.
  \]
  We can solve for $C$. Since $\pm\sqrt{C-2}=18$ we must choose the $+\sqrt{\,}$ and discard the $-\sqrt{\,}$. Thus,
  \[
  \sqrt{C-2}=18 \:\implies\: C = 18^2 + 2 = 324+2 = 326.
  \]
  Thus,
  \[
  y=-1+\sqrt{326-2 \cos x}
  \]
  is the particular solution we require.
\end{proof}

\vspace{.2in}

\section{Two Applications (Section 1.2 of textbook)}

{\bf Example 7. [Radioactive Decay.]} Suppose substance $A$ decays in substance $B$ with rate $r>0$. This means
\[
\frac{dA}{dt} = -rA,
\]
where we are using $A(t)$ to denote the amount of substance $A$ at time $t$. We will examine and answer three problems.

(a) Find the general solution for $A(t)$. (b) If $A(0)=A_0$ find the
particular solution. (c) At what time $t$ will half of $A$ have decayed? This is called the {\em half-life} of $A$.



\begin{proof}[Solution for (a).]
  \[\int \frac{1}{A}\,dA = -\int r \,dt\]
  \[\ln |A| = -rt+C\]
  \[|A|=e^{-rt+C}= e^Ce^{-rt}\]
    \[A = \pm e^C e^{-rt}\]
    \[A= Ce^{-rt}\]
As in Example 6, this is valid for all $C$.
\end{proof}

\begin{proof}[Solution for (b).]
  \[
  A_0 = A(0)= Ce^{-r0} = C.
  \]
  This, $C=A_0$ and
  \[
  A(t) = A_0 e^{-rt},
  \]
is the particular solution.
\end{proof}

\begin{proof}[Solution for (c).]
  We merely need to solve $A(t) = A_0/2$. That is, we let
  \[
  A_0 e^{-rt} = A_0/2.
  \]
  Then $-rt = \ln \tfrac{1}{2}= -\ln 2$, so $t = \ln 2 /r$ is the half-life of substance $A$. 
  \end{proof}


\vspace{.2in}

{\bf Example 8. [Newton's Law of Cooling.]} Let $T(t)$ be the temperature of some object, like a cup of coffee, at time $t$. Let $T_a$ be the ambient temperature, that is the temperature of the surrounding or ambient environment, which we assume is constant. Then Newton's Law of Cooling states that
\[
\frac{dT}{dt} = k(T_a - T).
\]
where $k\geq 0$ is a constant. We solve for $T(t)$.

\begin{proof}[Solution.]
  \[
  \int \frac{1}{T_a - T} \, dT = \int k \, dt
  \]
  \[
  -\ln |T_a - T| = kt+C
  \]
  \[
|T_a - T| = e^{-kt-C} = Ce^{-kt} \:\:\:\mbox{(new $C>0$)}
\]
\[
T_a - T = \pm Ce^{-kt} \:\:\:\mbox{(new $C$, $C=0$ if $T=T_a$)}
\]
Thus,
\[T(t) = T_a - C e^{-kt},\]
is the general solution.
\end{proof}

\vspace{.2in}

{\bf Student Exercise.} Suppose a cup of coffee has $T(0) = 200^o$F and one minute later $T(1) = 190^o$F. Assume $T_a = 70^o$F. When will the coffee be $150^o$F? {\em Answer.} 3 minutes and 38 seconds. 

\section{Example Using CASs}

There are several computer algebra systems (CASs) that can solve differential equations. We will show how to solve
\[
y' = x^2 \cos^2 y \:\:\&\:\: y(\pi)=-1,
\]
for with several CASs.

\vspace{.2in}

{\bf Maple.} First, we use Maple. The command name is {\tt dsolve}. We will find the general solution and then the desired particular solution. The input line is

\vspace{.2in}

{\tt dsolve(diff(y(x),x)=x$\wedge$2 * cos(y(x))$\wedge$2,y(x));}

\vspace{.2in}

The output is
\[
y(x) = \arctan\left(\tfrac{1}{3}x^3 + \_C1\right)
\]
\vspace{.2in}

Here is the command format for solving the initial value problem.
\vspace{.2in}

{\tt dsolve(\{diff(y(x),x)=x$\wedge$2 * cos(y(x))$\wedge$2,y(Pi)=-1\},y(x));}

\vspace{.2in}
\[
y(x) = \arctan\left(-\tfrac{1}{3}\pi^3 +\tfrac{1}{3}x^3 -\tan(1)\right)
\]
\vspace{.2in}

If you prefer to see the answer with numbers use the command {\tt evalf}, which stands for evaluate as floating point numbers. The \% sign means use the output of the last command as the input.

\vspace{.2in}
{\tt evalf(\%);}

\vspace{.2in}
\[
y(x) = \arctan(-11.89283328+.3333333333\,x^3)
\]

Finally, we can plot the solution curve.
\vspace{.2in}

{\tt plot(arctan(-11.89283328+.3333333333*x$\wedge$3),x=1..4);}

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

\vspace{.2in}

       {\bf Question.} Suppose we had initial condition $y(\pi)=-10$. Since the range of the $\arctan$ is $(-\pi/2, \pi/2)$ it would seem that there are no solutions. But, Maple returns
       \[
       y(x) = \arctan(-(1/3)\pi^3+(1/3)x^3-\tan(10))-3\pi
       \]
       for this problem. Explain.


\vspace{.2in}
       {\bf Matlab.} Here are the commands and their outputs using Matlab.

       \vspace{.2in}
       
       {\tt dsolve($'$Dy=x$\wedge$2 * cos(y)$\wedge$2$'$,$'$x$'$)}

       {\tt atan(1/3*x$\wedge$3 + C1)}
       
       {\tt dsolve($'$Dy=x$\wedge$2 * cos(y)$\wedge$2$'$,$'$y(pi)=-1$'$,$'$x$'$)}

       {\tt atan(1/3*x$\wedge$3 - 1/3*pi$\wedge$3 - tan(1))}
       
       {\tt vpa($'$atan(1/3*x$\wedge$3-1/3*pi$\wedge$3-tan(1),5)}\\
       (vpa stands for very precise arithmetic.)
  
       {\tt atan(.33333*x$\wedge$3-11.893)}

       \vspace{.2in}

       There are several online diff eq solvers now. Find three and play with them. 

\section{Existence and Uniqueness (Theorem 2.4.2)}

For a given initial value problem when do solutions exist and when can we be sure a solution is unique?
\vspace{.2in}


{\bf Example 1.} Consider $y' = 1/x$ with $y(0)=3$. The general solution is $y=\ln|x| + C$, But $y(0)$ is undefined.

\vspace{.2in}

{\bf Example 2.} Consider $y' = y^{1/3}$ with $y(0)=0$. Then
\[
\int  y^{-1/3} \, dy = \int \, dx
\]
\[
\tfrac{3}{2} y^{\tfrac{2}{3}} = x + C
\]
Thus,
\[
y= \left(\tfrac{2}{3}x+C\right)^{\tfrac{3}{2}} = \pm \sqrt{\left(\tfrac{2}{3}x+C\right)^{3}}
\]
Then,
\[
y(0)=0 \:\implies\: \pm \sqrt{C^3} = 0 \:\implies\: C=0
\]
But, this leaves us with two solutions,
\[
y=\left(\tfrac{2}{3}x\right)^{\tfrac{3}{2}} \:\:\&\:\: y=-\left(\tfrac{2}{3}x\right)^{\tfrac{3}{2}} 
\]
Furthermore, $y(x)=0$ is also a solution!

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

\vspace{.2in}
So, in Example 1 no solution existed and in Example 2 there are three solutions that work equally well.
The next theorem gives conditions such that we are guaranteed the existence of a unique solution.

\vspace{.2in}

{\bf Theorem 2.4.2 (Picard's Theorem).} Consider $y'=f(x,y)$ with $y(x_0)=y_0$. If $f(x,y)$ and $\bd f(x,y)/\bd y$ are continuous in an open rectangle
\[
\{ (x,y)\,|\, a<x_0<b, \, c<y_0<d \}
\]
then there exists a unique function, $y(x)$, such that $y'=f(x,y)$
and $y(x_0)=y_0$. Furthermore, $y(x)$ is continuous on some open
interval $(x_0-h,x_0+h) \subset (a,b)$, where $h>0$.

\vspace{.2in}

{\bf Note.} This theorem does not tell us how to find the solution or how big $h$ can be.

\vspace{.2in}

{\bf Note on the Proof.} The proof of Theorem 2.4.2 is in Section 2.8. We do not cover it in this course, but you may read it if you wish. Feel free to ask me about it outside of class. In is covered in MATH 452. 

\vspace{.2in}

{\bf Example 1'.} Let's look back at Example 1, where $F(x,y)=1/x$. It does not even exist at $x=0$. Suppose, the initial condition was $y(1)=3$. Then $1/x$ is continuous around $x=1$ and $\bd_y F =0$ is continuous. Thus, a unique solution exists. You should be able to show that $y=\ln|x| + 3$ is the solution and it is valid for $x>0$.

\vspace{.2in}

{\bf Example 2'.} Let's look back at Example 2, where $F(x,y)=y^{1/3}$ and $y(0)=0$ were given. Of course, $y^{1/3}$ is continuous everywhere, but $\bd_y F =y^{-2/3}$ is not continuous when $y=0$. However, if we were interested in a different initial condition, say $y(0)=2$, there will be a unique solution as $y_0\neq 0$. Show that it is
\[
y(x) = \sqrt{\left(\tfrac{2}{3} x + 2\right)^3}.
\]


{\bf Example 3.} Consider $y' = F(x,y)= \frac{y^{2/5} \cdot \tan(y)}{x^2-1}$.
For which initial conditions are we guaranteed a unique solution by Theorem 2.4.2? Draw this as a set in $\R^2$.

\begin{proof}[Solution.] We see that $F(x,y)$ is undefined when $x=\pm 1$ or $y=\pi/2 + n\pi$, where $n$ ranges over the integers. Also,
  \[
  \bd_y F = \frac{\tfrac{2}{5}y^{-3/5} \cdot \tan(y) }{x^2-1} + \frac{y^{2/5} \cdot \sec^2(y)}{x^2-1}
  \]
  is not defined at $y=0$.
  Thus, an initial condition $y(x_0)=y_0$ will have a unique solution when $x\neq \pm 1$ and $y\neq 0$ or $\pi/2 + n\pi$ for any integer $n$.
  In the figure below as long as $(x_0,y_0)$ does not fall onto any of the dashed lines, $y(x_0)=y_0$ will have a unique solution.
\end{proof}

\begin{center}
\includegraphics[height=3in]{Figs/Ex242.pdf}
\end{center}  

\section{Homogeneous Equations (pages 49-50 in textbook)}

{\bf Substitutions.} Sometimes a differential equation that is not separable can be converted to one that is using an algebraic substitution.
This is basically an extension of the $u$-substation methods you learned in calculus. We will illustrate this in the case of {\bf homogeneous
equations}, which we define shortly. But, first we do an example.

{\bf Example 1.} Consider $y' = e^{\frac{y}{x}} + \tfrac{y}{x}$. It is not separable. Let $v=\frac{y}{x}$. Then $y=xv$. We regard $v$ as a function of $x$ and apply the
Product Rule to get
\[
y' = x'v +xv' = v + xv'.
\]
Thus, we have $v + xv' = e^v + v$ or $xv' = e^v$. This is separable.
We proceed. The original equation becomes,
\[ \int e^{-v} \, dv = \int \tfrac{1}{x}\, dx.\]
Thus,
\[ -e^{-v} = \ln |x| + C.\]
Solving for $v$ gives,
\[
v = \ln \left(-\ln|x| + C\right) = \ln \left(\ln|1/x| + C\right).
\]
Thus,
\[y = xv = x\ln \left(\ln|1/x| + C\right).\]
is the general solution.

\vspace{.2in}

Now, we generalize this process. Suppose $y' = F(x,y)$ and that
$F(x,y)$ can be rewritten as a function of $y/x$. That is
$F(x,y) = f(y/x)$ for some single variable function $f$.
Let $v=y/x$. Then, regrading $v$ as a function of $x$ we have

\[
v  + xv' = f(v),
\]
which is separable. This equation can be solved via
\[
\int \frac{dv}{f(v)-v} = \int \frac{1}{x},\ dx.
\]
We do the integrations, solve for $v$ in terms of $x$ and use
$y=xv$ to get the general solution.

\vspace{.2in}

{\bf Definition.} A function of two variables, $F(x,y)$, is said to be {\bf homogeneous} if $F(tx,ty) = F(x,y)$. This is equivalent to saying $F(x,y)$ depends only on the ratio of $y$ to $x$, that is $y/x$.
This gives a way to test $F(x,y)$ to see if it depends only on $y/x$.

\vspace{.2in}

{\bf Example 2.} Let $F(x,y) = \frac{x^2+3y^2}{2xy}$. Then
\[
F(tx,ty) = \frac{t^2x^2+3t^2y^2}{2t^2xy} = \frac{x^2+3y^2}{2xy} = F(x,y).
\]
Thus, $F(x,y)$ is homogeneous. It may take some effort to put $F(x,y)$
into the form $f(y/x)$. In this example,
\[
F(x,y) = \frac{1}{2} \frac{x}{y}+  \frac{3}{2} \frac{y}{x}= \frac{1}{2v}+ \frac{3v}{2}.
\]

\vspace{.2in}

{\bf Example 3.} Let $F(x,y) = \sin (xy)$. It is not homogeneous since
\[
\sin (txty) \neq \sin (xy),
\]
in general, that is for all values. For example, let $x=\pi/2$, $y=1$, and $t=2$. Then $\sin (txty) =\sin ( 2\pi)=0$,
  while $\sin (xy) = \sin(\pi/2) = 1$. Thus, this method cannot be applied to the problem $y' = \sin (xy)$.

\vspace{.2in}

{\bf Example 4.}
Let's go back to Example 2 and find the general solution to $y' = F(x,y) =  \frac{x^2+3y^2}{2xy}$.
We let $v=y/x$. Then
\[
y' = \frac{1}{2v}+ \frac{3v}{2}.
\]
Now, using $y=xv$ the Product Rule gives $y' = v + xv'$. Thus, we have
\[
v + xv' = \frac{1}{2v}+ \frac{3v}{2}.
\]
Thus,
\[
x\frac{dv}{dx} =  \frac{1}{2v}+ \frac{3v}{2} - v = \frac{1}{2v} + \frac{v}{2} = \frac{1}{2}\left(\frac{1}{v} + v\right).
\]
Now we can separate the variables and integrate.
\[
\int \frac{1}{\frac{1}{v} + v} \, dv = \int \frac{1}{2x} \, dx  = \frac{1}{2} \ln |x| + C.
\]
For the $dv$ integral, rewrite as
\[
\int \frac{v}{1+v^2} \, dv =  \frac{1}{2} \ln (1+v^2) + C,
\]
where we used the substitution $u=1+v^2$. Therefore,
\[
 \ln (1+v^2) = \ln |x| + C.
 \]
 Thus,
 \[
 1+v^2 = e^{\ln |x| + C} = |x|e^c = Cx.
 \]
Thus, 
\[
v = \pm \sqrt{Cx - 1}
\]
Finally,
\[
y = xv = \pm x  \sqrt{Cx - 1},
\]
is the general solution. Both the sign and the value of $C$ are to be determined by an initial condition.

Note 1: The equation $1+v^2 =  Cx$ implies $x$ is always positive or always negative.

Note 2: Our $C$ came from $\pm e^C$, which can never be zero. In fact, our $C$ cannot be zero, since otherwise $y$ would be imaginary.
Thus, for our general solution we should say $C\neq 0$.

Below is a computer plot of solutions for four different initial conditions. 

\begin{center}
\includegraphics[height=5in]{Figs/Ex4hom.pdf}
\end{center}  

\vspace{-2in}

This was done in Maple. The command that generated it is below.

\vspace{.2in}
    
{\tt\noindent DEplot(diff(y(x),x) = (x$\wedge$2+3*y(x)$\wedge$2)/(2*x*y(x)),\\y(x),x=-5..5,y=-5..5,

  \noindent[[y(1)=1],[y(1)=-1],[y(-1)=1],[y(-1)=-1]],\\linecolor=[red,green,blue,yellow],color=black);}

\vspace{.2in}

In fact, this generated the following error message, four times.

\vspace{.2in}

{\em Warning, plot may be incomplete, the following errors(s) were issued:
   cannot evaluate the solution further left of .49999992, probably a singularity}

\vspace{.2in}

Think about what that means.

\vspace{.2in}

\section{Linear First Order Differential Equations (2.1)}

{\bf First order linear differential equations} are differential equations that can be placed in the following form.
\[
\frac{dy}{dx} = -p(x) y + q(x) \:\:\mbox{or} \frac{dy}{dx}+p(x)y = q(x)
\]
That is $y' = F(x,y)$ is a linear function with respect to $y$, but not necessarily $x$. The solution method involves a trick. We will illustrate with an example first and then develop a general method.

\vspace{.2in}
{\bf Example 1.} Consider $y' +2y = x$. (You can check that it is not separable.) Let $\mu(x) = e^{2x}$. Multiply through by $\mu$.
\[
e^{2x} y' + 2e^{2x}y = xe^{2x}. \hspace{1in}(*)
\]
Now, watch closely. By the Product Rule
$(e^{2x}y)' = e^{2x} y' + 2e^{2x}y$. Substituting into $(*)$ gives
\[     
       (e^{2x}y)' = xe^{2x}.
\]
Thus,
\[
       e^{2x}y = \int  xe^{2x}\, dx = \tfrac{1}{2}(x-1)e^{2x} + C.
\]
(We used the Fundamental Theorem of Calculus of the left side and Integration by Parts on the right side. Integration by Parts is just the Product Rule backwards.) Hence,
\[
       y = \frac{x-1}{2} + C e^{2x}.
\]

\vspace{.2in}
       

The $\mu(x)$ is called an {\bf integrating factor}; it allowed us to integrate the equation and then solve for $y$. But, where did it come from?

To find a suitable integrating factor consider what $\mu(x)$ must \underline{do}.

We need $(\mu y)' = \mu y' + \mu p y$.

We know $(\mu y)' = \mu y' + \mu' y$.

Thus, we want $\mu' = \mu p$. But, this is a separable differential equation.

\[
\int \frac{1}{\mu} \, d\mu = \int p(x)\, dx.
\]
\[
\ln |\mu| = \int p(x)\, dx.
\]
\[
\mu = \pm e^{\int p(x)\, dx}.
\]
Since either $\pm$ works, we choose to use +. Thus,
\[
\mu(x) = e^{\int p(x)\, dx}.
\]

\vspace{.2in}

{\bf Example 2.} Solve $y' + 2xy = x$. (Note, this equation is separable. Do it that way too and compare.)

\vspace{.2in}

{\em Solution.} Let $\mu = e^{\int 2x\, dx} = e^{x^2+C}$. We let $C=0$ since we only need we one $\mu$ to work with. Now, $\mu  = e^{x^2}$. Now, we multiply the original equation by $\mu$ on both sides to get
\[
 e^{x^2}y' + 2xe^{x^2}y = xe^{x^2}.
\]
Thus,
\[
 (e^{x^2}y)'  = xe^{x^2}.
\]
Now we integrate.
\[
e^{x^2}y = \int xe^{x^2} \, dx = \tfrac{1}{2}e^{x^2} + C.
\]
Finally, we solve for $y$ to get,
\[
y = \tfrac{1}{2} + Ce^{-x^2}.
\]

\vspace{.2in}

{\bf Example 3.} Solve $y' + \frac{y}{x} = 3.$

\vspace{.2in}

{\em Solution.}
Then $\mu = \pm e^{\int \frac{1}{x} dx} = \pm e^{\ln|x|+C} = \pm e^C|x| =Cx$. We can choose $C=1$. [We are just finding a solution to $\mu'/\mu = 1/x$, so clearly $\mu=x$ works.]

Now we multiply both sides of $y' + \frac{y}{x} = 3$ by $\mu=x$ to get
\[
xy' + y = 3x.
\]
By the Product Rule (backwards) we have
\[
(xy)'= 3x.
\]
Thus,
\[
xy = \tfrac{3x^2}{2}+C.
\]
The general solution is then
\[
y = \tfrac{3}{2}x + \tfrac{C}{x}.
\]
\vspace{.2in}

{\bf Example 4.} Solve $xy' + 2y = -\sin x,$ with $y\left(\frac{\pi}{2}\right) = 4$.


\vspace{.2in}
{\em Solution.}
First, we divide through by $x$ so that we have a linear type problem.
\[
y' + \tfrac{2}{x}y = -\tfrac{1}{x}\sin x.
\]
Let $\mu = e^{\int\frac{2}{x} dx} = e^{2\ln|x|} = e^{\ln x^2} = x^2$.
Multiply through by $\mu = x^2$ to get
\[
x^2y' + 2xy = -x\sin x.
\]
Thus,
\[
(x^2y)' = - x \sin x.
\]
Integration gives
\[
x^2y = -\int x \sin x \, dx = x\cos x -\sin x + C.
\]
Thus, the general solution is
\[
y = \frac{x\cos x -\sin x + C}{x^2}.
\]
\vspace{.2in}
Now, set $y(\pi/2) = 4$ and solve for $C$.
\[
4= \frac{\frac{\pi}{2}\cos \frac{\pi}{2} -\sin \frac{\pi}{2} + C}{(\pi/2)^2}
\]
Since $\cos \frac{\pi}{2} =0$ and $\sin \frac{\pi}{2}=1$ we find that
\[
C= 1+\pi^2.
\]
Thus,
\[
y=\frac{x\cos x -\sin x + 1+\pi^2}{x^2}
\]
is the particular solution to this initial value problem.

\vspace{.2in}

{\bf Example 5.} Solve $y' -2xy=4$ with $y(0)=3$. Estimate $y(1)$.
\vspace{.2in}

{\em Solution.} This is linear. Let $\mu = e^{-\int2x\,dx} = e^{-x^2}$. Multiplying through gives
\[
e^{-x^2}y' - 2 xe^{-x^2}y =4e^{-x^2}.
\]
Thus,
\[
\left(e^{-x^2}y\right)' = 4e^{-x^2}.
\]
Thus,
\[
e^{-x^2}y = 4 \int e^{-x^2} \, dx.
\]
The integral of $e^{-x^2}$ cannot be done in closed form. The best we can do is to write
\[
y(x) = \frac{4\int_0^x e^{-t^2} dt + C}{e^{-x^2}}.
\]
We use $y(0) = 3$ to find $C$.
\[
3 = \frac{4\int_0^0 e^{-t^2} dt + C}{e^{-0^2}} = C.
\]
Thus, $C=3$.
So, our particular solution to this initial value problem is
\[
y(x) = \frac{4\int_0^x e^{-t^2} dt + 3}{e^{-x^2}}.
\]
\vspace{.2in}
To estimate $y(1)$ we will use numerical integration.
I used this command in Maple 17.

\vspace{.2in}

$>$ {\tt int(exp(-t$\wedge$2),t=0..1);}

\vspace{.2in}

The output was $\frac{1}{2}\mbox{erf}(1)\sqrt{\pi}$. Since I did not specify numerical integration the result is not that helpful. The function {\tt erf} stands for {\em error function} is is just defined to be
$2\sqrt{\pi}$ times our integral. Next I'll specify to do the integration numerically.

\vspace{.2in}

$>$ {\tt int(exp(-t$\wedge$2),t=0..1,numeric=true);}

\vspace{.2in}

The result is 0.7468241328. We now get
\[
y(1) = \frac{4\int_0^1 e^{-t^2} dt + 3}{e^{-1}} \approx 16.27515936.
\]

\vspace{.2in}

\section{Existence and Uniqueness (Theorem 2.4.1)}

Theorem 2.4.2, discussed above, takes a particularly simply form when applied to first order linear differential equations.
Consider
\[
y' + p(x) y = g(x) \:\:\:\&\:\:\: y(x_o) = y_o.\hspace{1in}(*)
\]
Let $f(x,y) = -p(x)y + g(x)$. Then $\bd_y f = -p(x)$. Thus, $f$ and $\bd_y f$ are continuous exactly when $p$ and $g$ are continuous.
Hence, $(*)$ has a unique solution whenever there is an open interval $(a,b)$ that contains $x_o$ on which $p$ and $g$ are continuous.
Furthermore, it can be shown that the solution exist and is continuous on all of $(a,b)$. See Theorem 2.4.1. in Section 2.4 for details.

\vspace{.2in}

{\bf Example 1.} Consider $y' + \frac{y}{x-3} = \frac{1}{x}$. It will have a unique solution for $y(x_o)=y_o$ as long as $x_o$ is not 0 or 3.

\noindent If $x_o = 1$ the solution will be valid on $(0,3)$.\\
If $x_0 = 5$ the solution will be valid on $(3,\infty)$.\\
If $x_0 = -\pi$ the solution will be valid on $(-\infty,0)$.\\

\vspace{.2in}

{\bf Example 2.} Consider $y' + y \cot x = x^3$ with $y(1)=77$. On what interval will the solution be valid? 

\vspace{.2in}

{\em Solution.} $\cot x$ is continuous except when $x= 0, \pm \pi, \pm 2\pi, \dots$. Notice that $1 \in (0,\pi)$. Thus,
the solution $y(x)$ exists and is continuous on $(0, \pi)$.

\vspace{.2in}

\section{Example with Jump Discontinuity}

We wish to find a continuous function $y(t)$ that satisfies the initial value problem
\[
y' +2y = g(t) \:\:\:\&\:\:\: y(0)=0,
\]
where
\[
g(t) = \left\{\begin{array}{ccl}0 &\mbox{for}& t<0,\\1 & \mbox{for}& 0\leq t < 1,\\0 &\mbox{for} & t\geq 1.\end{array}\right.
\]
Perhaps $g(t)$ is controlled by a switch and can be on or off.

\vspace{.2in}

{\em Solution.} Step 1. We find the general solution for $t<0$. We have $y' + 2y=0$. Thus, $y(t) = Ce^{-2t}$. Now, to have the final result be continuous and $y(0)=0$, we need $\dis \lim{t\to 0^-} y(t) = 0$. Since $\dis \lim{t\to 0^-}Ce^{-2t} = C$, it must be that $C=0$.

Step 2. We find the general solution for  $0< t < 1$. We have $y' + 2y =1$. This is linear. Let $\mu = e^{2t}$. Then
\[
e^{2t}y' + 2e^{2t}y = e^{2t}.
\]
Thus,
\[
\left(e^{2t}y\right)' =  e^{2t}.
\]
Integration gives
\[
e^{2t}y = \frac{ e^{2t}}{2} + C.
\]
Thus,
\[
y = \tfrac{1}{2} + C e^{-2t}.
\]
The condition that $y(0)=0$ implies $C=-\frac{1}{2}$. Thus,
\[
y(t) = \frac{1-e^{-2t}}{2},
\]
for $0<t<1$.

Step 3. For $t>1$ we have $y'+2y=0$. Thus, $y=Ce^{-2t}$. For the final solution to be continuous we require this $y(t)$ match the previous $y(t)$ at $t=1$.
(Technically, we are matching limits as $t$ goes to 1 from the left and right.)
\[
\frac{1-e^{-2}}{2} = Ce^{-2}.
  \]
  It follows that this $C$ is $\frac{e^2-1}{2}\approx 3.4$.

Step 4. We write out the complete solution and plot it.

  \[
  y(t) = \left\{ \begin{array}{ccl} 0 & \mbox{for} & t<0,\\ \frac{1-e^{-2t}}{2}  & \mbox{for} & 0 \leq t < 1,\\\frac{e^2-1}{2}e^{-2t} & \mbox{for} & t\geq 1.\end{array}\right.
  \]

\begin{center}\vspace*{-1in}
\includegraphics[width=5in]{Figs/JumpExample.pdf}
\end{center}

\vspace{-4in}
Perhaps there was a leak of a radio active substance from $0\leq t \leq 1$.




\section{Bernoulli Equations (page 77)}

Bernoulli Equations are equations of the form

\[
y' + p(x)y = g(x)y^n.
\]

The substitution $v = y^{1-n}$ will convert them into linear equations. 

\vspace{.2in}

{\bf Example 1.} Find the general solution to $y' + 2y = y^4$. (This is separable, but the integration is hard.)

\vspace{.2in}

{\em Solution.} Let $v = y^{-3}$. Then $y = v^{-1/3}$ and by the Chain Rule
\[
y' = -\tfrac{1}{3}v^{-4/3} v'
\]
Thus, the original equation becomes
\[
-\tfrac{1}{3}v^{-4/3} v' +2 v^{-1/3} = v^{-4/3}.
\]
Well, that does not look very promising, but multiply through by $-3v^{4/3}$ to get
\[
v' -6v = -3.
\]
This is linear in $v$. You should be able to show that $v=\tfrac{1}{2} + C e^{-6x}$ is the general solution. Thus,
\[ y(x) = \left(\tfrac{1}{2} + C e^{-6x}\right)^{-1/3},\]
is the general solution to the original problem.

\vspace{.2in}

{\bf Example 2.} Find the general solution to $t^2y'+ 2ty-y^3 = 0$. Assume $t>0$. (Here $y$ is a function of $t$ instead of $x$.)

\vspace{.2in}

{\em Solution.}
We can divide through by $t^2$ and convert the problem to
\[
y' + \tfrac{2}{t}y = \tfrac{1}{t^2} y^3,
\]
which is in the form of a Bernoulli Equation with $n=3$. Let $v = y^{-2}$. Then $y = v^{-1/2}$ and $y' = -\tfrac{1}{2}v^{-3/2} v'$.
Thus, the original equation becomes
\[
-\tfrac{1}{2}v^{-3/2} v'  + \tfrac{2}{t}  v^{-1/2} = \tfrac{1}{t^2} v^{-3/2}.
\]
Hence,
\[
v' -  \tfrac{4}{t}v = -\tfrac{2}{t^2},
\]
which is linear. Check that $\mu = t^{-4}$.
This gives
\[
t^{-4} v' - 4t^{-5}v = -2 t^{-6}.
\]
Hence,
\[
t^{-4}v = -2 \int t^{-6} \, dt = \tfrac{2}{5}t^{-5} +C.
\]
Thus,
\[
v =\tfrac{2}{5}t^{-1} +Ct^{-4}.
\]
Finally,
\[
y = v^{-1/2} = \frac{\pm1}{\sqrt{\tfrac{2}{5}t^{-1} +Ct^{-4}}} = \frac{\pm t^2}{\sqrt{\tfrac{2}{5}t^3 + C}}.
\]

\vspace{.4in}

Now that we have done a couple of examples, let's check that this method does work in general. We are given
\[
y' +p(x)y = g(x)y^n.
\]
Let $v=y^{1-n}$. Then $y= v^{\frac{1}{1-n}}$ and
\[
y' = \tfrac{1}{1-n}v^{\frac{1}{1-n} -1} v' =  \tfrac{1}{1-n}v^{\frac{n}{1-n}} v'.
\]
The original equation becomes
\[
\tfrac{1}{1-n}v^{\frac{n}{1-n}} v' + p(x)v^{\frac{1}{1-n}} = g(x)v^{\frac{n}{1-n}}.
\]
Multiply through by $(1-n)v^{\frac{-n}{1-n}}$ to get
\[
v' + (1-n)p(x)v = (1-n)g(x),
\]
which is linear in $v$. Solve it for $v(x)$, then find $y(x)$. 


\vspace{.2in}

\section{Analysis of Solutions: Slope Fields (1.1)} 

We shall study slope fields and direction fields. Given a differential
equation of the form
\[
\frac{dy}{dx} = f(x,y)
\]
and a chosen grid of points in the $xy$-plane we can compute the slope $y'$ at each grid point and then put a small line segment whose slope matches the slope we found. This allows use to see how solutions behave without actually solving the equation for $y(x)$. We have actually seen computer plots of this already. 

\vspace{.2in}

{\bf Example 1.} Consider $\dis y' = f(x,y)=\frac{x+y}{3}$. This is pretty easy to solve but here we will just study the slope field. We will use an grid with $x$ and $y$ taking on all integer values between $-4$ and $4$.  For example at the origin $y' = f(0,0) = 0$. We make a table of slope values.
\[
f(-4,4) = 0, f(-4,3) = 1/3, f(-4,2) = 2/3, \mbox{etc.}
\]
At each grid point we place a small line segment with the given slope. We normally use a computer for this, but it is good to do a couple of examples by hand to get a feel for what is going on. We can use the slope field to sketch rough solution curves.
See below. Notice if $y=-x-3$, then $y' = -1$. Since $y=-x-3$ itself has slope $-1$ it should be a solution. Check this.


%\begin{center}
%\vspace*{-1in}
\hspace*{2in}\includegraphics[width=3in]{Figs/splorefieldbyhand.png}
%\end{center}


\vspace*{-0.5in}
Below is a command in Maple to create the same slope field, except it used a finer default grid. Three solution curves are also shown.

\vspace{.2in}
{\tt> DEplot(diff(y(x),x) = (x+y(x))/3,y(x),x=-4..4,y=-4..4,color=black,}\\{\tt arrows=line,[[y(0)=0],[y(0)=-3],[y(-4)=3]],linecolor=red);}

\vspace{-1in}
\begin{center}
  \includegraphics[height=6in]{Figs/SlopeFieldExample.pdf}
\end{center}
\vspace{-3in}

Next we did the slope field using GeoGebra. You can use your cursor to move the solution curve as you wish.  See the link:\\
{\tt https://www.geogebra.org/m/W7dAdgqc}


\begin{center}
  \includegraphics[height=3in]{Figs/slopefieldgeogebra.png}
\end{center}
\vspace{.2in}

  Here is the same slope field using WolframAlpha.
  The link is \\
  {\tt https://www.wolframalpha.com/input?i=slope+field+y\%27+\%3D+\%28x\%2By\%29\%2F3\%2C+}\\{\tt-4\%3Cx\%3C4\%2C+-4\%3Cy\%3C4}

  \begin{center}
   \includegraphics[height=3in]{Figs/slopefieldWolframAlpha.png}
  \end{center}

  Finally, here is code for doing a different {\em direction field} in {\tt matlab} for the equation $y' =2x-y$. Note: a direction field is the same as a slope field, but you have arrows instead of line segments. The arrows give the direction of solution curve as $x$ increases. (Think of $x$ as time.)

 \begin{center}
   \includegraphics[height=2in]{Figs/slopefieldmatlabcode.png}
 \end{center}
 
 \begin{center}
   \includegraphics[height=3in]{Figs/slopefieldmatlab.png}
  \end{center}

  
We will do several examples in class. On tests I often have a matching problem with a list of equations and a series of slope fields. 
}



\end{document}
