annotate scripts/linear-algebra/dot.m @ 4720:e759d01692db ss-2-1-53

[project @ 2004-01-23 04:13:37 by jwe]
author jwe
date Fri, 23 Jan 2004 04:13:37 +0000
parents 22bd65326ec1
children e7da90a1cc11
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 -*-
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
21 ## @deftypefn {Function File} {} dot (@var{x}, @var{y})
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
22 ## Computes the dot product of two vectors.
3449
858695b3ed62 [project @ 2000-01-18 04:08:59 by jwe]
jwe
parents: 3426
diff changeset
23 ## @end deftypefn
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
24
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
25 ## Author: jwe
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 function z = dot (x, y)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
28
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
29 if (nargin != 2)
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
30 usage ("dot (x, y)");
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
31 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
32
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3922
diff changeset
33 if (isvector (x) && isvector (y) && length (x) == length (y))
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
34 [x_nr, x_nc] = size (x);
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
35 [y_nr, y_nc] = size (y);
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
36 if (x_nr == 1)
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
37 if (y_nr == 1)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
38 z = x * y.';
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
39 else
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
40 z = x * y;
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
41 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
42 else
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
43 if (y_nr == 1)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
44 z = y * x;
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
45 else
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3238
diff changeset
46 z = y.' * x;
3175
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
47 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
48 endif
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
49 else
096940972434 [project @ 1998-05-18 17:03:01 by jwe]
jwe
parents:
diff changeset
50 error ("dot: both arguments must be vectors of the same length");
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