# HG changeset patch # User Rik # Date 1403199339 25200 # Node ID 3d33fe79816c07aa23a9baedf26c094f1a325a84 # Parent 30d8501a857a5bf7d693e1c0f4347a358e86fd29 gallery.m: Return correct matrix if 3rd argument is not specified. * gallery.m (triw): Change default of final argument to k=n-1, rather than k = -1. Add input validation to test that k >=0. diff -r 30d8501a857a -r 3d33fe79816c scripts/special-matrix/gallery.m --- a/scripts/special-matrix/gallery.m Wed Jun 18 13:03:27 2014 -0700 +++ b/scripts/special-matrix/gallery.m Thu Jun 19 10:35:39 2014 -0700 @@ -2520,7 +2520,7 @@ T = spdiags ([[x;0] y [0;z]], -1:1, n, n); endfunction -function t = triw (n, alpha = -1, k = -1) +function t = triw (n, alpha = -1, k = n(end) - 1) ## TRIW Upper triangular matrix discussed by Wilkinson and others. ## TRIW(N, ALPHA, K) is the upper triangular matrix with ones on ## the diagonal and ALPHAs on the first K >= 0 superdiagonals. @@ -2556,8 +2556,8 @@ error ("gallery: N must be a 1 or 2 elements vector for triw matrix."); elseif (! isscalar (alpha)) error ("gallery: ALPHA must be a scalar for triw matrix."); - elseif (! isscalar (k) || ! isnumeric (k) || fix (k) != k) - error ("gallery: K must be a numeric integer for triw matrix."); + elseif (! isscalar (k) || ! isnumeric (k) || fix (k) != k || k < 0) + error ("gallery: K must be a numeric integer >= 0 for triw matrix."); endif m = n(1); # Parameter n specifies dimension: m-by-n.