X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=tridiagonal.m;fp=tridiagonal.m;h=ba99b6375c1bfa0bf9aa7dbce49c262ec30ba67f;hp=0000000000000000000000000000000000000000;hb=b49076a1d3f7f9d7830a4da5d9958636b9e5d903;hpb=b89ed48b92e5b38b7c8df70c12e4b8cc275628df diff --git a/tridiagonal.m b/tridiagonal.m new file mode 100644 index 0000000..ba99b63 --- /dev/null +++ b/tridiagonal.m @@ -0,0 +1,25 @@ +function A = tridiagonal(integerN, x, y, z) + % + % Construct the integerN x integerN (square) tridiagonal matrix + % diag(x,y,z). + % + % INPUT: + % + % - ``integerN`` -- The dimensions of the resulting matrix. + % + % - ``x`` -- The value on the subdiagonal. + % + % - ``y`` -- The value on the diagonal. + % + % - ``z`` -- The value on the superdiagonal. + % + if (integerN < 0) + A = NA; + return; + end + + sub_diag = repmat(x, 1, integerN-1); + on_diag = repmat(y, 1, integerN); + super_diag = repmat(z, 1, integerN-1); + A = diag(on_diag) + diag(super_diag, 1) + diag(sub_diag, -1); +end