annotate scripts/linear-algebra/dot.m @ 7016:93c65f2a5668

[project @ 2007-10-12 06:40:56 by jwe]
author jwe
date Fri, 12 Oct 2007 06:41:26 +0000
parents 045038e0108a
children a1dbe9d80eee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 1998 John W. Eaton
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
2 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
3 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
4 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
5 ## 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
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: 6157
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: 6157
diff changeset
8 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
9 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
10 ## 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
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
12 ## 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
13 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
14 ##
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
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: 6157
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: 6157
diff changeset
17 ## <http://www.gnu.org/licenses/>.
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
18
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
19 ## -*- texinfo -*-
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
20 ## @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
21 ## 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
22 ## are matrices, calculate the dot-product along the first
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
23 ## 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
24 ## given, calculate the dot-product along this dimension.
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
25 ## @end deftypefn
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
26
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
27 ## Author: jwe
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
28
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
29 function z = dot (x, y, dim)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
30
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
31 if (nargin != 2 && nargin != 3)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5307
diff changeset
32 print_usage ();
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
33 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
34
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
35 if (nargin < 3)
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
36 if isvector (x)
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
37 x = x(:);
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
38 endif
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
39 if isvector (y)
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
40 y = y(:);
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
41 endif
6157
045038e0108a [project @ 2006-11-13 22:22:53 by jwe]
jwe
parents: 6046
diff changeset
42 if (! size_equal (x, y))
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
43 error ("dot: sizes of arguments must match")
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
44 endif
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
45 z = sum(x .* y);
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
46 else
6157
045038e0108a [project @ 2006-11-13 22:22:53 by jwe]
jwe
parents: 6046
diff changeset
47 if (! size_equal (x, y))
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
48 error ("dot: sizes of arguments must match")
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
49 endif
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
50 z = sum(x .* y, dim);
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
51 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
52
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
53 endfunction