BVPs Relaxation methods

Step 1

Discretize the domain into a finite difference grid. That is, a set of discrete points upon which we will find the solution. * Normally, but not always, put points on the boundary. * Here, we’ll consider a uniform grid for now.

|               :       :             |
O     O     O   :   O   :   O    O    O
|          i-1      i      i+1        |
x=0                                  x=R 

Step 2

Approximate the exact derivatives in the ODE by finite difference approximations (FDS)

$$y_i^{\prime\prime} = \left(\frac{d^2y}{dx^2}\right)_i$$$$= \frac{y_{i+1/2}^{\prime}-y_{i-1/2}^{\prime}}{\Delta x} = \frac{\frac{y_{i+1}-y_i}{\Delta x}-\frac{y_i - y_{i-1}}{\Delta x}}{\Delta x}$$

$$= \frac{y_{i+1}-2y_i+y_{i-1}}{\Delta x^2}.$$ $$y_i^{\prime} = \left(\frac{dy}{dx}\right)_i$$$$=\frac{y_{i+1}-y_{i-1}}{2\Delta x}.$$

Step 3

Substitute the FDAs into the ODE to get the finite difference equation (FDE).

$$\frac{y_{i+1} - 2y_i + y_{i-1}}{\Delta x^2} + P_i\frac{y_{i+1}-y_{i-1}}{2\Delta x} + Q_iy_i = F_i.$$

Step 4

Solve the system of algebraic equations.

$$\left(\frac{1}{\Delta x^2} - \frac{P_i}{2\Delta x}\right) y_{i-1} + \left(Q_i - \frac{2}{\Delta x^2}\right)y_i + \left(\frac{1}{\Delta x^2} + \frac{P_i}{2\Delta x}\right)y_{i+1} = F_i.$$ $$l_i y_{i-1} + a_iy_i + u_iy_{i+1} = b_i.$$ grid equation

Shooting versus relaxation

Example

Solve the following with Dirichlet boundary conditions.

$$y^{\prime\prime} + Py^{\prime} + Qy = F.$$
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from thomas import thomas
ngrd = 21
Ldom = 1.0
yL   = 0.5
yR   = 0.0
P    = np.full(ngrd, 4.0)
Q    = np.zeros(ngrd)
F    = np.full(ngrd, -10.0)
x  = np.linspace(0, Ldom, ngrd)
dx = x[1] - x[0]

l = 1.0/dx**2 - P/2/dx
a = Q         - 2/dx**2
u = 1.0/dx**2 + P/2/dx
b = F
b[1] -= l[1]*yL
b[ngrd-2] -= u[ngrd-2]*yR
y = thomas(a[1:-1], u[1:-1], l[1:-1], b[1:-1])

y = np.insert(y,0,yL)
y = np.append(y,yR)
plt.rc('font', size=14)
plt.plot(x,y, 'o-')
plt.xlabel('x')
plt.ylabel('y');
solution