1 function A = tridiagonal(integerN, x, y, z)
3 % Construct the integerN x integerN (square) tridiagonal matrix
8 % - ``integerN`` -- The dimensions of the resulting matrix.
10 % - ``x`` -- The value on the subdiagonal.
12 % - ``y`` -- The value on the diagonal.
14 % - ``z`` -- The value on the superdiagonal.
18 % - ``A`` -- an integerN-by-integerN square matrix.
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);