Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Numerical methods

Topics in numerical methods

Numerical methods are focused on ways to solve problems that, in general, cannot be solved exactly.

We will describe both how to write these solvers from scratch, as well as how to write. For each, we will provide code examples using vanilla Python (with NumPy) and other libraries as needed.

ODEs and initial-value problems

In our discussion on differential equations, we mentioned that ordinary differential equations take the general form:

dydt=f(t,y)\dfrac{dy}{dt} = f(t, y)

(note that yy can be a vector, and reduction of order may be necessary to cast a particular ODE in this form). An initial-value problem is a description of a physical scenario in which an ODE is provided along with the initial conditions, that is, y(0)y(0), the value of yy at t=0t = 0. Often, we cannot solve initial-value problems exactly, and some initial-value problems are so complicated that even approximate solutions cannot be found. We therefore turn to numerical methods.

The general basis of solving an initial-value problem numerically is to discretize y(x)y(x) into a set of line segments. Each segment connects the nnth-point (tn,yn)(t_n, y_n) to its next point (tn+1,yn+1)(t_{n + 1}, y_{n+1}). By starting at the known initial condition (0,y(0))(0, y(0)), we may then use the fundamental of calculus to calculate the next point:

yn+1=tntn+1f(t,yn)dty_{n+1} = \int_{t_n}^{t_{n+1}}f(t, y_n) d t

This process is known as numerical integration and is the principle behind solving ODEs. Different ways of computing the integral numerically result in a diverse class of specialized numerical integration schemes, each of which has its own advantages and disadvantages.

forwards Euler, backwards Euler, midpoint, leapfrog, runge-kutta 2 & 4, also some bit about symeptic integrators

PDEs and boundary-value problems

The most common methods of solving boundary-value problems numerically are as follows:

The finite difference method

More info here: https://labs.elaraproject.org/theoretical/Guide-to-partial-differential-equations.html#numerically-solving-pdes

The finite element method

a) Assume the solution takes the form u(x)=iφiϕi(x)u(\mathbf{x}) = \sum_i \varphi_i \phi_i(\mathbf{x}) where ϕi(x)\phi_i(x) is a set of functions that form a complete basis. A popular choice is the Chebyshev polynomials, you can also use Legendre or Lagrange polynomials, but any basis will do. The more terms in the series expansion/approximation, the more accurate your solution will be. b) By autodiff (or just hard-coded derivative rules), substitute u(x)=iφiϕi(x)u(x) = \sum_i \varphi_i \phi_i(\mathbf{x}) into the ordinary/partial differential equation in question where the ordinary/partial differential equation is written in the form F(u,u,2u)=0F(u, \nabla u, \nabla^2 u) = 0 and FF is some combination of linear and nonlinear operators. This substitution will result in a system of (possibly nonlinear) equations in the form G(x)=0\mathbf{G}(\mathbf{x}) = 0. c) Solve this system of homogenous equations either with a linear algebra solver or Newton’s method for nonlinear