function K = diffusion_matrix_sparse(integerN)
- ##
- ## A sparse representation of the matrix K in the advection-diffusion
- ## equation. See advection_matrix.m for details.
- ##
+ %
+ % A sparse representation of the matrix K in the advection-diffusion
+ % equation. See advection_matrix.m for details.
+ %
if (integerN < 2)
K = NA;
return
end
- ## The negative ones directly above the diagonal.
+ % The negative ones directly above the diagonal.
top = [ [zeros(integerN-1, 1), -speye(integerN-1)]; ...
zeros(1, integerN)];
- ## The negative ones directly below the diagonal.
+ % The negative ones directly below the diagonal.
bottom = [ [zeros(1, integerN-1); ...
-speye(integerN-1) ], zeros(integerN, 1)];
- ## Combine the top and bottom.
+ % Combine the top and bottom.
K = top + bottom + 2*speye(integerN);
- ## Fill in the entries in the corner.
+ % Fill in the entries in the corner.
K(1, integerN) = -1;
K(integerN, 1) = -1;
end