cross function added. See bug #9941 fixed. 69/11469/6
Charlotte HECQUET [Fri, 10 May 2013 11:48:59 +0000 (13:48 +0200)]
Change-Id: If020bc7b5d58fff5f2d23650cf30f1728b7e6759

SEP/INDEX
SEP/SEP_096_cross.odt [new file with mode: 0644]
scilab/CHANGES_5.5.X
scilab/modules/elementary_functions/help/en_US/matrixoperations/cross.xml [new file with mode: 0644]
scilab/modules/elementary_functions/macros/cross.sci [new file with mode: 0644]
scilab/modules/elementary_functions/tests/unit_tests/cross.dia.ref [new file with mode: 0644]
scilab/modules/elementary_functions/tests/unit_tests/cross.tst [new file with mode: 0644]
scilab/modules/helptools/etc/images_md5.txt
scilab/modules/helptools/images/_LaTeX_cross.xml_1.png [new file with mode: 0644]

index d426624..5dcbb68 100644 (file)
--- a/SEP/INDEX
+++ b/SEP/INDEX
@@ -93,3 +93,5 @@ SEP #093: New function cov
 SEP #095: New functions: ismatrix, isrow,iscolumn and issquare.
 SEP #097: New argument added at strtod function (decimalseparator)
 SEP #098: New output argument for qp_solve function
+SEP #089: New parameter added at routh_t function (normalized).
+SEP #096: cross function.
diff --git a/SEP/SEP_096_cross.odt b/SEP/SEP_096_cross.odt
new file mode 100644 (file)
index 0000000..92254d1
Binary files /dev/null and b/SEP/SEP_096_cross.odt differ
index f9409a6..fd163b2 100644 (file)
@@ -22,6 +22,7 @@ BDF methods with direct and preconditioned Krylov linear solvers, from ODEPACK.
  - isrow - Check if a variable is a row vector. See bug #10456 fixed.
  - iscolumn - Check if a variable is a column vector. See bug #10456 fixed.
  - issquare - Check if a variable is a square matrix. See bug #10456 fixed.
+ - cross - Vector cross product. See bug #9941 fixed.
 
 * Add a complete set of functions to read and write any HDF5 file from Scilab.
 
