Mercurial > octave-nkf
comparison scripts/special-matrix/gallery.m @ 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 | 9ac2357f19bc |
children | 0850b5212619 |
comparison
equal
deleted
inserted
replaced
18877:30d8501a857a | 18880:3d33fe79816c |
---|---|
2518 ## T = diag (x, -1) + diag (y) + diag (z, 1); # For non-sparse matrix. | 2518 ## T = diag (x, -1) + diag (y) + diag (z, 1); # For non-sparse matrix. |
2519 n = numel (y); | 2519 n = numel (y); |
2520 T = spdiags ([[x;0] y [0;z]], -1:1, n, n); | 2520 T = spdiags ([[x;0] y [0;z]], -1:1, n, n); |
2521 endfunction | 2521 endfunction |
2522 | 2522 |
2523 function t = triw (n, alpha = -1, k = -1) | 2523 function t = triw (n, alpha = -1, k = n(end) - 1) |
2524 ## TRIW Upper triangular matrix discussed by Wilkinson and others. | 2524 ## TRIW Upper triangular matrix discussed by Wilkinson and others. |
2525 ## TRIW(N, ALPHA, K) is the upper triangular matrix with ones on | 2525 ## TRIW(N, ALPHA, K) is the upper triangular matrix with ones on |
2526 ## the diagonal and ALPHAs on the first K >= 0 superdiagonals. | 2526 ## the diagonal and ALPHAs on the first K >= 0 superdiagonals. |
2527 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2) and | 2527 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2) and |
2528 ## upper trapezoidal. | 2528 ## upper trapezoidal. |
2554 error ("gallery: 1 to 3 arguments are required for triw matrix."); | 2554 error ("gallery: 1 to 3 arguments are required for triw matrix."); |
2555 elseif (! isnumeric (n) || all (numel (n) != [1 2])) | 2555 elseif (! isnumeric (n) || all (numel (n) != [1 2])) |
2556 error ("gallery: N must be a 1 or 2 elements vector for triw matrix."); | 2556 error ("gallery: N must be a 1 or 2 elements vector for triw matrix."); |
2557 elseif (! isscalar (alpha)) | 2557 elseif (! isscalar (alpha)) |
2558 error ("gallery: ALPHA must be a scalar for triw matrix."); | 2558 error ("gallery: ALPHA must be a scalar for triw matrix."); |
2559 elseif (! isscalar (k) || ! isnumeric (k) || fix (k) != k) | 2559 elseif (! isscalar (k) || ! isnumeric (k) || fix (k) != k || k < 0) |
2560 error ("gallery: K must be a numeric integer for triw matrix."); | 2560 error ("gallery: K must be a numeric integer >= 0 for triw matrix."); |
2561 endif | 2561 endif |
2562 | 2562 |
2563 m = n(1); # Parameter n specifies dimension: m-by-n. | 2563 m = n(1); # Parameter n specifies dimension: m-by-n. |
2564 n = n(end); | 2564 n = n(end); |
2565 | 2565 |