# Chapter 2: First-order differential equations

The purpose of this first lecture is to get us started as quickly as possible in solving differential equations. We will first learn about how ODEs are classified, and then we learn the two principal methods of solving first-order ODEs: separation of variables and integrating factors. Lastly, we will see how differential equations can be studied visually.

## Terminology

Now that we have a general understanding of how the subject of differential equations was developed over the past three hundred years, let us begin our study of ODEs by introducing the terminology.

Definition (Ordinary differential equation): An $n^\text{th}$ order ordinary differential equation is an equation relating a function, say $y(x)$, and $n$ of its first derivatives: $G\Bigl( x, y, y', y'', y''', \ldots, y^{(n)} \Bigr) = 0.$

As it concerns us, a most important distinction is between linear and nonlinear ODEs. We shall define Definition (Inhomogeneous ODE) An $n^\text{th}$ order inhomogeneous linear ODE is one of the form $a_n(x) \frac{d^n y}{dx^n} + a_{n-1}(x) \frac{d^{n-1} y}{dx^{n-1}} + \ldots + a_1(x) \frac{dy}{dx} + a_0(x)y = f(x).$

where $a_n$ is not identically zero. This equation is called homogeneous if $f(x) \equiv 0$. If all the coefficients, $a_i(x)$ are independent of $x$, then we call the equation a constant coefficient ODE.

Notice that in the definition of a linear equation, there is no requirement on the form of the coefficients, $a_i(x)$. The linearity simply requires linearity in the function $y$ and its derivatives. An example of a nonlinear ODE is $\frac{dy}{dt} = y^2.$

Consider now the simple example of tracking the location of a ball thrown in the air. Ignoring air resistance, and letting the height of the ball be $h(t)$ at time $t$, then we have from Newton's law $$\label{eq:first_grav} \frac{d^2 h}{dt^2} = -g,$$

where $g \approx 9.81 \text{m}/\text{s}^2$. To solve, we integrate the equation twice, and this gives $h(t) = - \frac{1}{2} gt^2 + C_1 t + C_2,$

for unknown constants, $C_1$ and $C_2$. This is a general solution of the differential equation (\ref{eq:first_grav}). We remark that we may think of an $n^\text{th}$ order ODE as requiring $n$ integrations, and thus $n$ constants of integration. Do $n^\text{th}$ order ODEs then require $n$ initial conditions or boundary conditions? The answer is yes' (in most simple cases), but there are also many cases where more or fewer than $n$ conditions are necessary.

In order to obtain a particular solution to the above problem, we must also specify two initial conditions, say, the initial location and velocity of the ball. Let us suppose that $$h(0) = 2 \quad \text{and} \quad h'(0) = 4.$$

Applying these two conditions allow us to solve for the particular solution: $$\label{eq:first_gravinit} h(t) = -\frac{1}{2} gt^2 + 4t + 2.$$

Together, the ODE (\ref{eq:first_grav}) and its initial conditions (\ref{eq:first_gravinit}) form an initial value problem (or IVP). Instead of specifying conditions at $t = 0$, we could ask for a solution which satisfies $$\label{eq:first_gravbound} h(0) = 2 \quad \text{and} \quad h(1) = 3,$$

which gives $$h(t) = -\frac{1}{2} gt^2 + \left(1 + \frac{g}{2}\right)t + 2.$$

The conditions (\ref{eq:first_gravbound}) are called boundary conditions and together with the ODE, they make a boundary value problem (BVP).

There is no general methodology which can solve arbitrary nonlinear first-order ODEs, and even linear first-order ODEs can present many challenges. However, there are methods which are applicable to classes of such equations. The below table summarizes some of the well-known classes of first-order equations. The first two methods are covered in the lecture, and you will explore some of the others in the problem set.

Name Equation Method
Separable equation $y' = X(x) Y(y)$ Separation of variables
Linear inhomogeneous $y' + P(x) y = Q(x)$ Integrating factors
Exact equation $M(x,y) + N(x,y) y' = 0$
with $\partial N/\partial y = \partial M/\partial x$
Find a function $\Psi(x,y)$ such that $\partial \Psi/\partial x = M$ and $\partial \Psi/\partial y = M$
Bernoulli equation $y' + p(x)y = q(x) y^n$ Substitute $v = y^{n-1}$
Homogeneous equation $y' = f(x/y)$ Substitute $v = x/y$
Ricatti equation $y' = f(x)$
\phantom{y'=f(x) \, \,} $+ \, g(x)y + h(x)y^2$
Transform to linear second-order ODE
Clairaut equation $y = xy' + f(y')$ Possesses both a general solution and a singular solution.

