[genius] Thu Sep 30 15:28:50 2010 Jiri (George) Lebl <jirka 5z com>



commit 3d44f508727752353a53255a49bae852acf1661f
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Thu Sep 30 15:28:57 2010 -0700

    Thu Sep 30 15:28:50 2010  Jiri (George) Lebl <jirka 5z com>
    
    	* lib/linear_algebra/linear_algebra.gel: Fix CrossProduct and
    	  make it return a column vector.
    
    	* src/geniustests.txt: add a test
    
    	* help/C/gel-function-list.xml: note that the result is a column
    	  vector

 ChangeLog                             |   10 ++++++++++
 help/C/gel-function-list.xml          |    3 ++-
 lib/linear_algebra/linear_algebra.gel |    7 +++++--
 src/geniustests.txt                   |    2 ++
 4 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 20318c3..e88c296 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Thu Sep 30 15:28:50 2010  Jiri (George) Lebl <jirka 5z com>
+
+	* lib/linear_algebra/linear_algebra.gel: Fix CrossProduct and
+	  make it return a column vector.
+
+	* src/geniustests.txt: add a test
+
+	* help/C/gel-function-list.xml: note that the result is a column
+	  vector
+
 Thu Sep 09 22:47:54 2010  Jiri (George) Lebl <jirka 5z com>
 
 	* Release 1.0.11
diff --git a/help/C/gel-function-list.xml b/help/C/gel-function-list.xml
index 9e43665..fb3b19f 100644
--- a/help/C/gel-function-list.xml
+++ b/help/C/gel-function-list.xml
@@ -2922,7 +2922,8 @@ result as a vector and not added together.</para>
          <term>CrossProduct</term>
          <listitem>
           <synopsis>CrossProduct (v,w)</synopsis>
-          <para>CrossProduct of two vectors in R<superscript>3</superscript>.</para>
+	  <para>CrossProduct of two vectors in R<superscript>3</superscript> as
+		  a column vector.</para>
          </listitem>
         </varlistentry>
 
diff --git a/lib/linear_algebra/linear_algebra.gel b/lib/linear_algebra/linear_algebra.gel
index 14a9e66..c7dae75 100644
--- a/lib/linear_algebra/linear_algebra.gel
+++ b/lib/linear_algebra/linear_algebra.gel
@@ -106,8 +106,11 @@ function StripZeroRows (M) =
 SetHelp ("CrossProduct", "linear_algebra", "CrossProduct of two vectors in R^3")
 function CrossProduct(v,w) =
  (
-  M=[v;w;1,1,1];
-  [Minor(M,3,1),Minor(M,3,2),Minor(M,3,3)]
+  if not IsVector (v) or not IsVector (w) then
+    (error ("CrossProduct: v,w must be vectors");bailout)
+  else if elements(v) != 3 or elements(w) != 3 then
+    (error ("CrossProduct: v,w must be vectors in R^3");bailout);
+  [v@(2)*w@(3)-v@(3)*w@(2); v@(3)*w@(1)-v@(1)*w@(3); v@(1)*w@(2)-v@(2)*w@(1)]
  )
 
 # Direct sum of a vector of matrices
diff --git a/src/geniustests.txt b/src/geniustests.txt
index c4926df..f87dd38 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -1020,6 +1020,8 @@ IsMatrixSquare([1,2;3,4])					true
 IsMatrixSquare([1,2,3,4])					false
 SetMatrixSize(null,2,3)						[0,0,0;0,0,0]
 ExpandMatrix(null)+1						((null)+1)
+CrossProduct ([-2,1,4],[3,2,5])					[-3;22;-7]
+CrossProduct ([3;2;5],[-2;1;4])					[3;-22;7]
 load "nullspacetest.gel"					true
 load "longtest.gel"						true
 load "testprec.gel"						true



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]