comparison scripts/linear-algebra/istril.m @ 18900:49961d67e4b9

Add new matrix functions (isdiag, isbanded, istril, istriu) (bug #42688). * NEWS: Announce new functions. * scripts/linear-algebra/module.mk: Add new functions to build system. * scripts/linear-algebra/isdiag.m: New function. * scripts/linear-algebra/isbanded.m: New function. * scripts/linear-algebra/istril.m: New function. * scripts/linear-algebra/istriu.m: New function. * numbers.txi: Add new functions to manual.
author Massimiliano Fasi <massimiliano.fasi@gmail.com>
date Sat, 05 Jul 2014 10:09:56 +0200
parents
children 9addb5ad9426
comparison
equal deleted inserted replaced
18899:3d9e503aea2c 18900:49961d67e4b9
1 ## Copyright (C) 2014 Massimiliano Fasi
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} istril (@var{x})
21 ## Return true if @var{x} is a lower triangular matrix.
22 ##
23 ## A lower triangular matrix has nonzero entries only on the main diagonal
24 ## and below.
25 ## @seealso{istriu, isbanded, isdiag, tril}
26 ## @end deftypefn
27
28 ## Author: Massimiliano Fasi
29
30 function retval = istril (A)
31
32 if (nargin != 1)
33 print_usage ();
34 endif
35
36 retval = (isnumeric (A) || islogical (A)) && ndims (A) == 2;
37 if (retval)
38 [i, j] = find (A);
39 retval = all (i >= j);
40 endif
41
42 endfunction
43
44
45 %!assert (! istril ("string"))
46 %!assert (istril ([]))
47 %!assert (! istril (zeros (2,2,2)))
48
49 %!assert (istril (1))
50 %!assert (! istril ([1, 1]))
51 %!assert (istril ([1; 1]))
52 %!assert (istril (eye (10)))
53 %!assert (istril (speye (100)))
54
55 %!assert (istril (tril (randn (10))))
56 %!assert (! istril (randn (10)))
57
58 %% Test input validation
59 %!error istril ()
60 %!error istril (1,2)
61