1.1. Revision of Concepts#

Classification of Differential Equations#

Note

Important things to retain from this block:

  • Identify characteristics of differential equations

  • Understand how numerical and analytical solutions might differ as we get to more complex problems which need simplification

  • Remember that analytical solutions are not always possible

Differential equations can be classified as Ordinary Differential Equations (ODEs) and Partial Differential Equations (PDEs). ODEs have derivatives with respect to a single independent variable (either time or space), for example:

\[ \frac{d x(t)}{d t} = \cos t \]

describes the rate of change of the variable \(x\) in time \(t\).

PDEs have derivatives with respect to multiple independent variables (often time and space), for example:

\[ \frac{\partial c(x,t)}{\partial t} + u\frac{\partial c(x,t)}{\partial x} = 0 \]

describes the propagation of the concentration \(c\) in time \(t\) along dimension \(x\).

The classification can be done more precisely by the equation’s order and linearity (linear or non-linear). The order refers to the highest derivative while non-linear equations are those in which the dependent variable or its derivative(s) are non linear (exponential, sine or with a power different than 1). See the following examples:

\[ \frac{d^3y}{dx^3} - x\frac{d^2y}{dx^2} + y = 0 \qquad \text{third-order linear ODE} \]
\[ \frac{dy}{dx} = y^2 + x \qquad \text{first-order non-linear ODE} \]
\[ \frac{d^2y}{dx^2} + y\left(\frac{dy}{dx}\right)^2 = \sin(y) \qquad \text{second-order non-linear ODE} \]

Analytical vs Numerical Solutions#

Equations can be solved in two ways: analytically and numerically. The analytical solution is exact while a numerical solution requires computational methods to approximate the solution. So why would we use anything other than analytical solutions? Well, analytical solutions are difficult/impossible to find for complex equations, specially when the problem involves a complex geometry. This complexity will be treated later in the book. For now, let’s illustrate analytical and numerical solutions considering a simple problem.

Find the value \(x\) for \(f(x)=3x-2\) when \(f(x) = 0\) in the interval \([0,1]\).

Analytical Solution

\[ f(x) = 0 \Leftrightarrow 3x-2=0 \Leftrightarrow x = \frac{2}{3}=0.666666666666666..\]

Note that there is no need for any extra computation. You can say that there is only one computation needed: the assignment of the \(x\) value.

Numerical Solution

The code below shows an iterative method to find the x value.

def f(x):
    return 3*x-2

dx = 0.001
for i in range(1000):
    x = dx*i
    if f(x) * f(x+dx) < 0:
        print("Number of computations needed to find a solution",i*4)
        break

print("Answer x = ", x+dx)
Number of computations needed to find a solution 2664
Answer x =  0.667

Note that the 2664 computations needed is highly dependent on the method (this one is not very efficient). Here the search starts at x=0 and increases in steps of 0.001, which also limits the accuracy of the solution.

Exercise

Let us now look to another simple example:

Find the value \(x\) for \(f(x) = 3\sin(x)-2\) when \(f(x) = 0\) in the interval \([0,1]\).

Analytical Solution

\[ f(x) = 0 \Leftrightarrow 3\sin(x)-2=0 \Leftrightarrow x = \arcsin\left(\frac{2}{3}\right) = 0.7297276562269663..\]

Numerical Solution

import math

def f(x):
    return 3*math.sin(x)-2

dx = 0.001
for i in range(1000):
    x = dx*i
    if f(x) * f(x+dx) < 0:
        print("Number of computations needed to find a solution",i*4)
        break

print("Answer x = ", x+dx)
Number of computations needed to find a solution 2916
Answer x =  0.73

Note that there is no attempt to solve f(x) directly. Only the function is defined and the exact same steps of the previous problem are followed.