diff --git a/scilab/modules/elementary_functions/help/en_US/matrixoperations/cross.xml b/scilab/modules/elementary_functions/help/en_US/matrixoperations/cross.xml
new file mode 100644 (file)
index 0000000..a805d0a
--- /dev/null
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="cross" xml:lang="en">
+    <refnamediv>
+        <refname>cross</refname>
+        <refpurpose>vector cross product</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling sequence</title>
+        <synopsis>C = cross(A,B)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>A</term>
+                <listitem>
+                    <para>real, complex, polynomial or boolean matrix of size 3-by-N or 1-by-3.</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>B</term>
+                <listitem>
+                    <para>real, complex, polynomial or boolean matrix of same size as A.</para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>C</term>
+                <listitem>
+                    <para>real, complex, polynomial or boolean matrix of same size as A and B.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            <function>cross</function> returns the cross product of <varname>A</varname> and <varname>B</varname>, that is:
+            <para>
+                <latex>
+                    \begin{eqnarray}
+                    C = A \wedge B
+                    \end{eqnarray}
+                </latex>
+            </para>
+        </para>
+        <para>
+            <varname>A</varname> and <varname>B</varname> can be full or sparse matrix. However, rational matrix are not supported.
+            Concerning boolean matrix, <function>cross</function> computes as if %t (resp. %f) was 1 (resp. 0), and '&amp;' (resp. '|')
+            was '*' (resp. '+').
+        </para>
+        <para>
+            To finish, if <varname>A</varname> and <varname>B</varname> are 3-by-N matrix, column-wise computations are done.
+        </para>
+    </refsection>
+    <refsection>
+        <title>Example</title>
+        <programlisting role="example"><![CDATA[
+A=[1;2;3];
+B=[2;3;4];
+cross(A,B) //expected: [-1;2;-1]
+A=[%i,2,1+%i];
+B=[1,%i,2+%i];
+cross(A,B) //expected: [5+%i,2-%i,-3]
+A=[%t;%f;%t];
+B=[%t;%f;%f];
+cross(A,B) //expected: [0;1;0]
+ ]]></programlisting>
+    </refsection>
+    <refsection>
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.5.0</revnumber>
+                <revremark>Function cross introduced.</revremark>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/elementary_functions/macros/cross.sci b/scilab/modules/elementary_functions/macros/cross.sci
new file mode 100644 (file)
index 0000000..f9c82bd
--- /dev/null
@@ -0,0 +1,38 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+function c=cross(a,b)
+    // This function returns the cross product of a and b
+    rhs = argn(2);
+    if rhs <> 2 then
+        error(msprintf(_("%s: Wrong number of input arguments: %d expected.\n"), "cross",2));
+    end
+    if type(a) > 8 | type(a) == 6 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A real, complex, boolean or polynomial matrix expected.\n"), "cross", 1));
+    end
+    if type(b) > 8 | type(b) == 6 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A real, complex, boolean or polynomial matrix expected.\n"), "cross", 2));
+    end
+
+    if size(a,1) <> size(b,1) | size(a,2)<>size(b,2) then
+        error(msprintf(_("%s: Wrong size for input arguments: Same sizes expected.\n"), "cross"));
+    end
+    if size(a,1)<>3 & (size(a,1)<>1 & size(a,2)<>3) then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A matrix of size 1x3 or 3xN expected.\n"), "cross", 1));
+    end
+    if size(b,1)<>3 & size(b,1)<>1 & size(b,2)<>3 then
+        error(msprintf(_("%s: Wrong size for input argument #%d: A matrix of size 1x3 or 3xN expected.\n"), "cross", 2));
+    end
+
+    if size(a,2)==3 & size(a,1)==1 then
+        c=a(:,[2 3 1]).*b(:,[3 1 2]) - a(:,[3 1 2]).*b([2 3 1]);
+    else
+        c=a([2 3 1],:).*b([3 1 2],:) - a([3 1 2],:).*b([2 3 1],:);
+    end
+endfunction
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/cross.dia.ref b/scilab/modules/elementary_functions/tests/unit_tests/cross.dia.ref
new file mode 100644 (file)
index 0000000..662a6ac
--- /dev/null
@@ -0,0 +1,52 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+// unit tests for cross function.
+// =============================================================================
+A=[1;2;3];
+B=[2;3;4];
+C=[-1;2;-1];
+assert_checkequal(cross(A,B), C);
+assert_checkequal(cross(A',B'),C');
+assert_checkequal(cross([A,A],[B,B]),[C,C]);
+assert_checkequal(cross([A,A,A],[B,B,B]),[C,C,C]);
+assert_checkequal(cross(int8(A),int8(B)),int8(C));
+assert_checkequal(cross(uint8(A),uint8(B)),uint8(C));
+assert_checkequal(cross(int16(A),int16(B)),int16(C));
+assert_checkequal(cross(uint16(A),uint16(B)),uint16(C));
+assert_checkequal(cross(int32(A),int32(B)),int32(C));
+assert_checkequal(cross(uint32(A),uint32(B)),uint32(C));
+A=[%i;2;1+%i];
+B=[1;%i;2+%i];
+C=[5+%i;2-%i;-3];
+assert_checkequal(cross(A,B),C);
+s=poly(0,"s");
+A=[s;1+s;3];
+B=[1;2+s;s];
+C=[s^2-2*s-6;3-s^2;s^2+s-1];
+assert_checkequal(cross(A,B),C);
+A=[%t;%f;%t];
+B=[%t;%f;%f];
+C=[0;1;0];
+assert_checkequal(cross(A,B),C);
+A=sparse([1;0;3]);
+B=sparse([2;3;0]);
+C=sparse([-9;6;3]);
+assert_checkequal(cross(A,B),C);
+// Error messages
+errmsg1=msprintf(_("Wrong number of input arguments."));
+assert_checkerror("cross(A,B,C)", errmsg1);
+errmsg2=msprintf(_("%s: Wrong number of input arguments: %d expected.\n"), "cross",2);
+assert_checkerror("cross(A)", errmsg2);
+errmsg3=msprintf(_("%s: Wrong type for input argument #%d: A real, complex, boolean or polynomial matrix expected.\n"), "cross", 1);
+assert_checkerror("cross([""s"";""t"";""u""],B)", errmsg3);
+errmsg4=msprintf(_("%s: Wrong type for input argument #%d: A real, complex, boolean or polynomial matrix expected.\n"), "cross", 2);
+assert_checkerror("cross(A,[""s"";""t"";""u""])", errmsg4);
+errmsg5=msprintf(_("%s: Wrong size for input argument #%d: A matrix of size 1x3 or 3xN expected.\n"), "cross", 1);
+assert_checkerror("cross([1;2;3;4],[1;2;3;4])", errmsg5);
+errmsg6=msprintf(_("%s: Wrong size for input arguments: Same sizes expected.\n"), "cross");
+assert_checkerror("cross(A,[2;3])",errmsg6);
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/cross.tst b/scilab/modules/elementary_functions/tests/unit_tests/cross.tst
new file mode 100644 (file)
index 0000000..6689a94
--- /dev/null
@@ -0,0 +1,56 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+
+// unit tests for cross function.
+// =============================================================================
+
+A=[1;2;3];
+B=[2;3;4];
+C=[-1;2;-1];
+assert_checkequal(cross(A,B), C);
+assert_checkequal(cross(A',B'),C');
+assert_checkequal(cross([A,A],[B,B]),[C,C]);
+assert_checkequal(cross([A,A,A],[B,B,B]),[C,C,C]);
+assert_checkequal(cross(int8(A),int8(B)),int8(C));
+assert_checkequal(cross(uint8(A),uint8(B)),uint8(C));
+assert_checkequal(cross(int16(A),int16(B)),int16(C));
+assert_checkequal(cross(uint16(A),uint16(B)),uint16(C));
+assert_checkequal(cross(int32(A),int32(B)),int32(C));
+assert_checkequal(cross(uint32(A),uint32(B)),uint32(C));
+A=[%i;2;1+%i];
+B=[1;%i;2+%i];
+C=[5+%i;2-%i;-3];
+assert_checkequal(cross(A,B),C);
+s=poly(0,"s");
+A=[s;1+s;3];
+B=[1;2+s;s];
+C=[s^2-2*s-6;3-s^2;s^2+s-1];
+assert_checkequal(cross(A,B),C);
+A=[%t;%f;%t];
+B=[%t;%f;%f];
+C=[0;1;0];
+assert_checkequal(cross(A,B),C);
+A=sparse([1;0;3]);
+B=sparse([2;3;0]);
+C=sparse([-9;6;3]);
+assert_checkequal(cross(A,B),C);
+
+// Error messages
+errmsg1=msprintf(_("Wrong number of input arguments."));
+assert_checkerror("cross(A,B,C)", errmsg1);
+errmsg2=msprintf(_("%s: Wrong number of input arguments: %d expected.\n"), "cross",2);
+assert_checkerror("cross(A)", errmsg2);
+errmsg3=msprintf(_("%s: Wrong type for input argument #%d: A real, complex, boolean or polynomial matrix expected.\n"), "cross", 1);
+assert_checkerror("cross([""s"";""t"";""u""],B)", errmsg3);
+errmsg4=msprintf(_("%s: Wrong type for input argument #%d: A real, complex, boolean or polynomial matrix expected.\n"), "cross", 2);
+assert_checkerror("cross(A,[""s"";""t"";""u""])", errmsg4);
+errmsg5=msprintf(_("%s: Wrong size for input argument #%d: A matrix of size 1x3 or 3xN expected.\n"), "cross", 1);
+assert_checkerror("cross([1;2;3;4],[1;2;3;4])", errmsg5);
+errmsg6=msprintf(_("%s: Wrong size for input arguments: Same sizes expected.\n"), "cross");
+assert_checkerror("cross(A,[2;3])",errmsg6);
index 5cc9aa7..b69ae1e 100644 (file)
@@ -311,6 +311,7 @@ _LaTeX_cdfnor.xml_1.png=b86b06522195bfcbfd8f4536dfa11330
 _LaTeX_ceil.xml_1.png=701fa44621fd283e3f2c5468958859d8
 _LaTeX_ceil.xml_ru_RU_1.png=701fa44621fd283e3f2c5468958859d8
 _LaTeX_cov.xml_1.png=1c3e8061d5b85a1b05a8f1c390f6f94d
+_LaTeX_cross.xml_1.png=9653e9a5372afaed5d4a1ca1554ecac7
 _LaTeX_csc.xml_1.png=95c11e401eed01b86b588b99436708ae
 _LaTeX_csc.xml_2.png=e070fd531e084fbf4de11e4096f5d58
 _LaTeX_cscd.xml_1.png=95c11e401eed01b86b588b99436708ae
diff --git a/scilab/modules/helptools/images/_LaTeX_cross.xml_1.png b/scilab/modules/helptools/images/_LaTeX_cross.xml_1.png
new file mode 100644 (file)
index 0000000..59a8641
Binary files /dev/null and b/scilab/modules/helptools/images/_LaTeX_cross.xml_1.png differ