1887
|
1 # Copyright (C) 1996 John W. Eaton |
245
|
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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, write to the Free |
1315
|
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
245
|
18 |
4
|
19 function retval = tril (x, k) |
|
20 |
|
21 # usage: triu (x, k) |
|
22 # |
|
23 # Return the lower triangular part of x above the k-th diagonal. If |
|
24 # the second argument is omitted, k = 0 is assumed. |
|
25 # |
|
26 # See also: triu, diag |
|
27 |
|
28 if (nargin > 0) |
|
29 [nr, nc] = size (x); |
1083
|
30 retval = zeros (nr, nc); |
4
|
31 endif |
|
32 |
|
33 if (nargin == 1) |
|
34 k = 0; |
|
35 elseif (nargin == 2) |
1083
|
36 if ((k > 0 && k > nc) || (k < 0 && k < -nr)) |
1518
|
37 error ("tril: requested diagonal out of range"); |
4
|
38 endif |
|
39 else |
904
|
40 usage ("tril (x [, k])"); |
4
|
41 endif |
|
42 |
1083
|
43 for j = 1 : min (nc, nc + abs (k)) |
|
44 nr_limit = max (1, j-k); |
|
45 retval (nr_limit:nr, j) = x (nr_limit:nr, j); |
4
|
46 endfor |
|
47 |
|
48 endfunction |