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.

p01: Convergence of fourth order finite differences

Let us compute the derivative of

u(x)=exp⁡(sin⁡(x)),x∈[−π,π]u(x) = \exp(\sin(x)), \qquad x \in [-\pi,\pi]

using fourth order finite difference scheme

u′(xj)≈wj=1h(112uj−2−23uj−1+23uj+1−112uj+2)u'(x_j) \approx w_j = \frac{1}{h} \left( \frac{1}{12} u_{j-2} - \frac{2}{3} u_{j-1} + \frac{2}{3} u_{j+1} - \frac{1}{12} u_{j+2} \right)

using periodic boundary conditions.

The differentiation matrix is anti-symmetric; we first construct the upper triangular part UU and get

D=1h(U−U⊤)D = \frac{1}{h} ( U - U^\top)

The matrix is stored in coo_format which is a sparse matrix format.

The error in the derivative approximation is measured as

EN=max⁡1≤j≤N∣wj−uj′∣E_N = \max_{1 \le j \le N} |w_j - u_j'|
<Figure size 640x480 with 1 Axes>

With about 4000 points, the error is of order 10-12.

Exercise

Find sixth and eigth order finite differences, implement them and make error plot as above.

Exercise

Construct the differentiation matrix using scipy.toeplitz function. You need to pass the first column and first row.