]> gitweb.michael.orlitzky.com - octave.git/blob - tridiagonal.m
Add ellipses on a multi-line statement.
[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 % OUTPUT:
17 %
18 % - ``A`` -- an integerN-by-integerN square matrix.
19 %
20 if (integerN < 0)
21 A = NA;
22 return;
23 end
24
25 sub_diag = repmat(x, 1, integerN-1);
26 on_diag = repmat(y, 1, integerN);
27 super_diag = repmat(z, 1, integerN-1);
28 A = diag(on_diag) + diag(super_diag, 1) + diag(sub_diag, -1);
29 end