]> gitweb.michael.orlitzky.com - octave.git/blob - tridiagonal.m
Add tridiagonal() and its tests.
[octave.git] / tridiagonal.m
1 function A = tridiagonal(integerN, x, y, z)
2 %
3 % Construct the integerN x integerN (square) tridiagonal matrix
4 % diag(x,y,z).
5 %
6 % INPUT:
7 %
8 % - ``integerN`` -- The dimensions of the resulting matrix.
9 %
10 % - ``x`` -- The value on the subdiagonal.
11 %
12 % - ``y`` -- The value on the diagonal.
13 %
14 % - ``z`` -- The value on the superdiagonal.
15 %
16 if (integerN < 0)
17 A = NA;
18 return;
19 end
20
21 sub_diag = repmat(x, 1, integerN-1);
22 on_diag = repmat(y, 1, integerN);
23 super_diag = repmat(z, 1, integerN-1);
24 A = diag(on_diag) + diag(super_diag, 1) + diag(sub_diag, -1);
25 end