First order linear differential equations

We are now going to deal with another subset of first order differential equations which in some ways are easier than the previous and in other ways more complicated. These are linear first order differential equations. The general form of a first order linear differential equation is:

$\frac{dy}{dx}+P(x)y=Q(x)$

where $P(x)$ and $Q(x)$ are any functions of $x$.

Very importantly, I’m leaving off the fact that $y$ is dependent on $x$ in the notation, but you should remember that this is really $y(x)$ and that is the function you are trying to solve for.

Sometimes you will be given an equation which is not obviously in this form but it can be transformed to this form. For instance:

$\frac{1}{y}\frac{dy}{dx}=x^2+\frac{\sin x}{y}$

This can easily be transformed into the canonical form for a linear first order DE. We are going to try and rewrite the left hand side of the equation in a form which will mean that we can solve the differential equation very easily. We are going to try and rewrite the left hand side of the first equation as:

$\frac{1}{R(x)}\frac{d yR(x)}{dx}$

for some $R(x)$ so that indeed the two expressions are the same. The bottom line: We want to find $R(x)$ for which the previous equation is equal to the L.H.S of the first equation.

Let’s start by expanding the previous equation using the product rule:

$\frac{1}{R(x)}\frac{d yR(x)}{dx}=\frac{dy}{dx}+\frac{y}{R(x)}\frac{dR(x)}{dx}$

ie. if this is going to equal the L.H.S of the first equation then we must have that:

$\frac{1}{R(x)}\frac{d(R(x))}{dx}=P(x)$

So let’s see if we can find what $R(x)$ has to be for this to be true. We can use a rather nice trick which is that:

$\frac{1}{R(x)}\frac{dR(x)}{dx}=\frac{d(\ln R(x))}{dx}$

