comparison scripts/general/tril.m @ 4:b4df021f796c

[project @ 1993-08-08 01:26:08 by jwe] Initial revision
author jwe
date Sun, 08 Aug 1993 01:26:08 +0000
parents
children 16a24e76d6e0
comparison
equal deleted inserted replaced
3:9a4c07481e61 4:b4df021f796c
1 function retval = tril (x, k)
2
3 # usage: triu (x, k)
4 #
5 # Return the lower triangular part of x above the k-th diagonal. If
6 # the second argument is omitted, k = 0 is assumed.
7 #
8 # See also: triu, diag
9
10 if (nargin > 0)
11 [nr, nc] = size (x);
12 retval = x;
13 endif
14
15 if (nargin == 1)
16 k = 0;
17 elseif (nargin == 2)
18 max_nr_nc = max (nr, nc);
19 if ((k > 0 && k > nr - 1) || (k < 0 && k < 1 - nc))
20 error ("tril: requested diagonal out of range")
21 endif
22 else
23 error ("usage: tril (x [, k])");
24 endif
25
26 for i = 1:nr
27 for j = i+1-k:nc
28 retval (i, j) = 0.0;
29 endfor
30 endfor
31
32 endfunction