## Direction fields for first-order ODEs

Remember that the first order differential equation $$\label{eq:first_genfirst} \frac{dy}{dx} = f(x,y)$$

gives a prescription for the slope of the solution at any point $(x,y)$ in the plane. What we can do, then, is for each point in a section of the plane, we draw a small vector whose slope is $f(x,y)$. Then any solution passing through $(x,y)$ must be tangent to the vector.

### Example of a direction field

Consider the direction field of $$\label{eq:first_directeq1} \frac{dy}{dx} = x - y,$$

subject to the initial condition $y(-2) = 2$. The direction field is shown below. There is in fact a critical solution, with $y = x - 1$, and all the trajectories approach this solution as $x \to \infty$. The direction field for (\ref{eq:first_directeq1}) is created by drawing a small vector at a grid of points in the $(x,y)$ plane. Solutions (trajectories) should then run tangential to these vectors. The solution which begins at $y(-2) = 2$ moves along the solid black line, and approaches $y = x - 1$ as $x \to \infty$.

### Example of a direction field$^2$

Consider the direction field of $$\label{eq:first_directeq2} \frac{dy}{dx} = \frac{-x}{y+1},$$

subject to the initial condition $y(-1.5^-) = -1^-$ (that is, as $x$ tends to $-1.5$ from the left, $y$ tends to $-1$ from below). The direction field is shown below. We see that the solutions form circular trajectories which end abruptly as they approach the line $y = -1$. This is not surprising as the magnitude of the slope, $dy/dx$, tends to infinity as $y \to -1$; our solutions contain vertical tangents and are no longer functions at this point.

## Separable equations

We now introduce an important technique which allows us to solve a special type of nonlinear first-order equations of the form (\ref{eq:first_genfirst}). A special class of such equations contains those of the form $$\label{eq:first_sepform} \frac{dy}{dx} = X(x)Y(y),$$

which we call separable equations. These are easily solved by re-arranging (\ref{eq:first_sepform}) and integrating with respect to $x$: $$\int \frac{1}{Y(y)} \frac{dy}{dx} \, dx = \int X(x) \, dx,$$

which, by the chain rule simply gives $$\label{eq:first_sep} \int \frac{dy}{Y(y)} = \int X(x) \, dx.$$

Occasionally, students are taught to simply separate the differentials $dx$ and $dy$, and writing $$\label{eq:first_sepbad} \frac{dy}{Y(y)} = X(x) \, dx,$$

in the intermediary step before integrating. But remember: $dy/dx$ only exists as a limiting value, valid as the approximating differentials, $\delta x, \delta y \to 0$. Equation (\ref{eq:first_sepbad}) then tells us that $0 = 0$, which is inconsequential. In practice, however, everyone' writes (\ref{eq:first_sepbad}) in the intermediary, and there is generally no harm if you treat the differentials as separable. Nevertheless, you should be aware of the rigor-be-damned nature of separating differentials.

### Example of separation of variables

Let us return to Example \ref{ex:first_direct2} and solve the differential equation (\ref{eq:first_directeq2}) using separation of variables. Separating and integrating, we have $\int (y+1) \, dy = -\int x \, dx \qquad \Rightarrow \qquad x^2 + (y+1)^2 = C^2,$

for some constant, $C$. Thus, the general solution is simply a circle of radius $C$, centered at $(0, -1)$. For the initial condition of $y(-1.5) = -1$, the solution is simply $x^2 + (y+1)^2 = 1.5^2$. \end{example}

### Example of exponential growth and decay

In many examples from science, the rate of change of a variable is proportional to the variable itself. We could write this as an ODE of the form $\frac{dy}{dt} = ky,$

where $k$ is a constant. Assuming that $y \neq 0$, we separate and integrate, giving $\int \frac{dy}{y} = k\int dt \Rightarrow \log |y| = kt + C,$

for some constant $C$. Solving now for $y$ gives $y = \pm e^C e^t = A e^t,$

where $A$ is any constant. Notice that we have absorbed the $\pm$ signs into the new constant, $A$, and also that the special case of $y = 0$ is already included when $A = 0$.

### Example

Consider the equation $$\label{eq:first_eye} \frac{dy}{dx} = \frac{x^2}{1-y^2}.$$

We separate and integrate to give $\int (1-y^2) \, dy = \int x^2 \, dx$

