annotate scripts/linear-algebra/dot.m @ 5083:8386cf9811ee ss-2-1-63

[project @ 2004-11-17 15:49:26 by jwe]
author jwe
date Wed, 17 Nov 2004 15:51:27 +0000
parents e7da90a1cc11
children 4c8a2e4e0717
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
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
7 ## the Free Software Foundation; either version 2, or (at your option)
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
8 ## 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
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
16 ## along with Octave; see the file COPYING. If not, write to the Free
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3449
diff changeset
18 ## 02111-1307, USA.
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)
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
33 usage ("dot (x, y, dim)");
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
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
43 if (size (x) != size (y))
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
44 error ("dot: sizes of arguments must match")
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
4890
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
48 if (size (x) != size (y))
e7da90a1cc11 [project @ 2004-05-06 20:36:29 by jwe]
jwe
parents: 4030
diff changeset
49 error ("dot: sizes of arguments must match")
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