Parts of Code for the Crank-Nicolson Scheme
We can code in an efficient way the Crank-Nicolson algortihm by first multplying the matrix
˜Vj−1=(2ˆI−αˆB)Vj−1,
with our previous vector
Vj−1 using the matrix-vector multiplication algorithm for a
tridiagonal matrix, as done in the forward-Euler scheme. Thereafter we can solve the equation
(2ˆI+αˆB)Vj=˜Vj−1,
using our method for systems of linear equations with a tridiagonal matrix, as done for the backward Euler scheme.