annotate scripts/linear-algebra/dot.m @ 8664:e07e93c04080

style fixes
author John W. Eaton <jwe@octave.org>
date Wed, 04 Feb 2009 10:56:23 -0500
parents a1dbe9d80eee
children eb63fbe60fab
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
1 ## Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005, 2006, 2007
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
2 ## John W. Eaton
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
3 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
4 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
5 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
7 ## 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: 6157
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
9 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
10 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
14 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
15 ##
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
16 ## 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: 6157
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
18 ## <http://www.gnu.org/licenses/>.
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
19
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
20 ## -*- texinfo -*-
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
21 ## @deftypefn {Function File} {} dot (@var{x}, @var{y}, @var{dim})
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
22 ## Computes the dot product of two vectors. If @var{x} and @var{y}
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
23 ## are matrices, calculate the dot-product along the first
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
24 ## non-singleton dimension. If the optional argument @var{dim} is
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
25 ## given, calculate the dot-product along this dimension.
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
26 ## @end deftypefn
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
27
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
28 ## Author: jwe
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
29
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
30 function z = dot (x, y, dim)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
31
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
32 if (nargin != 2 && nargin != 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
33 print_usage ();
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
34 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
35
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
36 if (nargin < 3)
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
37 if isvector (x)
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
38 x = x(:);
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
39 endif
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
40 if isvector (y)
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
41 y = y(:);
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
42 endif
6157
045038e0108a [project @ 2006-11-13 22:22:53 by jwe]
jwe
parents: 6046
diff changeset
43 if (! size_equal (x, y))
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
44 error ("dot: sizes of arguments must match");
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
45 endif
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
46 z = sum(x .* y);
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
47 else
6157
045038e0108a [project @ 2006-11-13 22:22:53 by jwe]
jwe
parents: 6046
diff changeset
48 if (! size_equal (x, y))
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
49 error ("dot: sizes of arguments must match");
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
50 endif
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
51 z = sum(x .* y, dim);
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
52 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
53
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
54 endfunction