Appendix: Useful formulas

Finite difference operator notation

u(tn)[Dtu]n=un+12un12Δt
u(tn)[D2tu]n=un+1un12Δt
u(tn)=[Dtu]n=unun1Δt
u(tn)[D+tu]n=un+1unΔt
u(tn+θ)=[ˉDtu]n+θ=un+1unΔt
u(tn)[D2tu]n=3un4un1+un22Δt
u
\tag{616} u(t_{n+\frac{1}{2}}) \approx \lbrack \overline{u}^{t}\rbrack^{n+\frac{1}{2}} = \frac{1}{2}(u^{n+1} + u^n)
\tag{617} u(t_{n+\frac{1}{2}})^2 \approx \lbrack \overline{u^2}^{t,g}\rbrack^{n+\frac{1}{2}} = u^{n+1}u^n
\tag{618} u(t_{n+\frac{1}{2}}) \approx \lbrack \overline{u}^{t,h}\rbrack^{n+\frac{1}{2}} = \frac{2}{\frac{1}{u^{n+1}} + \frac{1}{u^n}}
\tag{619} u(t_{n+\theta}) \approx \lbrack \overline{u}^{t,\theta}\rbrack^{n+\theta} = \theta u^{n+1} + (1-\theta)u^n ,
\tag{620} \qquad t_{n+\theta}=\theta t_{n+1} + (1-\theta)t_{n-1}

Some may wonder why \theta is absent on the right-hand side of (613). The fraction is an approximation to the derivative at the point t_{n+\theta}=\theta t_{n+1} + (1-theta) t_{n}.

Truncation errors of finite difference approximations

