# First-order ODEs

## Contents

# First-order ODEs#

Mathematics Methods 1 Mathematics Methods 2

ODEs of first order contain only the first derivative \(y'\), so they take the form

or often

where \(y\) is the dependent variable and \(x\) is the independent variable and \(f\) is any function of them. The ODE in eq. (111) is written in *implicit* form, while it is written *explicitly* in eq. (112).

## Direction field#

```
import numpy as np
import matplotlib.pyplpot as plt
```

## Direct integration#

The basic technique in solving differential equations is integration. We can directly integrate an ODE of the form

## Separation of variables#

If we can reduce an ODE through algebraic manipulations to the form

we call it a **separable** equation. If \(h(u) = 0\) then the solution is \(u =\) const. If \(h(y) \neq 0\) we can divide through by it and integrate with respect to \(x\):

to find the general solution.

**Example 2.** Let us find the general solution of

This is a separable equation … integrate both sides w.r.t. \(x\):

Example: \(y' + ky = 0, \quad k \in \mathbb{R}\)

Consider a simple, but very important, ODE \(y' = -ky\), where \(k\) is a constant. The question we need to be asking ourselves is “*what function when differentiated is equal to itself times some \(-k\)?*” The answer is the exponential function

With practice this type of questions and the answers to them will come more naturally. If an answer is not obvious (and most often it will not be), you could try solving it using some method. Let us do that:

## Reduction to separable form#

## Exact ODEs#

If a function \(u(x, y)\) has continuous partial derivatives, its **differential** (also called its *total differential*) is

From here it follows that if \(u(x, y) =\) const, then \(du = 0\).

A first-order ODE \(M(x, y) + N(x, y)y' = 0\), written as

is called an **exact differential equation** if the differential form \(M(x, y) dx + N(x, y) dy\) is **exact**, that is, this form is the differential

of some function \(u(x, y)\). Then (1) can be written

By integration we immediately obtain the general solution of (1) in the form

This is called an **implicit solution**

Comparing (1) and (2), we see that (1) is an exact differential equation if there is some function \(u(x, y)\) such that

Necessary and sufficient condition for (1) to be an exact differential equation

If (1) is exact, the function \(u(x, y)\) can be found by inspection or in the following systematic way. From 4a we have by integration w.r.t. x

where \(k(y)\) is the “constant” of integration. To determine \(k(y)\), we derive \(\partial u / \partial y\) from (6), use (4b) to get \(dk/dy\), and integrate \(dk/dy\) to get \(k\).

Could have done the same with 4b to get

Physical interpretation: conservative force

Recall that a force \(\mathbf{F}\) is conservative if the work done while moving between two points is independent of the path taken. Then it can be expressed as a gradient of potential \(\mathbf{F} = \nabla \Phi = (\Phi_x, \Phi_y)\).

Consider a force field \(\mathbf{F} = (P, Q)\) along an infinitesimal path \(\mathbf{dr} = (dx, dy)\)

The exactness condition is

which is satisfied. Therefore, the exactness of a differential equation can be identified with physical systems in which there is a potential.

### Reduction to exact form. Integrating factors#

Nonexact equation

multiply by a function F that will in general be a function of both x and y

which is exact. F(x, y) is then called an **integrating factor** of that equation.

HOW TO FIND INT FACTORS

In simpler cases it may be found by inspection. In general:

The exactness condition \(\partial M / \partial y = \partial N / \partial x\), so for \(FP dx + FQ dy = 0\) the exactness condition is

In general this would be difficult to solve, so we try a simpler case. In many practical cases there are factors that depend only on one variable. We let \(F = F(x)\) so the above becomes

This proves the following theorem: If (12) is such that the right side R of 16 depends only on x, then (12) has an integrating factor F = F(x) which is obtained by integrating 16 and taking exponents on both sides

Similarly, if F* = F*(y), then instead of 16

and

## First order linear differential equation#

A general first-order linear ODE is of the form

In engineering r(x) is often called the input and y(x) the output of the response to the input (and, if given, to the initial condition)

We find the solution to the homogeneous equation \(u_h(x)\) and then one particular solution \(u_p(x)\) to obtain the complete solution \(u\). The corresponding homogeneous equation

is separable, so the solution can be found by **separation of parameters**

and integrating from \(x_0\) to \(x\)

where \(s\) is a dummy variable that we use so to not confuse the integration variable with the upper integration limit \(x\). The reason why we are integrating from \(x_0\) to \(x\) will become clear very soon.

We find the particular solution by **variation of parameters** where \(C\) is no longer a constant but a function of \(x\):

We plug this back into the original equation and solve for \(C(x)\)

The solution to the inhomogeneous problem is

where \(C = u(x_0)\) because for \(x=x_0\) all integrals are \(0\); this is why we integrated from \(x_0\) but, of course, we did not have to. If we did not, only the constant would be different. Rewriting this in a more convenient way

**Note.** We can rewrite the above as

After differentiating both sides we get

We see that \(e^{\int_{x_0}^x p(s) ds}\) is the **integrating factor** so we could have found the solution by multiplying both sides of the equation by it.

Example: \(xy' + 4y = 8x^4, \quad y(1) = 2\)

(Kreyszig PS 1.5, Q7)

We divide both sides by \(x\) to get standard form:

Now we see that \(p(x) = \frac{4}{x}, r(x) = 8x^3\) and the condition \(y(x_0) = y(1) = 2\). We first calculate \(h\)

Plug this into our solution