X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=advection_matrix_sparse.m;fp=advection_matrix_sparse.m;h=ce45e159d84f0d28510240ee08c145833ca8ce78;hp=0000000000000000000000000000000000000000;hb=9b1a3c694305734969d771a6e67a67123006b5ca;hpb=b39006334c16dcd7256cb7c36e88996229863e6b diff --git a/advection_matrix_sparse.m b/advection_matrix_sparse.m new file mode 100644 index 0000000..ce45e15 --- /dev/null +++ b/advection_matrix_sparse.m @@ -0,0 +1,29 @@ +function S = advection_matrix_sparse(integerN) + ## + ## Sparse version of the advection_matrix function. See + ## advection_matrix.m for details. + ## + + if (integerN < 2) + S = NA; + return + end + + ## The ones directly above the diagonal. + top = [ [zeros(integerN-1, 1), speye(integerN-1)]; ... + zeros(1, integerN)]; + + ## The ones directly below the diagonal. + bottom = [ [zeros(1, integerN-1); ... + -speye(integerN-1) ], zeros(integerN, 1)]; + + ## Combine the top and bottom. + S = top + bottom; + + ## Fill in the entries in the corner. + S(1, integerN) = -1; + S(integerN, 1) = 1; + + ## And divide the whole thing by 2. + S = (1/2)*S; +end