so we have $\frac{d(\ln R(x)}{dx}=P(x)$. Let’s bring up the $dx$ from the bottom and integrate, to give:

$\ln R(x)+c=\int P(x)dx$

and thus:

$R(x)=e^{\int P(x)dx-c}=e^{\int P(x) dx}e^{-c}$

Let’s redefine the exponential of the constant and just say:

$R(x)=\tilde{c} e^{\int P(x) dx}$

But in fact we see that we will write the left hand side of the equation in the form:

$\frac{1}{R(x)}\frac{dyR(x)}{dx}$

and so the constant will vanish because we have it in the numerator and denominator, so we can actually ignore it and say:

$R(x)=e^{\int P(x) dx}$

All we are claiming is that if $R(x)=e^{\int P(x) dx}$ then

$\frac{1}{R(x)}\frac{dyR(x)}{dx}=\frac{dy}{dx}+P(x)y$

Think of some simple functions for $P(x)$ and show that indeed the left and right are the same when $R(x)=e^{\int P(x) dx}$.

This looks pretty strange, but in fact it’s fine. If we can integrate $P(x)$ then we can certainly take the exponential of the integral. So, we are claiming that now the differential equation can be written in the form $\frac{1}{R(x)}\frac{d(yR(x))}{dx}=Q(x)$ so that the solution is:

$yR(x)=\int R(x) Q(x)dx+c$

So we have done it….without knowing what we were doing….We can plug back in what $R(x)$ has to be in terms of $P(x)$ and we have found the solution to the equation. The complete solution is then:

$y=\frac{1}{e^{\int P(x) dx}}\left(\int e^{\int P(x)dx} Q(x)dx+c\right)$

which might look horrible, but there’s no part of that which you can’t do…as long as the integrals themselves aren’t too complicated.

Let’s look at an example of this where we will follow the same reasoning but it will all be a bit more clear when we have specific $P$‘s and $Q$‘s and $R$‘s. Let’s take a really simple example:

$\frac{dy}{dx}+\frac{y}{x}=x$

so now we have $P(x)=\frac{1}{x}$ and $Q(x)=x$. We thus have that $R(x)=e^{\int P(x)dx}=e^{\ln x+c}=e^c e^{\ln x}=e^c x$. So apparently the left hand side of the equation should be the same as:

$\frac{1}{R(x)}\frac{d (y R(x))}{dx}$

Check this by plugging in $R(x)$:

$\frac{1}{e^c x}\frac{d (y e^c x)}{dx}=\frac{1}{x}\frac{d (yx)}{dx}=\frac{dy}{dx}+\frac{y}{x}$

which is indeed the left hand side of the original equation. So now we have that:

$\frac{1}{x}\frac{d (yx)}{dx}=x$

which is just $\frac{d(yx)}{dx}=x^2$. We can then solve this to get:

$y x=\frac{x^3}{3}+c$

$y=\frac{x^2}{3}+\frac{c}{x}$

Check that this is a solution by plugging it into the original differential equation that we were trying to solve. You’ll see that it is a general solution to this equation. As always $c$ can be fixed to a particular value by being given an initial condition.

Let’s take another example. This time it corresponds to a falling body accelerating under gravity but with air resistance:

$\frac{dv}{dt}=9.8-0.196v$

The 9.8 is the acceleration due to gravity. The 0.196 is a number which represents the amount of air resistance, but in fact it’s chosen here to make the numbers come out nicer in the end. Let’s start by putting it into the canonical form for a first order linear DE:

$\frac{dv}{dt}+0.196v=9.8$

The left hand side can then be rewritten to give:

$\frac{1}{e^{0.196 t}}\frac{d(ve^{0.196t})}{dt}=9.8$

Now we rearrange, and integrate to give:

$\int d(v e^{0.196 t})=\int 9.8 e^{0.196 t} dt$

which gives, after integration:

$v e^{0.196 t}=50 e^{0.196 t} +c$

or:

$v =50 +c e^{-0.196 t}$

If we state that at $t=0$ the velocity is 0 then we get:

$0 =50 +c e^{0}$

so $c=-50$:

$v =50-50 e^{-0.196 t}$

which corresponds to a body accelerating under gravity (like being dropped out of a plane) and the acceleration being slowed by air resistance until it reaches a terminal velocity of $50ms^{-1}$.

Let’s just make sure that we could have used our formalism to get the answer straight away without the juggling we did of the left hand side:

Calculating:

$y=\frac{1}{e^{\int P(t) dt}}\int e^{\int P(t)dt} Q(t)dt$

with $P(t)=0.196$ and $Q(t)=t$ you’ll find that you do indeed get the same solution we found above.

Let’s look at another example:

$y'-\frac{y}{2}=4\sin(3t)$

I’m jumping about between different forms of notation because in general you will come across all of these and it’s useful for you to be able to translate between them. The dash is just the usual derivative and we can see here that $y$ is supposed to be a function of a variable $t$. It should always be clear what the functional dependence will be just by looking at the equation.

Try running through this example like we did with the last one by getting the left hand side into a term which has a single derivative on $y$ times some function of $t$. We will however simply take $P(t)$ and $Q(t)$ and plug it into the formalism. here $P(t)=-\frac{1}{2}$ and $Q(t)=4\sin(3t)$ so $e^{\int P(t)}=e^{-\frac{t}{2}+c_1}$ and thus:

$y=\frac{1}{e^{-\frac{t}{2}+c_1}}\int 4\sin(3t)e^{-\frac{t}{2}+c_1}dt=-\frac{8}{37}\left(6\cos(3t)-\sin(3t)\right)+ce^{\frac{t}{2}}$

A reiteration

I think that it’s important to understand how we’re solving these first order linear differential equations. The idea is to make a rearrangement of them into a form which is very easily to solve. In order to do that we have to find a special function $R(x)$ which allows for this transformation, but once we’ve found it and made the rearrangement, we can solve the equation with ease (modulo being able to do the integrals).

A flowchart showing the formulation of the general solution to a linear first order differential equation.

We said at the very beginning of this section that in some ways these equations are more complicated than the separable equations we first looked at, and in other ways are less complicated. The method to solve them was certainly more involved than when we solved the separable equations but it turns out that the linearity of these equations imbues them with some very special properties. In general solutions to linear equations can be combined in ways which make finding the combined effects of different solutions very easy. We will not have a chance to go into this, but suffice it to say that in general, finding solutions to non-linear equations can be incredibly complicated, but they can have some amazing behaviour.

If you had a somewhat more sophisticated differential then you could study more complex problems

https://what-if.xkcd.com/28/

 How clear is this post?