annotate scripts/linear-algebra/trace.m @ 20614:10ec79b47808

use new string_value method to handle value extraction errors * __voronoi__.cc, chol.cc, colamd.cc, fftw.cc: Use new string_value method.
author John W. Eaton <jwe@octave.org>
date Thu, 08 Oct 2015 18:15:56 -0400
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 1993-2015 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2311
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## <http://www.gnu.org/licenses/>.
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
18
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 2847
diff changeset
19 ## -*- texinfo -*-
16960
7c575556e817 trace.m: Use @deftypefn instead of @deftypefnx in docstring.
Rik <rik@octave.org>
parents: 16958
diff changeset
20 ## @deftypefn {Function File} {} trace (@var{A})
16955
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
21 ## Compute the trace of @var{A}, the sum of the elements along the main
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
22 ## diagonal.
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
23 ##
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
24 ## The implementation is straightforward: @code{sum (diag (@var{A}))}.
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
25 ## @seealso{eig}
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 2847
diff changeset
26 ## @end deftypefn
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
27
2314
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
28 ## Author: jwe
949ab8eba8bc [project @ 1996-07-12 03:58:02 by jwe]
jwe
parents: 2313
diff changeset
29
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
30 function y = trace (A)
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
31
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
32 if (nargin != 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
33 print_usage ();
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
34 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
35
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
36 if (ndims (A) > 2)
7415
2da391ef7f55 [project @ 2008-01-24 07:40:58 by jwe]
jwe
parents: 7411
diff changeset
37 error ("trace: only valid on 2-D objects");
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
38 elseif (isempty (A))
7415
2da391ef7f55 [project @ 2008-01-24 07:40:58 by jwe]
jwe
parents: 7411
diff changeset
39 y = 0;
16955
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
40 elseif (isvector (A))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
41 y = A(1);
1065
5eeb61cac52e [project @ 1995-01-25 14:04:13 by jwe]
jwe
parents: 1014
diff changeset
42 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
43 y = sum (diag (A));
1065
5eeb61cac52e [project @ 1995-01-25 14:04:13 by jwe]
jwe
parents: 1014
diff changeset
44 endif
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
45
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
46 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
47
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
48
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
49 %!assert (trace ([1, 2; 3, 4]), 5)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
50 %!assert (trace ([1, 2; 3, 4; 5, 6]), 5)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
51 %!assert (trace ([1, 3, 5; 2, 4, 6]), 5)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
52 %!assert (trace ([]), 0)
16955
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
53 %!assert (trace (rand (1,0)), 0)
9c971fa62a77 trace.m: Update docstring. Use isvector() in checking inputs.
Rik <rik@octave.org>
parents: 14363
diff changeset
54 %!assert (trace ([3:10]), 3)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
55
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56 %!error trace ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 %!error trace (1, 2)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
58 %!error <only valid on 2-D objects> trace (reshape (1:9,[1,3,3]))
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
59