Mercurial > hg > octave-nkf
changeset 16980:1909e1ed63e6
gallery.m: Add 'integerdata' matrix to function.
* scripts/special-matrix/gallery.m: Add 'integerdata' matrix to function.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 13 Jul 2013 22:25:59 -0700 |
parents | 9aa293e00475 |
children | e86df0d43309 |
files | scripts/special-matrix/gallery.m |
diffstat | 1 files changed, 43 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/special-matrix/gallery.m +++ b/scripts/special-matrix/gallery.m @@ -389,8 +389,7 @@ case "grcar" , [varargout{1:n_out}] = grcar (varargin{:}); case "hanowa" , [varargout{1:n_out}] = hanowa (varargin{:}); case "house" , [varargout{1:n_out}] = house (varargin{:}); - case "integerdata" - error ("gallery: matrix %s not implemented.", name); + case "integerdata", [varargout{1:n_out}] = integerdata (varargin{:}); case "invhess" , [varargout{1:n_out}] = invhess (varargin{:}); case "invol" , [varargout{1:n_out}] = invol (varargin{:}); case "ipjfact" , [varargout{1:n_out}] = ipjfact (varargin{:}); @@ -1265,6 +1264,48 @@ endif endfunction +function A = integerdata (varargin) + + if (nargin < 3) + error ("gallery: At least 3 arguments required for integerdata matrix."); + endif + + if (isnumeric (varargin{end})) + jidx = varargin{end}; + svec = [varargin{:}]; + varargin(end) = []; + elseif (ischar (varargin{end})) + if (nargin < 4) + error (["gallery: CLASS argument requires 4 inputs " ... + "for integerdata matrix."]); + endif + jidx = varargin{end-1}; + svec = [varargin{1:end-1}]; + varargin(end-1) = []; + else + error (["gallery: J must be an integer in the range [0, 2^32-1] " ... + "for integerdata matrix"]); + endif + + if (! (isnumeric (jidx) && isscalar (jidx) + && jidx == fix (jidx) + && jidx >= 0 && jidx <= 0xFFFFFFFF)) + error (["gallery: J must be an integer in the range [0, 2^32-1] " ... + "for integerdata matrix"]); + endif + + ## Save and restore random state. Initialization done so that reproducible + ## data is available from gallery depending on the jidx and size vector. + randstate = rand ("state"); + unwind_protect + rand ("state", svec); + A = randi (varargin{:}); + unwind_protect_cleanup + rand ("state", randstate); + end_unwind_protect + +endfunction + function A = invhess (x, y) ## INVHESS Inverse of an upper Hessenberg matrix. ## INVHESS(X, Y), where X is an N-vector and Y an N-1 vector,