PDF (letter size)

## Notes on some numerical schemes

May 26, 2022   Compiled on May 26, 2022 at 9:15pm

### 1 Introduction

These are notes to describe some numerical schemes.

#### 1.1 Centered diﬀerence for 1D wave PDE

Here we want to solve $$u_{tt}=c^{2}u_{xx}$$ in 1D ﬁnite domain $$0<x<L$$ and $$t>0$$, with boundary conditions $$u\left ( 0,t\right ) =f\left ( t\right ) ,u\left ( L,t\right ) =g\left ( t\right )$$ and initial position $$u\left ( x,0\right ) =\alpha \left ( x\right )$$ and initial velocity $$\frac {\partial u\left ( x,0\right ) }{\partial t}=\beta \left ( x\right )$$.

Centered diﬀerence is used.

At each internal node $$j$$ we have the following ﬁnite diﬀerence represenation of $$u_{tt}=c^{2}u_{xx}$$

To handle initial conditions, initial velocity is used to solve for $$u_{j}^{-1}$$

This gives all the information needed to ﬁnd the matrices to use. Let $$k=\Delta t$$. From Eq(1) \begin {align*} \frac {u_{j}^{1}-u_{j}^{-1}}{2k} & =\alpha \\ u_{j}^{-1} & =u_{j}^{1}-2k\alpha \end {align*}

Substituting this in Eq(2) gives\begin {align*} \frac {\left ( u_{j}^{1}-2k\alpha \right ) -2u_{j}^{0}+u_{j}^{1}}{k^{2}} & =c^{2}\frac {u_{j-1}^{0}-2u_{j}^{0}+u_{j+1}^{0}}{h^{2}}\\ 2u_{j}^{1} & =\frac {k^{2}c^{2}}{h^{2}}\left ( u_{j-1}^{0}-2u_{j}^{0}+u_{j+1}^{0}\right ) +2u_{j}^{0}+2k\alpha \\ u_{j}^{1} & =\frac {1}{2}\frac {k^{2}c^{2}}{h^{2}}\left ( u_{j-1}^{0}-2u_{j}^{0}+u_{j+1}^{0}\right ) +u_{j}^{0}+k\alpha \end {align*}

Therefore for $$n=1$$ only and for $$j=1\cdots N$$ where $$N$$ is number of nodes$\begin {pmatrix} u_{1}^{1}\\ u_{2}^{1}\\ u_{3}^{1}\\ u_{4}^{1}\\ u_{5}^{1}\end {pmatrix} =\frac {1}{2}\frac {k^{2}c^{2}}{h^{2}}\begin {pmatrix} 1 & 0 & 0 & 0 & 0\\ 1 & -2 & 1 & 0 & 0\\ 0 & 1 & -2 & 1 & 0\\ 0 & 0 & 1 & -2 & 1\\ 0 & 0 & 0 & 0 & 1 \end {pmatrix}\begin {pmatrix} u_{1}^{0}\\ u_{2}^{0}\\ u_{3}^{0}\\ u_{4}^{0}\\ u_{5}^{0}\end {pmatrix} +\begin {pmatrix} u_{1}^{0}\\ u_{2}^{0}\\ u_{3}^{0}\\ u_{4}^{0}\\ u_{5}^{0}\end {pmatrix} +k\alpha$ Where $$\begin {pmatrix} u_{1}^{0}\\ u_{2}^{0}\\ u_{3}^{0}\\ u_{4}^{0}\\ u_{5}^{0}\end {pmatrix}$$ is known and comes from boundary and initial conditions. $$u_{1}^{0}$$ is left B.C. and $$u_{N}^{0}$$ comes from right B.C. and $$u_{2}^{0}\cdots u_{N-1}^{0}$$ comes from initial conditions $$u\left ( x,0\right )$$. Now, for $$n=2$$ or higher times\begin {align*} \frac {u_{j}^{n-1}-2u_{j}^{n}+u_{j}^{n+1}}{k^{2}} & =c^{2}\frac {u_{j-1}^{n}-2u_{j}^{n}+u_{j+1}^{n}}{h^{2}}\\ u_{j}^{n-1}-2u_{j}^{n}+u_{j}^{n+1} & =\frac {k^{2}c^{2}}{h^{2}}\left ( u_{j-1}^{n}-2u_{j}^{n}+u_{j+1}^{n}\right ) \\ u_{j}^{n+1} & =\frac {k^{2}c^{2}}{h^{2}}\left ( u_{j-1}^{n}-2u_{j}^{n}+u_{j+1}^{n}\right ) +2u_{j}^{n}-u_{j}^{n-1} \end {align*}

In Matrix form$\begin {pmatrix} u_{1}^{n+1}\\ u_{2}^{n+1}\\ u_{3}^{n+1}\\ u_{4}^{n+1}\\ u_{5}^{n+1}\end {pmatrix} =\frac {k^{2}c^{2}}{h^{2}}\begin {pmatrix} 1 & 0 & 0 & 0 & 0\\ 1 & -2 & 1 & 0 & 0\\ 0 & 1 & -2 & 1 & 0\\ 0 & 0 & 1 & -2 & 1\\ 0 & 0 & 0 & 0 & 1 \end {pmatrix}\begin {pmatrix} u_{1}^{n}\\ u_{2}^{n}\\ u_{3}^{n}\\ u_{4}^{n}\\ u_{5}^{n}\end {pmatrix} +2\begin {pmatrix} u_{1}^{n}\\ u_{2}^{n}\\ u_{3}^{n}\\ u_{4}^{n}\\ u_{5}^{n}\end {pmatrix} -\begin {pmatrix} u_{1}^{n-1}\\ u_{2}^{n-1}\\ u_{3}^{n-1}\\ u_{4}^{n-1}\\ u_{5}^{n-1}\end {pmatrix}$ So to ﬁnd $$u_{j}^{n+1}$$ we need to know the last time step solution and also the solution for the step before that.

Small Mathematica was written to implement the above scheme. Here is screen show of the GUI for one example.

The Mathematica notebook of the above is here

The following is an animation of $$u_{tt}=4u_{xx}$$ with ﬁxed ends, and string length $$L=5$$ with initial position given by $$8x\frac {\left ( L-x\right ) ^{2}}{L^{3}}$$ and zero initial velocity. This uses $$\Delta t=0.02$$ seconds and $$30$$ grid points over the length $$5$$.

 Pause Play Restart Step forward Step back