diff scripts/linear-algebra/cross.m @ 3085:e6d14959bea9

[project @ 1997-09-19 22:06:12 by jwe]
author jwe
date Fri, 19 Sep 1997 22:08:32 +0000
parents c3d634d49ce4
children 041ea33fbbf4
line wrap: on
line diff
--- a/scripts/linear-algebra/cross.m
+++ b/scripts/linear-algebra/cross.m
@@ -29,16 +29,20 @@
     usage ("cross (x, y)");
   endif
 
-  if (! (is_vector (x) && length (x) == 3
-	 && is_vector (y) && length (y) == 3))
+  if (length (x) == 3 && length (y) == 3)
+
+    z = [x(2)*y(3) - x(3)*y(2); x(3)*y(1) - x(1)*y(3); x(1)*y(2) - x(2)*y(1)];
+
+    x_nr = rows (x);
+    y_nr = rows (y);
+
+    if ((x_nr == y_nr && x_nr == 1)
+ 	|| (x_nr != y_nr && ! prefer_column_vectors))
+      z = z';
+    endif
+
+  else
     error ("cross: both x and y must be 3-dimensional vectors");
   endif
-  
-  x = reshape (x, 3, 1);
-  y = reshape (y, 3, 1);
-  e = eye (3, 3);
-  for k = 1 : 3
-    z(k) = det ([x y e(:, k)]);
-  endfor
 
 endfunction