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. % % OUTPUT: % % - ``A`` -- an integerN-by-integerN square matrix. % 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