$$
\newcommand{\uex}{{u_{\small\mbox{e}}}}
\newcommand{\Aex}{{A_{\small\mbox{e}}}}
\newcommand{\half}{\frac{1}{2}}
\newcommand{\tp}{\thinspace .}
\newcommand{\Oof}[1]{\mathcal{O}(#1)}
\newcommand{\dfc}{\alpha} % diffusion coefficient
$$
Crank-Nicolsoon scheme written out
$$
\begin{equation}
u^{n+1}_i - \half F(u^{n+1}_{i-1} - 2u^{n+1}_i + u^{n+1}_{i+1})
= u^{n}_i + \half F(u^{n}_{i-1} - 2u^{n}_i + u^{n}_{i+1})
\end{equation}
$$
Observe:
- The unknowns are \( u^{n+1}_{i-1}, u^{n+1}_{i}, u^{n+1}_{i+1} \)
- These unknowns are coupled to each other (in a linear system)
- Must solve \( AU=b \) at each time level
Now,
$$
\begin{align}
A_{i,i-1} &= -\half F_o\\
A_{i,i} &= \half + F_o\\
A_{i,i+1} &= -\half F_o
\end{align}
$$
for internal points. For boundary points,
$$
\begin{align}
A_{0,0} &= 1\\
A_{0,1} &= 0\\
A_{N_x,N_x-1} &= 0\\
A_{N_x,N_x} &= 1
\end{align}
$$
Right-hand side:
$$
\begin{align}
b_0 &= 0\\
b_i &= u^{n-1}_i,\quad i=1,\ldots,N_x-1\\
b_{N_x} &= 0 \end{align}
$$