# First order differential equations

## Linear DE

The linear DE of first order can be described as

$$a_1(x)\ y' + a_0(x)\ y = g(x).$$

That means both $y,\ y'$ are involved with coefficients, which are either constant or are a function of $x$.

Note: DE e.g.

\begin{align} y' + \sin y &= g(x) \hskip1em \text{or} \nonumber \\ (y')^2 + y &= g(x) \nonumber \end{align}

are not linear DE.

We will rather work with linear DE in the standard form

$$\begin{equation} \color{red}{\frac{dy}{dx}+P(x)\cdot y = f(x)}. \label{ref:linea1_1} \end{equation}$$

In some cases the DE above, which is linear, can be solved also by separating variables. General method to solve linear DE involves a special function $\mu(x)$. As for now, do not think where this function comes from. If we use such special function $\boldsymbol{\mu(x)}$ to multiply DE, it will help us to bring the solution. So let us multiply $(\ref{ref:linea1_1})$ by $\mu(x)$ to derive the principle:

$$\begin{equation} \color{blue}{\mu(x)\frac{dy}{dx}+{\mu(x) P(x)}\cdot y} = \mu(x) f(x) \label{ref:linea1_2} \end{equation}$$

Now it is important to pay attention to the left side of $(\ref{ref:linea1_2})$. Because it will be shown that after multiplying both sides of DE by $\boldsymbol{\mu(x)}$, on the left side of DE is being left $\boldsymbol{\mu(x) y}$ differentiated with respect to $\boldsymbol{x}$. Let us differentiate $\mu(x)y$:

$$\begin{equation} \frac{d}{dx}\mu(x)\ y = \color{blue}{\mu(x)\frac{dy}{dx} + {\frac{d\mu}{dx}}y} \label{ref:linea1_2a} \end{equation}$$

By $(\ref{ref:linea1_2a})$ it was shown that $\frac{d}{dx}\mu(x) y$ is on the left side of $(\ref{ref:linea1_2})$ supposing

$$\begin{equation} \frac{d\mu}{dx} = \mu(x) P(x) \label{ref:linea1_3} \end{equation}$$

The DE $(\ref{ref:linea1_3})$ above can be solved by separating variables and will answer the question where does the function $\mu(x)$ come from.

\begin{align} \frac{1}{\mu(x)}d \mu &= P(x)\ dx \nonumber \\ \log |\mu(x)| &= \int P(x)\ dx + c_1 \nonumber \\ \mu(x) &= c_2 e^{\int P(x)\ dx} \nonumber \end{align}

It can be shown that the value of the constant has no effect on solution of linear DE. So, we may put $c_2 = 1$:

$$\begin{equation} \color{red}{\mu(x) = e^{\int P(x)\ dx}}. \label{ref:linea1_4} \end{equation}$$

Since we have identified $\mu(x)$ as $e^{\int P(x)\ dx}$, let us use $\mu(x)$ again to multiply the DE $(\ref{ref:linea1_1})$. Because it will be shown, that after multiplying, the DE is readily solved. Let us bring back DE in standard form and multiply by integrating factor:

\begin{align} \frac{dy}{dx}+P(x)\cdot y &= f(x) \hskip4em / \cdot e^{\int P(x)\ dx} \nonumber \\ \color{blue}{\left[e^{\int P(x)\ dx}\right]\frac{dy}{dx}+ \left[e^{\int P(x)\ dx}\right]P(x)\cdot y} &= \left[e^{\int P(x)\ dx}\right]f(x) \nonumber \\ \color{blue}{\frac{d}{dx}\left(e^{\int P(x)\ dx} y\right)} &= e^{\int P(x)\ dx} f(x) \nonumber \end{align}

The most important observation is that we have $\boldsymbol{d/dx (\mu(x)y)}$ (as a product of the product rule) on the left side. Now we have to integrate both sides of DE. Especially the left side is simple and the remaining tasks are not so difficult, which will be seen on examples.

The steps to solve linear DE can be summarized as

1. Bring DE into standard form $\frac{dy}{dx}+P(x)\cdot y = f(x)$.
2. Identify $P(x)$ and form the integrating factor $\mu(x)$ from $(\ref{ref:linea1_4})$.
3. Multiply both sides of DE by integrating factor $\mu(x)$.
4. Integrating both sides of DE is simple then considering the fact on the left side is $d/dx (\mu(x)y)$ to be found.

