Ordinary Differential Equations
Instructor: Bingchen Liu (bil013@ucsd.edu)
TAs: Argen Smith (argen@ucsd.edu) and Lauren Harvey (lrharvey@ucsd.edu)
1 | Notation
In these notes, I use \(y\) as the dependent variable and \(x\) as the independent variable consistently. However, it’s important to note that these can be represented by any character. For example, one of the most common is \(x\) being the dependent variable and \(t\) being the independent variable, especially in physical, time-dependent problems.
In these notes, I use the notation \(\frac{dy}{dx}\) to represent a derivative of \(y(x)\) with respect to \(x\). However, the notation \(y'(x)\) is often used. Here we would write \(\frac{d^2y}{dx^2}\) as \(y''(x)\). In this case, some high \(n^{th}\) derivative of \(y\), written here as \(\frac{d^ny}{dx^n}\) is written as \(y^{(n)}(x)\).
In time-dependent problems, the derivative of a function with respect to time is often written as \(\dot{x}(t)\), with higher derivatives increasing the number of dots (up to a reasonable point, before \(x^{(n)}(t)\) is used), so a second derivative is written as \(\ddot{x}(t)\).
2 | Classification of ODEs
2.1 What is an ODE?
An ordinary differential equation is an equation that relates the derivative(s) (\(\frac{dy}{dx}\)) of the dependent variable (y) to some function of the the independent variable (x) and dependent variable itself (y(x)):
The word ‘ordinary’ means that the differential equation dependent on only a single independent variable (x), in contrast to partial differential equations (PDEs) that is respect to more than one independent variable (x, y, z…).
2.2 Order of an ODE
The order of an ODE refers to the highest derivative of the function present in the equation. For example,
is second order, because the highest derivative, \(\frac{d^2y}{dx^2}\), is the second derivative of the function \(y(x)\).
is fifth order, because the highest derivative is the fifth derivative of \(y(x)\).
2.3 Linear vs Non-linear ODEs
A linear ODE is linear in the dependent variable, \(y(x)\), and all of its derivatives. This means that the dependent variable \(y(x)\) cannot have a power that isn’t one or zero, and nor can any of its derivatives. The dependent variable and its derivatives also cannot multiply or divide each other. The general form of an \(n^{th}\)-order linear ODE is:
It is important to notice that the functions \({A_n(x), A_{n-1}(x), ... , A_2(x), A_1(x), A_0(x)}\) do not depend on the dependent variable or any of its derivatives. These are arbitrary functions of \(x\). Although it would make it hard to solve, it can still be linear even if these functions are exponential, trigonometric, hyperbolic, or anything else, so long as they are only functions of \(x\).
In general, most ODEs you’ll be able to solve analytically (meaning, by hand) are linear (though certainly not all linear ODEs can be solved analytically!). There are some exceptions though!
On the other hand, a non-linear ODE violates these rules. For example, it may have the dependent variable and/or its derivatives raised to a power of two or more, or it could have any or all of the functions \({A_n(x), A_{n-1}(x), ... , A_2(x), A_1(x), A_0(x)}\) depend on \(y\) or its derivatives.
2.4 Homogeneous vs Inhomogeneous ODEs
A homogeneous ODE is an ODE for which \(y = 0\) is a solution. In practice, this means that a homogeneous ODE does not contain any function of \(x\) that is not multiplied by a function of \(y\) or its derivatives. For example,
is a homogeneous ODE. But,
is an inhomogeneos ODE. A homogeneous ODE is usually written in a form so that the right hand side is 0. This means that every term on the left hand side is a function of \(y\), its derivatives, and \(x\), but none are functions of \(x\) alone.
An inhomogeneous ODE is usually written with the function of \(x\) alone (this function is referred to as the forcing) on the right hand side. For example, the inhomogeneous example from before would be written as:
where \(-\sin(x)\) is the forcing. However, of course, ODEs aren’t always written in this form, but it’s often how you’ll see them in practice.
As a quick exercise, let’s classify the following ODEs:
3 | An Introduction to Solving ODEs
Many ODEs cannot be solved analytically. For those taking Janet’s class, you’ll go through a lot of different solution strategies, but a few are assumed to be known at the beginning of the class. I’ll go through these briefly today.
3.1 Boundary and Initial Conditions
An ODE is incomplete without specifying boundary or initial conditions. Without these conditions, you can only solve an \(n^{th}\)-order ODE up to \(n\) arbitrary constants (this is called the general solution to the ODE). These constants can be specified by applying \(n\) boundary or initial conditions.
Note that a total of n conditions are required to solve n-th order ODEs.
Boundary conditions are when the dependent variable is specified at \(n\) values of the independent variable. For example, for a second order ODE, the boundary conditions are \(y(a) = A, \ \ y(b) = B\). In order to apply these conditions, you first need to find the general solution to the ODE, and then find \(y(a), \ y(b)\) in terms of the two arbitrary constants, and then solve for the constant by setting them equal to \(A\) and \(B\) respectively.
Initial conditions for an \(n^{th}\) order ODE specify the value of the dependent variable and its next \(n-1\) derivatives at \(t=0\). For a first order ODE, for example, this is simply specifying \(y(0) = A\). For a second order ODE, \(y(0) = A, \ y'(0) = B\) must both be specified in order to obtain an exact solution.
3.2 First Order ODEs
There are many approaches to solving first order ODEs. Today we’ll look only at the two most common strategies, separation and integrating factor.
3.2.1 Separable First Order ODEs
The simplest way to solve an ODE is to separate so that the LHS is only a function of \(y\), multiplied by \(\frac{dy}{dx}\) and the RHS is only a function of \(x\). However, this only works for a special kind of first order ODE called separable. These can be written in the form
The solution strategy for solving this kind of ODE is as follows:
Separate the ODE into the form above
“Multiply” both sides by \(dx\) (in general, its heinous to refer to this as multiplication. \(dx\) is an infinitesimal quantity that approaches 0, and so formally you cannot multiply through an equation by \(dx\), however, in this case only, it’s easiest to do this as if you can). Now you have an equation of the form
\[f(y)dy = g(x)dx\].
Integrate both sides! After integrating, you have the general solution to the ODE.
\[\int f(y) dy = \int g(x) dx\]Apply the initial/boundary condition to specify the constant of integration. What is left is the exact solution to the ODE.
Example: \(\frac{dy}{dx} + \sin(x)y = 0\), subject to the initial condition \(y(0) = 5e\)
To get this in separable form, we can move the second term to the RHS, and then divide both sides by \(y\). This becomes:
\[\frac{1}{y} \frac{dy}{dx} = -\sin(x)\]“Multiply” by \(dx\):
\[\frac{1}{y} dy = -\sin(x) dx\]Integrate!
\[\begin{split}\int \frac{1}{y} dy = \int -\sin(x) dx \Rightarrow \ln{y} = \cos(x) +C \\ \\ \Rightarrow y = e^{\cos(x) + C} = e^C e^{\cos(x)} = A e^{\cos(x)}\end{split}\]Apply the initial condition:
\[y(0) = Ae^{cos(0)} = Ae = 5e \Rightarrow A = 5\]and now we have the solution:
\[y = 5e^{\cos(x)}.\]
3.2.2 Integrating Factor
This is the most useful method for solving first order ODEs, as it can always be used for any linear first order ODE. The trick is to find a function of \(x\) that you can multiply the whole equation by so that it can be directly integrated.
Note, the ODE (except in very few cases) must be linear for this to work. This means it can be written in the form:
for some functions of \(x\) only \(P(x)\) and \(Q(x)\).
The solution strategy for the integrating factor method is as follows:
Find the integrating factor. The integrating factor can be found by finding
\[\mu(x) = e^{\int P(x) dx}.\]Note that in this case, we don’t need a constant of integration.
Multiply the ODE through by the integrating factor:
\[\mu(x) \frac{dy}{dx} + \mu(x)P(x)y = \mu(x) Q(x).\]Due to the form of the integrating factor, this can ALWAYS be written as
\[\frac{d}{dx}(\mu(x)y) = \mu(x)Q(x).\]because \(\frac{d\mu}{dx} = \mu(x)P(x)\) by definition.
Integrate!
\[y = \mu^{-1}(x) \left[A+\int \mu(x) Q(x) dx \right]\]Specify the constant of integration with the initial or boundary condition.
Example: \(3x\frac{dy}{dx} + y = x^3 + x^2\) subject to \(y(1) = \frac{17}{70}\)
Find the integrating factor: here, we need to rearrange to put it in the correct form. dividing by \(3x\), we get \(\frac{dy}{dx} + \frac{y}{3x} = \frac{1}{3}(x^2 + x)\).
\(P(x) = \frac{1}{3x}\), so we can find \(\mu(x)\) by
Multiply through by the integrating factor: using the trick outlined in step 2 above (where \(Q(x) = \frac{1}{3} (x^2+x)\)), we can immediately write
\[\frac{d}{dx}(y x^{\frac{1}{3}}) = \frac{1}{3}(x^{\frac{7}{3}}+x^{\frac{4}{3}})\]Integrate:
\[yx^{\frac{1}{3}} = \frac{1}{10}x^{\frac{10}{3}} + \frac{1}{7}x^{\frac{7}{3}} + A \Rightarrow y = \frac{1}{10} x^3 + \frac{1}{7}x^2 + C\]Specify the constant of integration with the initial condition:
\[y(1) = \frac{17}{70}+C = \frac{17}{70} \Rightarrow y = \frac{1}{10} x^3 + \frac{1}{7}x^2.\]
3.3 Second Order ODEs
3.3.1 Classification (again)
Here, we are only going to look at linear, homogeneous ODEs with constant coefficients. This means that the ODE can be written in the form:
where \(A, B, C\) are all constants. This is called a constant coefficient second order ODE (and in this case, it’s also homogeneous and linear).
3.3.2 Solution by Ansatz
For linear, constant coefficient, second order ODEs, the easiest way to find a solution is by making a guess. This is called the “ansatz”. For constant coefficient, we ALWAYS make the guess that \(y \propto e^{sx}\) for some unknown constant \(s\). The solution strategy is as follows:
Sub the ansatz \(y \propto e^{sx}\) into the ODE, and divide through by \(e^{sx}\). There should be no \(x\)s left in the equation, it will be a quadratic in \(s\). This is called the characteristic equation of the ODE.
Solve the characteristic equation for \(s\), which should have two solutions. There are three cases:
the characteristic equation has two real distinct roots.
the characteristic equation has a repeated root.
the characteristic equation has two roots that are a complex conjugate pair.
If the characteristic equation has two distinct real roots, \(s = a_1, a_2\), then the general solution to the ODE is
\[y = C_1e^{a_1x} + C_2e^{a_2x}.\]
If the characteristic equation has a single repeated root, \(s = a\) then the general solution to the ODE is
\[y = C_1 e^{ax} + C_2 x e^{ax}.\]
If the characteristic equation has a complex conjugate pair of roots \(s = a+ib, a-ib\), then the general solution to the ODE is
\[y = e^{ax}(C_1\sin(bx) + C_2\cos(bx)).\]
Use the initial or boundary conditions to solve for \(C_1\) and \(C_2\) and thus the exact solution.
Example: \(\frac{d^2y}{dx^2} + 4\frac{dy}{dx} + 5y = 0\), subject to \(y(0) = 3, \ \ y(\pi/2) = e^{-\pi}\)
Sub in the ansatz: \(s^2e^{sx} + 4se^{sx} + 5e^{sx} = 0\), and divide by \(e^{sx}\): \(s^2 + 4s + 5 = 0\) is our characteristic equation.
Solve for \(s\): using the quadratic formula, we obtain \(s = -2 \pm i\).
Since we have a complex conjugate pair, the general solution is given by (iii):
\[y = e^{-2x}(C_1\sin(x) + C_2\cos(x)).\]Use the BCs to solve for \(C_1\) and \(C_2\):
\[y(0) = C_2 = 3, y(\pi/2) = e^{-\pi}(C_1) = e^{-\pi} \Rightarrow C_1 = 1\]so, we have the solution:
\[y = e^{-2x}(\sin(x) + 3\cos(x)).\]
[ ]: