Lecture 6. First order linear ordinary differential equations#
Last lecture, you saw an exact technique for solving separable ordinary differential equations. In this lecture, we are going to look at some techniques for solving what are called ‘first order linear ordinary differential equations’. That’s a lot of adjectives, many of which may be new! So we will start by giving some definitions.
6.1 Classification of differential equations#
The first way to classify a differential equation is by the number of independent variables. What’s an independent variable? Good question - we need a definition.
Definition 5
A dependent variable is a variable that depends upon other variables. An independent variable is one that is not dependent.
For example, in the equation
the dependent variable is \(U\) as it depends upon \(t\), and \(t\) is the independent variable as it does not depend on any other variable. Usually, in the context of differential equations, you differentiate dependent variables by independent variables.
Definition 6
An ordinary differential equation (ODE) is a differential equation with only one independent variable. A differential equation with more than one independent variable is called a partial differential equation (PDE).
In this module, we will only be concerned with ordinary differential equations (ODEs), so we will now look at some subclassifications of ODEs.
Definition 7
The order of an ODE is the highest exponent of any differential operator in the equation.
That’s a bit abstract, so let’s see some examples. A first order ODE will involve terms where a dependent variable is differentiated no more than once and must include at least one term where a dependent variable is differentiated once. For example
A second order ODE may involve terms where a dependent variable is differentiated either once or twice, but no more. It must include at least one term where a dependent variable is differentiated twice. Here are two examples
A third order ODE involves terms where the dependent variable is differentiated up to three times. It must include at least one term where a dependent variable is differentiated thrice. Here are two examples
Definition 8
A linear function of \(x_{1}, \ldots, x_{n}\) is a function of the form \(f\left(x_{1}, \ldots, x_{n}\right)=\) \(a_{0}+a_{1} x_{1}+\cdots+a_{n} x_{n}\) where \(a_{0}, \ldots, a_{n}\) are constant with respect to \(x_{1}, \ldots, x_{n}\).
Definition 9
A linear ODE is one that is a linear function of the dependent variables and their derivatives.
Again, those definitions are a bit abstract, but you hopefully after a few examples, you will get the idea. Here are some linear ODEs:
and here are some non-linear ODEs:
In Equations (78), (79), (80), and (81), the non-linear terms are \(-U^{2}, \sin (U) \frac{\mathrm{d} U}{\mathrm{~d} t},\left(\frac{\mathrm{d} U}{\mathrm{~d} t}\right)^{2}\), and \(U \frac{\mathrm{d} U}{\mathrm{~d} t}\), respectively.
Definition 10
The general \(n^{\text {th }}\) order linear ordinary differential equation can be written as
where \(a_{0}(t), \ldots, a_{n-1}(t)\) and \(b(t)\) are functions of \(t\). If \(b(t)=0\), then Equation (82) is called homogeneous. If \(b(t) \neq 0\), then Equation (82) is called inhomogeneous.
Here are some examples of homogeneous linear ODEs:
and here are some inhomogeneous linear ODEs:
In Equations (86), (87), and (88), we have \(b(t)=t^{2}, b(t)=t^{2} \ln (t)\), and \(b(t)=-\sin (t)\), respectively.
6.2 Solving first order linear ODEs#
The general form for a first order linear ODE is as follows
where \(p(t)\) and \(q(t)\) are functions. In the homogeneous case, \(q(t)=0\) so the equations is separable and can be solved using the techniques of Section 5.3, as follows
where we can pick \(A=\exp (c)\) for solutions where \(U(t)>0\) or \(A=-\exp (c)\) for solutions where \(U(t)>0\).
There is also a general equation for the solution of an inhomogeneous first order linear ODE, but it is rather cumbersome and unenlightening. Instead, we will look at an example, which illustrates the key trick to solving these beasts. But first we need a definition.
Definition 11
For an ODE in the form of Equation (89), we the define integrating factor as \(I(t)=\exp \left(\int p(t) \mathrm{d} t\right)\).
Example 11
Solve
Solution.
First re-write Equation (91) as
Then we do a strange trick. We multiply through by the integrating factor \(I(t)=\exp \left(\int 2 t \mathrm{~d} t\right)=\) \(\exp \left(t^{2}\right)\), to give
Why on Earth have we done that? Watch:
which is the left-hand side of Equation (93). Putting Equations (93) and Equation (94) together, we have
for a constant, \(c\).
Lecture 6 Homework exercises#
Exercise 15
Solve the following first order linear ODEs
(a) \(\frac{\mathrm{d} U}{\mathrm{~d} t}+4 U-8=0\) with initial condition \(U(0)=1\)
(b) \(\frac{\mathrm{d} U}{\mathrm{~d} t}-U-t^{2}=0\) with initial condition \(U(0)=1\)
(c) \(\frac{\mathrm{d} U}{\mathrm{~d} t}-U \exp (t)-3 \exp (t)=0\) with initial condition \(U(0)=1\)
(d) \(\frac{\mathrm{d} U}{\mathrm{~d} t}+\frac{3 U}{t}-t=0\) with condition \(U(1)=1\)
(e) \(\frac{\mathrm{d} U}{\mathrm{~d} t}-U-\sin (t)=0\) with initial condition \(U(0)=1\)
(f) \(\frac{\mathrm{d} U}{\mathrm{~d} t}+2 U-6=0\) with initial condition \(U(0)=1\)
(g) \(\frac{\mathrm{d} U}{\mathrm{~d} t}-U-2 \cos (t)=0\) with initial condition \(U(0)=1\)
(h) \(\frac{\mathrm{d} U}{\mathrm{~d} t}-U-2 t=0\) with initial condition \(U(0)=1\)
Option extra: coding
The code below will show the time-course from the ODE we looked at in example 11. It computes the solution in two ways: it uses the explicit solution we found (having used an initial condition \(U(0)=1\) to get a value for \(c\)), and it also uses an in-built ‘numerical solver’ to calculate the time-course. This is well beyond this module (you’ll see it in more detail in the 2nd year scientific programming course) but just trust that it works! If you want a challenge, try altering the code to check your results for some of the questions in exercise 15.
# @title
#Accompanying python code for MAS108 lecture 6
#Code to produce plots of first-order linear ODEs
# First we import the libraries we need
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
#A 'function' for the ODE
def ex11_ode(t,U):
dUdt = -2*U*t+t
return dUdt
#The initial value of U
U0 = 1
# The timespan we will inetgrate over
tspan=np.linspace(0,10,101)
# The special funciton to numerically solve the ODE
sol = solve_ivp(ex11_ode,[tspan[0],tspan[-1]],[U0],t_eval=tspan)
# The explicit solution we derived (having used he initial condition to find c)
mysol = 0.5+0.5*np.exp(-tspan**2)
#Code to plot the output
plt.rcParams['figure.figsize'] = [8, 4]#
plt.rcParams.update({'font.size': 16})
fig1=plt.figure()
plt.plot(tspan,sol.y[0],'b', marker = 'o')
plt.plot(tspan,mysol,'r', marker = 'x')
plt.xlabel('Time')
plt.ylabel('U')
plt.show()