### Example

Solve DE $dy/dx + 3x^2y = 6x^2$.

Given DE is linear, already in standard form, so we can locate $P(x) = 3x^2$ to evaluate integrating factor $\mu(x)$:

$$\mu(x) = e^{\int 3x^2\ dx} = e^{x^3}.$$

The integrating factor will be used to multiply both sides of DE in the standard form. Then:

$$e^{x^3}\frac{dy}{dx} + e^{x^3}\ 3x^2y = e^{x^3}\ 6x^2$$

We know in advance that what will be found on the left side is a product of product rule of $d/dx(\mu(x)\ y) = d/dx(e^{x^3} y)$:

$$\frac{d}{dx}e^{x^3}y = e^{x^3}\ 6x^2$$

Now all we need is to integrate both sides and especially the left side is trivial.

$$\underline{\underline{e^{x^3}y = 2e^{x^3}+ C}}$$

### Example

Solve DE $x^2y' + xy = 1,\ x \gt 0,\ y(1)=2$.

The first step is to bring the DE into standard form, then locate $P(x)$ in order to evaluate integrating factor $\mu(x)$:

$$y' = \color{red}{\frac{1}{x}}y = \frac{1}{x^2} \implies P(x)= \frac 1 x\hskip2em x \neq 0 \\ \mu(x) = e^{\int\frac 1 x \ dx} = e^{\log x} = x$$

Integrating factor has been found. Now let us use it to multiply DE:

$$y'x +y = \frac 1 x$$

On the left side is product of the product rule applied on $d/dx(\mu(x)y) = d/dx(xy) = (xy)'$ as anticipated. So it is easy to integrate both sides then.

\begin{align} (xy)' &= \frac 1 x \nonumber \\ xy &= \log |x| + C \nonumber \\ y &= \frac{\log |x| + C}{x} \nonumber \end{align}

That is general solution, constant $C$ has to be found for supplied IV $y(x=1) = 2$:

$$2 = \frac{\log |1| + C}{1} \implies C=2 \\$$

The particular solution is then

$$\underline{\underline{y = \frac{\log x + 2}{x}}}.$$

### Example

Solve DE $y' + \color{red}{2x}y = 1$.

The given DE is already in the standard form, so we can find the integrating factor $\mu(x)$ for $P(x) = 2x$:

$$\mu(x) = e^{\int P(x)\ dx} = e^{\int 2x\ dx} = e^{x^2}.$$

Let us use $\mu(x)$ to multiply each part of DE:

$$y'e^{x^2} + 2xy e^{x^2} = e^{x^2}$$

Again, what is on the left side is $(\mu(x)y)'$, thus trivial to integrate.

\begin{align} (e^{x^2} y)' &= e^{x^2} \nonumber \\ e^{x^2}y &= \int e^{x^2}\ dx + C \nonumber \end{align}

However this time on the right side is a function which antiderative can not be expressed in terms of elementary functions. So it is OK to leave the member as $\int e^{x^2}\ dx$.

$$\underline{\underline{y = e^{-x^2}\int e^{x^2}\ dx + Ce^{-x^2}}}$$

### Example

Solve DE $xy' + y =x^3$.

If we compare this DE with linear DE $(\ref{ref:linea1_1})$ in standard form, we observe that given DE fits into linear DE if is divided by $x$:

$$y' + \color{red}{\frac 1 x} y = x^2.$$

Now it is clear that $P(x) = 1/x$ and we can assemble integrating factor $\mu(x)$ which will be used to multiply both sides of the DE.

\begin{align} \mu(x) &= e^{\int P(x)\ dx} = e^{\int 1/x\ dx} = e^{\log x} \implies \nonumber \\ \implies \mu(x) &= x \nonumber \\ \end{align}

As reminded, now the integrating factor $\mu(x) = x$ is good to multiply DE and then $(\mu(x)y)'$ appears on the left side.

\begin{align} xy' + y &= x^3 \nonumber \\ (\mu(x)\ y)' = (xy)' &= x^3 \nonumber \\ xy &= \int x^3 \ dx \nonumber \\ \end{align}

Not much can be done when the right side is finally integrated. The solution will be left in implicit form.

$$\underline{\underline{xy = \frac 1 4 x^4 + C}}$$

### Example