or simply $y^3 + x^3 - 3y = C.$

It is not very easy to solve for $y$, so we have gone as far as we can. For a given initial condition, $C$ can then be solved. We can produce a stream plot in Mathematica using the command

StreamPlot[{1, x^2/(1 - y^2)}, {x, -2, 2}, {y, -2, 2}

A stream plot is essentially a vector plot in which the vectors are interpolated and the trajectories rendered more clearly. It is shown below. We see that the solution fails to exist along $y = \pm 1$. Note also the fixed points at $x = 0$ and $y = \pm 1$.

## Linear equations with variable coefficients

Linear ODEs form the most important class of equations in this course, and this is primarily for two reasons (i) they occur in a great number of physical settings, and (ii) they are easier to solve than nonlinear equations. In fact, as you go deeper into this course, you'll soon discover that most of the ways we have for studying nonlinear equations is to `make' them linear.

A first order homogeneous linear differential equation of the form $P(x) \frac{dy}{dx} + Q(x) = 0,$

can be easily solved using separation of variables. The challenge is now to solve the inhomogeneous equation $$\label{eq:first_inhom} P(x) \frac{dy}{dx} + Q(x) = R(x),$$

and this can be done using integrating factors.

### Example of integrating factors

Consider solving the differential equation $xy' + y = x.$ Written in this way, the solution is not easily spotted. However, let us combine the left-hand side $(xy)' = x.$ Now we may simply integrate both sides and solve for $y$ $y = \frac{1}{2} x + \frac{C}{x}.$

The previous example was set up so that the homogeneous portion of the differential equation was expressed as a derivative of a product. In order for us to use the same trick for (\ref{eq:first_inhom}), we would need $P(x) y' + Q(x) y = (A(x) y)',$

and this is certainly not true in general. The idea behind integrating factors is to multiply the differential equation by a factor, $I(x)$, so that the LHS becomes a complete derivative. Then we simply need to integrate both sides.

### Example of integrating factors$^2$

Let us return to Example \ref{ex:first_direct1} and solve the differential equation (\ref{eq:first_directeq1}) using integrating factors. We need to multiply the equation by a factor such that the left-hand side of $y' + y = x$ becomes a single derivative. Let us try $I(x) = e^{x}$. Then we have $e^x y' + e^x y = xe^x \Rightarrow (e^x y)' = xe^x.$

Integrating both sides and solving for $y$ gives $e^x y = \int xe^x \, dx + C \Rightarrow y = x - 1 + Ce^{-x}.$

for some constant, $C$. We can see that indeed, as concluded earlier from the direction field analysis, as $x \to \infty$, the solution tends to $y = x - 1$.

### Example of integrating factors$^3$

Consider $y' + 2y = 3.$

We need to multiply the equation by a factor such that the left-hand side becomes a single derivative. Let us try $I(x) = e^{2t}$. Then we have $e^{2t} y' + 2e^{2t} y = 3e^{2t} \Rightarrow \frac{d}{dx}\left(e^{2t}y \right) = 3e^{2t}.$

We now integrate, and solve $y = \frac{3}{2} + Ce^{2t}.$

When using the trick of integrating factors, it is valuable to always think of the integrating factor as $e$ raised to some power—for which you now need to find the power!

### Example of integrating factors$^4$

Solve the IVP $$\label{eq:first_dawson} \frac{dy}{dx} + 2xy = 1, \qquad y(0) = 0.$$

We multiply left and right sides by $e$ to some power: $e^{( \ldots )} \frac{dy}{dx} + 2x e^{( \ldots )} y = e^{( \ldots )},$

and you should be able to see that the integrating factor should be $I(x) = e^{x^2}$. Thus we have $\frac{d}{dx} \left( e^{x^2} y \right) = e^{x^2}$

The initial condition is given at $x = 0$, so we will integrate both sides $e^{x^2}y - e^{0}y(0) = \int_0^x e^{t^2} \, dt,$

and so $y(x) = e^{-x^2}\int_0^x e^{t^2} \, dt.$

The integral can not be reduced any further. In the below figure, the exact solution which satisfies the initial condition $y(0) = 0$ is shown in bold.

Once you have understood the basic trick of integrating factors, then a formula for the general solution of any linear inhomogeneous first-order ODE (\ref{eq:first_inhom}) can be written down in terms of integrals. Subject to the evaluation of these integrals (which may be nontrivial!), this puts away the problem for good. You will derive this formula in your problem set, but it is better to understood the methodology, rather than to memorize the formula.