Word-wrap a comment.
[octave.git] / advection_matrix_sparse.m
1 function S = advection_matrix_sparse(integerN)
2 ##
3 ## Sparse version of the advection_matrix function. See
4 ## advection_matrix.m for details.
5 ##
6
7 if (integerN < 2)
8 S = NA;
9 return
10 end
11
12 ## The ones directly above the diagonal.
13 top = [ [zeros(integerN-1, 1), speye(integerN-1)]; ...
14 zeros(1, integerN)];
15
16 ## The negative ones directly below the diagonal.
17 bottom = [ [zeros(1, integerN-1); ...
18 -speye(integerN-1) ], zeros(integerN, 1)];
19
20 ## Combine the top and bottom.
21 S = top + bottom;
22
23 ## Fill in the entries in the corner.
24 S(1, integerN) = -1;
25 S(integerN, 1) = 1;
26
27 ## And divide the whole thing by 2.
28 S = (1/2)*S;
29 end