{u_{\small\mbox{e}}}'(t_n) = [D_t{u_{\small\mbox{e}}}]^n + R^n = \frac{{u_{\small\mbox{e}}}^{n+\frac{1}{2}} - {u_{\small\mbox{e}}}^{n-\frac{1}{2}}}{\Delta t} +R^n\nonumber,
\tag{621} R^n = -\frac{1}{24}{u_{\small\mbox{e}}}'''(t_n)\Delta t^2 + {\cal O}(\Delta t^4)
{u_{\small\mbox{e}}}'(t_n) = [D_{2t}{u_{\small\mbox{e}}}]^n +R^n = \frac{{u_{\small\mbox{e}}}^{n+1} - {u_{\small\mbox{e}}}^{n-1}}{2\Delta t} + R^n\nonumber,
\tag{622} R^n = -\frac{1}{6}{u_{\small\mbox{e}}}'''(t_n)\Delta t^2 + {\cal O}(\Delta t^4)
{u_{\small\mbox{e}}}'(t_n) = [D_t^-{u_{\small\mbox{e}}}]^n +R^n = \frac{{u_{\small\mbox{e}}}^{n} - {u_{\small\mbox{e}}}^{n-1}}{\Delta t} +R^n\nonumber,
\tag{623} R^n = -\frac{1}{2}{u_{\small\mbox{e}}}''(t_n)\Delta t + {\cal O}(\Delta t^2)
{u_{\small\mbox{e}}}'(t_n) = [D_t^+{u_{\small\mbox{e}}}]^n +R^n = \frac{{u_{\small\mbox{e}}}^{n+1} - {u_{\small\mbox{e}}}^{n}}{\Delta t} +R^n\nonumber,
\tag{624} R^n = \frac{1}{2}{u_{\small\mbox{e}}}''(t_n)\Delta t + {\cal O}(\Delta t^2)
{u_{\small\mbox{e}}}'(t_{n+\theta}) = [\bar D_t{u_{\small\mbox{e}}}]^{n+\theta} +R^{n+\theta} = \frac{{u_{\small\mbox{e}}}^{n+1} - {u_{\small\mbox{e}}}^{n}}{\Delta t} +R^{n+\theta}\nonumber,
R^{n+\theta} = -\frac{1}{2}(1-2\theta){u_{\small\mbox{e}}}''(t_{n+\theta})\Delta t + \frac{1}{6}((1 - \theta)^3 - \theta^3){u_{\small\mbox{e}}}'''(t_{n+\theta})\Delta t^2 + \nonumber
\tag{625} \quad {\cal O}(\Delta t^3)
{u_{\small\mbox{e}}}'(t_n) = [D_t^{2-}{u_{\small\mbox{e}}}]^n +R^n = \frac{3{u_{\small\mbox{e}}}^{n} - 4{u_{\small\mbox{e}}}^{n-1} + {u_{\small\mbox{e}}}^{n-2}}{2\Delta t} +R^n\nonumber,
\tag{626} R^n = \frac{1}{3}{u_{\small\mbox{e}}}'''(t_n)\Delta t^2 + {\cal O}(\Delta t^3)
{u_{\small\mbox{e}}}''(t_n) = [D_tD_t {u_{\small\mbox{e}}}]^n +R^n = \frac{{u_{\small\mbox{e}}}^{n+1} - 2{u_{\small\mbox{e}}}^{n} + {u_{\small\mbox{e}}}^{n-1}}{\Delta t^2} +R^n\nonumber,
\tag{627} R^n = -\frac{1}{12}{u_{\small\mbox{e}}}''''(t_n)\Delta t^2 + {\cal O}(\Delta t^4)
{u_{\small\mbox{e}}}(t_{n+\theta}) = [\overline{{u_{\small\mbox{e}}}}^{t,\theta}]^{n+\theta} +R^{n+\theta} = \theta {u_{\small\mbox{e}}}^{n+1} + (1-\theta){u_{\small\mbox{e}}}^n +R^{n+\theta},\nonumber
\tag{628} R^{n+\theta} = -\frac{1}{2}{u_{\small\mbox{e}}}''(t_{n+\theta})\Delta t^2\theta (1-\theta) + {\cal O}(\Delta t^3) {\thinspace .}

Finite differences of exponential functions

Complex exponentials

Let u^n = \exp{(i\omega n\Delta t)} = e^{i\omega t_n}.

\tag{629} [D_tD_t u]^n = u^n \frac{2}{\Delta t}(\cos \omega\Delta t - 1) = -\frac{4}{\Delta t}\sin^2\left(\frac{\omega\Delta t}{2}\right),
\tag{630} [D_t^+ u]^n = u^n\frac{1}{\Delta t}(\exp{(i\omega\Delta t)} - 1),
\tag{631} [D_t^- u]^n = u^n\frac{1}{\Delta t}(1 - \exp{(-i\omega\Delta t)}),
\tag{632} [D_t u]^n = u^n\frac{2}{\Delta t}i\sin{\left(\frac{\omega\Delta t}{2}\right)},
\begin{align}\begin{aligned}\tag{633} [D_{2t} u]^n = u^n\frac{1}{\Delta t}i\sin{(\omega\Delta t)}\\ {\thinspace .}\end{aligned}\end{align}

Real exponentials

Let u^n = \exp{(\omega n\Delta t)} = e^{\omega t_n}.

\tag{634} [D_tD_t u]^n = u^n \frac{2}{\Delta t}(\cos \omega\Delta t - 1) = -\frac{4}{\Delta t}\sin^2\left(\frac{\omega\Delta t}{2}\right),
\tag{635} [D_t^+ u]^n = u^n\frac{1}{\Delta t}(\exp{(i\omega\Delta t)} - 1),
\tag{636} [D_t^- u]^n = u^n\frac{1}{\Delta t}(1 - \exp{(-i\omega\Delta t)}),
\tag{637} [D_t u]^n = u^n\frac{2}{\Delta t}i\sin{\left(\frac{\omega\Delta t}{2}\right)},
\begin{align}\begin{aligned}\tag{638} [D_{2t} u]^n = u^n\frac{1}{\Delta t}i\sin{(\omega\Delta t)}\\ {\thinspace .}\end{aligned}\end{align}

Finite differences of t^n

The following results are useful when checking if a polynomial term in a solution fulfills the discrete equation for the numerical method.

\tag{639} \lbrack D_t^+ t\rbrack^n = 1,
\tag{640} \lbrack D_t^- t\rbrack^n = 1,
\tag{641} \lbrack D_t t\rbrack^n = 1,
\tag{642} \lbrack D_{2t} t\rbrack^n = 1,
\begin{align}\begin{aligned}\tag{643} \lbrack D_{t}D_t t\rbrack^n = 0\\ {\thinspace .}\end{aligned}\end{align}

The next formulas concern the action of difference operators on a t^2 term.

\tag{644} \lbrack D_t^+ t^2\rbrack^n = (2n+1)\Delta t,
\tag{645} \lbrack D_t^- t^2\rbrack^n = (2n-1)\Delta t,
\tag{646} \lbrack D_t t^2\rbrack^n = 2n\Delta t,
\tag{647} \lbrack D_{2t} t^2\rbrack^n = 2n\Delta t,
\tag{648} \lbrack D_{t}D_t t^2\rbrack^n = 2,

Finally, we present formulas for a t^3 term:

\tag{649} \lbrack D_t^+ t^3\rbrack^n = 3(n\Delta t)^2 + 3n\Delta t^2 + \Delta t^2,
\tag{650} \lbrack D_t^- t^3\rbrack^n = 3(n\Delta t)^2 - 3n\Delta t^2 + \Delta t^2,
\tag{651} \lbrack D_t t^3\rbrack^n = 3(n\Delta t)^2 + \frac{1}{4}\Delta t^2,
\tag{652} \lbrack D_{2t} t^3\rbrack^n = 3(n\Delta t)^2 + \Delta t^2,
\tag{653} \lbrack D_{t}D_t t^3\rbrack^n = 6n\Delta t,

Application of finite difference operators to polynomials and exponential functions, resulting in the formulas above, can easily be computed by some sympy code (from the file lib.py):

from sympy import *
t, dt, n, w = symbols('t dt n w', real=True)

# Finite difference operators

def D_t_forward(u):
    return (u(t + dt) - u(t))/dt

def D_t_backward(u):
    return (u(t) - u(t-dt))/dt

def D_t_centered(u):
    return (u(t + dt/2) - u(t-dt/2))/dt

def D_2t_centered(u):
    return (u(t + dt) - u(t-dt))/(2*dt)

def D_t_D_t(u):
    return (u(t + dt) - 2*u(t) + u(t-dt))/(dt**2)


op_list = [D_t_forward, D_t_backward,
           D_t_centered, D_2t_centered, D_t_D_t]

def ft1(t):
    return t

def ft2(t):
    return t**2

def ft3(t):
    return t**3

def f_expiwt(t):
    return exp(I*w*t)

def f_expwt(t):
    return exp(w*t)

func_list = [ft1, ft2, ft3, f_expiwt, f_expwt]

To see the results, one can now make a simple loop over the different type of functions and the various operators associated with them:

for func in func_list:
    for op in op_list:
        f = func
        e = op(f)
        e = simplify(expand(e))
        print e
        if func in [f_expiwt, f_expwt]:
            e = e/f(t)
        e = e.subs(t, n*dt)
        print expand(e)
        print factor(simplify(expand(e)))