Numerical methods for differential equations

GUIDING QUESTION: How can I compute a solution to a differential equation?

Guiding philosophy: Translate a differential equation into a system of algebraic equations.

Motivating example

When solving a differential equation, we seek a certain function satisfying some conditions.
For instance, we might seek a function $v: \mathbb{R} \to \mathbb{R}$ such that $$v''(x) = -m^2 v(x)$$
whenever $0 < x < \pi$, for some integer $m$, and such that $v(0) = v(\pi) = 0$.

Motivating example

$$v''(x) = -m^2 v(x), \quad 0 < x < \pi, \quad v(0) = v(\pi) = 0$$ You may think of this data an infinite collection of equations, one for each point in the interval $[0, \pi]$.
We can't solve this infinite system numerically, but we can discretize the domain to obtain a finitely many algebraic equations.

Motivating example

$$v''(x) = -m^2 v(x), \quad 0 < x < \pi, \quad v(0) = v(\pi) = 0$$ You may think of this data an infinite collection of equations, one for each point in the interval $[0, \pi]$.
Fix $n$ and let $x_j = 0 + jh$, with $h = {\pi - 0 \over n}$.
Define $v_j = v(x_j)$. We'll set up a system of algebraic equations to find the unkown $v_j$, by approximating the derivative term $v''(x_j)$ as a linear combination of $v_j$.

Motivating example

$$v''(x) = -m^2 v(x), \quad 0 < x < \pi, \quad v(0) = v(\pi) = 0$$ Define $v_j = v(x_j)$. We'll set up a system of algebraic equations to find the unkown $v_j$, by approximating the derivative term $v''(x_j)$ as a linear combination of $v_j$.
We can do this in at least two ways.
First, we may approximate $v$ using its interpolating polynomial at the $x_j$ and use the differentiation matrix.

Via interpolant

$$v''(x) = -m^2 v(x), \quad 0 < x < \pi, \quad v(0) = v(\pi) = 0$$ We may approximate $v$ using its interpolating polynomial at the $x_j$ and use the differentiation matrix.
The system $$v''(x_j) + m^2 v_j = 0, \quad j = 1, \ldots, n-1$$ becomes $$D^2 \mathbf{v} + m^2 \mathbf{v} = 0,$$ with $D_{ij} = L_i'(x_j)$ and $L_i$ denoting the $i$th Lagrange basis polynomial corresponding to the nodes $x_0, x_1, \ldots, x_n$.

Via interpolant

Therefore, we can obtain an approximation for the values $v_j = v(x_j)$ by solving the algebraic system $$\begin{bmatrix} v_0 \\ D^2 \mathbf{v} + m^2 \mathbf{v} \\ v_n \end{bmatrix} = 0. $$
In this case, we obtain a linear system!

Finite difference schemes

Alternatively, we may approximate the derivative terms $v''(x_j)$ using a finite difference scheme.
If we choose the central difference approximation, the system $$v''(x_j) + m^2 v_j = 0, \quad j = 1, \ldots, n-1$$ becomes $${v_{j-1} - 2v_{j} + v_{j+1} \over h^2} + m^2 v_j = 0, \quad j = 1, \ldots, n-1.$$

Finite difference schemes

Alternatively, we may approximate the derivative terms $v''(x_j)$ using a finite difference scheme.
If we choose the central difference approximation, the system $$v''(x_j) + m^2 v_j = 0, \quad j = 1, \ldots, n-1$$ becomes $$v_{j-1} + (h^2 m - 2) v_{j} + v_{j+1} = 0, \quad j = 1, \ldots, n-1.$$

Finite difference schemes

Alternatively, we may approximate the derivative terms $v''(x_j)$ using a finite difference scheme.
Incorporating the boundary data, we obtain the tridiagonal system \begin{align} v_0 \qquad \qquad \qquad \qquad \quad &= 0 \\ v_0 + (h^2m^2 - 2) v_1 + v_2 \qquad &= 0 \\ \ddots \qquad \qquad \\ v_{n-2} + (h^2m^2 - 2) v_{n-2} + v_n &= 0 \\ v_n &= 0 \end{align}
We may re-write the last system as $$(A - \lambda I) \tilde{\mathbf{v}} = 0,$$ with $$A = \begin{bmatrix} -2 & 1 & & & \\ 1 & -2 & 1 & \\ & \ddots & \ddots & \ddots \\ && 1 & -2 & 1 \\ & & & 1 & -2 \end{bmatrix}, \quad \lambda = (mh)^2,$$ and $\tilde{\mathbf{v}} = \begin{bmatrix} v_1 & \cdots & v_{n-1} \end{bmatrix}^T$.
We've seen this system before, in Problem 1 of HW4!

Finite difference method

Given a differential equation, the finite difference method consists of
  1. Discretize the domain.
    That is, choose a finite set of points in the domain at which you will approximate the solution.
  2. Choose a finite difference approximation for all derivative terms.
  3. Incorporate boundary conditions and associated system!
We may also apply this finite difference method to partial differential equations.
Check out the live session!
Congratulations! You reached the end of this lecture.