# Local truncation error of Crank-Nicolson for PDE $u_t+au_x = 0$

Exercise 4: The Crank-Nicolson scheme for $$u_t + a u_x = 0$$ is given by $$\frac{U_{j,n+1}-U_{j,n}}{\Delta t} + \frac{a}{2}\frac{D_xU_{j,n}}{2\Delta x} + \frac{a}{2}\frac{D_xU_{j,n+1}}{2\Delta x} = 0 .$$ Show that the LTE is given by $$\mathcal{L}_\Delta u = au_{xxx} \left(\frac{1}{6} + \frac{p^2}{12}\right) {\Delta x}^2 + O({\Delta x}^3,{\Delta t}^3) ,$$ where $$p = a{\Delta t}/{\Delta x}$$. Find the amplification factor and find the conditions for stability.

I am just trying to work out the LTE of the Crank-Nicolson scheme, however i do not get the same answers the book. Here is my working if anyone could have a look and tell me what i am doing wrong, thank you.

The scheme $$u_j^{n+1} = u_j^n -\frac{1}{4}(u_{j+1}^n -u_{j-1}^{n}+ u_{j+1}^{n+1}-u_{j-1}^{n+1})$$ rewrites as $$\frac{(u(x,t+\Delta t) - u(x.t)}{\Delta t} + \frac{a}{4 \Delta x} [ u(x+\Delta x,t) - u(x-\Delta x ,t) + u(x+ \Delta x, t+ \Delta t)- u ( x-\Delta x , t+\Delta t)$$ Expanding using Taylor series, I get $$u_t + \frac{1}{2} u_{tt} \Delta t + \frac{1}{6}u_{ttt} \Delta t^{2} + O(\Delta t^{3})$$ and similarly for the $$x$$ and $$t$$. I get $$\frac{a}{4 \Delta x} [ u(x,t) + u_x \Delta + \frac{1}{2} u_{xx} \Delta x^2 + \frac{1}{6} u_{xxx} \Delta x^{3} + O(\Delta x ^{4})- (u(x,t)-u_{x} \Delta x......)]$$ after some simplification i get the even terms remaining.. $$\frac{a}{2}u_{x} + \frac{au_{xxx}\Delta x^{2}}{12} + O(\Delta x^{3})$$ similarly for the last expansion. And $$t$$ and $$x$$ together, i get $$\frac{a}{2}u_{x} + \frac{a}{2} u_{xt} \Delta t + o(\Delta t^{2}) + \frac{a}{12}u_{xxx} \Delta x^{2}$$ Putting all these terms back into the equation and using $$u_{t} - = -au_{x}$$, $$u_{tt} = -au_{xt}$$, I am left with $$\frac{1}{6} u_{ttt} \Delta t^{2} + \frac{1}{6} a u_{xxx} \Delta x^{2} + O( \Delta t^{3} \Delta x^{3})$$. However the answer in the book is $$au_{xxx}(\frac{1}{6} + \frac{p^2}{12} )\Delta x^{2}$$.

• Its notes from lecturer – italy Feb 15 at 19:38
• Can you share the notes? – Mikey Spivak Feb 16 at 3:24
• sure, I have added it in the original post. – italy Feb 16 at 22:05

Let us write the Crank-Nicolson method for the linear advection equation $$u_t + au_x = 0$$ by averaging forward and backward Euler time-integration and by using centered spatial differences: $$\frac{u_{j}^{n+1} - u_j^n}{\Delta t} = -\frac{a}{2}\left(\frac{u_{j+1}^n - u_{j-1}^n}{2\Delta x} + \frac{u_{j+1}^{n+1} - u_{j-1}^{n+1}}{2\Delta x}\right) , \qquad u_j^n \simeq u(j\Delta x, n\Delta t) . \tag{1}$$ Thus, the scheme reads $$u_{j}^{n+1} = u_j^n - \frac{1}{4} p\big(u_{j+1}^n - u_{j-1}^n + u_{j+1}^{n+1} - u_{j-1}^{n+1}\big) = 0$$, where $$p = {a \Delta t}/{\Delta x}$$ denotes the Courant number. To perform the local truncation error analysis, we need to expand the smooth function $$u$$ as a Taylor series in two variables in the vicinity of $$(x, t)$$. Doing so at the third order, we have \begin{aligned} v &= u + h u_x + k u_t + \tfrac{1}{2} \left( h^2 u_{xx} + 2 hk u_{xt} + k^2 u_{tt}\right) \\ &+ \tfrac{1}{6} \left( h^3 u_{xxx} + 3 h^2 k u_{xxt} + 3 h k^2 u_{xtt} + k^3 u_{ttt}\right) + O(h^4 + k^4) \end{aligned} with the notation $$v(x,t) = u(x+h, t+k)$$ for the steps $$h \in \lbrace{0, \pm\Delta x}\rbrace$$ and $$k \in \lbrace{0,\Delta t}\rbrace$$. Assuming that $$u$$ satisfies the PDE $$u_t = -au_x$$, we replace time-derivatives by spatial derivatives as follows $$v = u + (h-ak)u_x + \tfrac{1}{2} ( h-ak)^2 u_{xx} + \tfrac{1}{6} ( h-ak)^3 u_{xxx} + O(h^4 + k^4) .$$ For a fixed value of the Courant number, we obtain the following expressions to be substituted in the numerical scheme $$(1)$$: \begin{aligned} v_{j}^{n+1} &= u - p\Delta x\,u_x + \tfrac{1}{2}(p\Delta x)^2 u_{xx} - \tfrac{1}{6} (p\Delta x)^3 u_{xxx} + O(\Delta x^4) \\ v_j^n &= u \\ v_{j\pm 1}^{n} &= u \pm \Delta x\,u_x + \tfrac{1}{2} \Delta x^2 u_{xx} \pm \tfrac{1}{6} \Delta x^3 u_{xxx} + O(\Delta x^4) \\ v_{j\pm 1}^{n+1} &= u + (\pm 1 -p)\Delta x\, u_x + \tfrac{1}{2} ( \pm 1-p)^2\Delta x^2 u_{xx} + \tfrac{1}{6} ( \pm 1 -p)^3\Delta x^3 u_{xxx} + O(\Delta x^4) \end{aligned} The divided finite-difference operators become \begin{aligned} \frac{v_{j}^{n+1} - v_j^n}{\Delta t} &= {-a} u_x + \tfrac{1}{2}pau_{xx} \Delta x - \tfrac{1}{6} p^2 au_{xxx} \Delta x^2 + O(\Delta x^3) \, , \\ \frac{v_{j+1}^{n} - v_{j-1}^n}{2\Delta x} &= u_x + \tfrac{1}{6} u_{xxx} \Delta x^2 + O(\Delta x^3) \, , \\ \frac{v_{j+1}^{n+1} - v_{j-1}^{n+1}}{2\Delta x} &= u_x - pu_{xx}\Delta x + \tfrac{1}{6} (1 + {3}p^2) u_{xxx} \Delta x^2 + O(\Delta x^3) \end{aligned} leading to the local truncation error $$a u_{xxx} \big({\tfrac{1}{6}} + \tfrac{1}{12} p^2\big) \Delta x^2 + O(\Delta x^3)$$.

• I have doubt. Why do we have to show the truncatiom error has that form. Isnt $(constan)* \Delta x^2 + O( \Delta x^3) = O( \Delta x^2)$ ?? – Mikey Spivak Feb 15 at 17:06
• I see! Also, are you using the upper index as the spatial derivative dx? In this LTE problems, how do we know when to truncate the taylor expansion? – Mikey Spivak Feb 15 at 17:17
• I keep getting $O(\Delta t) + O(\Delta x^2)$ for the local truncation error. – James Feb 16 at 2:49
• @Harry49 See my derivation below so you can see why I argue as so – James Feb 16 at 2:54
• @JimmySabater Answer edited! – Harry49 Feb 18 at 10:18

$$\frac{ u_k^{n+1} - u_k^n }{\Delta t} + \frac{a}{2} \left( \frac{ u_{k+1}^{n+1} - u_{k-1}^{n+1} }{2 \Delta x} + \frac{ u_{k+1}^{n} - u_{k-1}^{n} }{2 \Delta x} \right) =0$$

Let $$v_k^n = v( k \Delta x, n \Delta t)$$ be exact solution. We proceed as above by first expanding each term in Taylor series. Since

$$v_k^{n+1} = v_k^n + (v_t)_k^n \Delta t + (v_{tt})_k^n \frac{ \Delta t^2 }{2} + (v_{ttt})_k^n \frac{ \Delta t^3 }{6} + O(\Delta t^4)$$

Thus,

$$$$\frac{ v_k^{n+1} - v_k^n }{\Delta t} = (v_t)_k^n + (v_{tt})_k^n \frac{ \Delta t}{2} + (v_{ttt})_k^n \frac{ \Delta t^2 }{6} + O(\Delta t^3)$$$$

We use taylor series for functions of two variables to expand the terms $$u_{k \pm 1}^{n + 1}$$. We have

$$v_{k \pm 1}^{n+1} = v_k^n \pm (v_x)_k^n \Delta x + (v_t)_k^n \Delta t + \frac{1}{2}[ ( v_{xx})_k^n \Delta x^2 \pm 2 \Delta x \Delta t (v_{xt} )_k^n + (v_{tt}) \Delta t^2 ] +$$ $$+ \frac{1}{6} [ \pm (v_{xxx})_k^n \Delta x^3 + (v_{xxt})_k^n 3 \Delta x^2 \Delta t \pm (v_{xtt})_k^n 3 \Delta x \Delta t^2 + (u_{ttt} )_k^n \Delta t^3 ] + O(\Delta t^4) + O(\Delta x^4)$$

after adding up everything we obtain

$$(v_t)_k^n + (v_{tt})_k^n \frac{ \Delta t}{2} + O(\Delta t^2) + a (v_x)_k^n + \frac{a}{2} \Delta t \Delta x (v_{xt})_k^n + \frac{ a \Delta x^2 }{12 } (v_{xxx})_k^n + \frac{a}{4} (v_{xtt})_k^n \Delta t^2 + O(\Delta x^3) + O( \Delta t^4 / \Delta x )$$

and once we do $$\nu = a \Delta t / \Delta x$$ we see cancellations

• Use the PDE $v_t = -av_x$ to replace time-derivatives by spatial derivatives. – Harry49 Feb 18 at 10:09