Parts of Code for the Crank-Nicolson Scheme
We can code in an efficient way the Crank-Nicolson algortihm by first multplying the matrix
$$
\begin{equation*}
\tilde{V}_{j-1}=\left(2\hat{I}-\alpha\hat{B}\right)V_{j-1},
\end{equation*}
$$
with our previous vector \( V_{j-1} \) using the matrix-vector multiplication algorithm for a
tridiagonal matrix, as done in the forward-Euler scheme. Thereafter we can solve the equation
$$
\begin{equation*}
\left(2\hat{I}+\alpha\hat{B}\right) V_{j}=
\tilde{V}_{j-1},
\end{equation*}
$$
using our method for systems of linear equations with a tridiagonal matrix, as done for the backward Euler scheme.