1 function K = diffusion_matrix_sparse(integerN)
3 % A sparse representation of the matrix K in the advection-diffusion
4 % equation. See advection_matrix.m for details.
12 % The negative ones directly above the diagonal.
13 top = [ [zeros(integerN-1, 1), -speye(integerN-1)]; ...
16 % The negative ones directly below the diagonal.
17 bottom = [ [zeros(1, integerN-1); ...
18 -speye(integerN-1) ], zeros(integerN, 1)];
20 % Combine the top and bottom.
21 K = top + bottom + 2*speye(integerN);
23 % Fill in the entries in the corner.