Solve DE $y'+\color{red}{a}y=b$.

DE is in the standard form, now $P(x) = a$, integrating factor

\begin{align} \mu(x) = e^{\int P(x)\ dx} &= e^{\int a\ dx} = e^{ax} \nonumber \\ a^{ax}\frac{dy}{dx} + e^{ax}ay &= a^{ax}b \nonumber \\ \frac{d}{dx} e^{ax}y &= e^{ax}b \nonumber \\ e^{ax}y &= \int e^{ax}b\ dx \nonumber \\ e^{ax}y &= b \frac 1 a e^{ax} + C\nonumber \\ \end{align}

And after we divide by $e^{ax}$: $$\underline{\underline{y = \frac b a + ce^{-ax}}}.$$

### Example

Solve DE $dy/dx=2x-3y,\ y(0)=1/3$.

First we have to shuffle the members to bring DE into standard form $(\ref{ref:linea1_2})$ of linear DE.

\begin{align} \frac{dy}{dx} + \color{red}{\color{red}{3}}y = &2x \nonumber \\ \mu(x) &= e^{\int P(x)\ dx} = e^{\int 3\ dx} = e^{3x} \nonumber \\ e^{3x}\frac{dy}{dx} + e^{3x}\cdot 3y &= e^{3x}\cdot 2x \nonumber \\ \end{align}

Again, after multiplying by $\mu(x)$, on the left side is $(\mu(x)y)'$ to be found.

\begin{align} \frac{d}{dx}e^{3x}y &= e^{3x}\cdot 2x \nonumber \\ e^{3x}y &= 2\int e^{3x}x\ dx \nonumber \end{align}

To integrate $e^{3x}x$ we have to use integration by parts. Integration by parts is product rule used backwards.

$$\color{blue}{(uv)'} = u'v + uv' \implies uv' = \color{blue}{(uv)'} - u'v \implies \int uv' = \color{blue}{uv}-\int u'v$$

For integration by parts there have to be one member which is easy to integrate and the other one which is easy to differentiate. In this case we differentiate $x$ and integrate $e^{3x}$.

$$\int e^{3x}x\ dx = \begin{vmatrix} u = x & u'=1\\ v'=e^{3x} & v = \frac 1 3 e^{3x} \end{vmatrix} = x\frac 1 3 e^{3x} - \int\frac 1 3 e^{3x}\ dx = \frac 1 3 e^{3x}x-\frac 1 9e^{3x}$$
\begin{align} e^{3x}y &= 2(\frac 1 3 e^{3x}x- \frac 1 9e^{3x}) + C \nonumber \\ y &= \frac 2 3 (x-\frac 1 3)+Ce^{-3x} \nonumber \end{align}

Considering given IV $y(x=0) = 1/3$:

$$\frac 1 3 = \frac 2 3 (0-\frac 1 3 )+ Ce^{-3\cdot 0} \implies C = \frac 5 9$$

Applying evaluated constant into the general solution we get particular solution for IV:

$$\underline{\underline{y = \frac 2 3 (x-\frac 1 3) + \frac 5 9 e^{-3x}}}.$$

### Example

Solve DE $xy'+y=e^x,\ y(1)=2$.

DE is not in the standard form yet.

$$y' + \color{red}{\frac 1 x} y = \frac 1 x e^x \implies P(x) = \color{red}{1/x} \nonumber \\ \mu(x) =e^{\int P(x)\ dx} = e^{\int 1/x\ dx} = e^{\log x} = x$$

The integrating factor $\mu(x)$ was needed to multiply the DE, because that is the way how to solve it:

\begin{align} xy' + x\frac 1 x y &= x\frac 1 x e^x \nonumber \\ xy' + y &= e^x \nonumber \\ \frac d {dx}xy &= e^x \nonumber \end{align}

As expected, on the left side is $d/dx\ \mu(x)y = d/dx\ xy$, which when integrated become $xy$:

\begin{align} (xy)' &= e^x \nonumber\\ xy &= \int e^x\ dx \nonumber \\ xy&= e^x + C \nonumber\\ y &= \frac 1 x(e^x+C) \nonumber \end{align}

Applying IV $y(x=1) = 2$ brings value of the constant $C=(2-e)$ and the particular solution is

$$\underline{\underline{y = \frac 1 x(e^x+2-e)}}.$$

List of chapters