changeset 18880:3d33fe79816c

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.
author Rik <rik@octave.org>
date Thu, 19 Jun 2014 10:35:39 -0700
parents 30d8501a857a
children aa9ca67f09fb
files scripts/special-matrix/gallery.m
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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.