* pol2str(): support to polynomials with complex coefs and hypermat (See bug #13109) 24/13224/2
Samuel GOUGEON [Mon, 25 Nov 2013 16:16:34 +0000 (17:16 +0100)]
Change-Id: I8865040f3febc03ef075f3eec4368cb758d5a447

scilab/CHANGES_5.5.X
scilab/modules/polynomials/help/en_US/pol2str.xml
scilab/modules/polynomials/help/fr_FR/pol2str.xml
scilab/modules/polynomials/help/ja_JP/pol2str.xml
scilab/modules/polynomials/help/pt_BR/pol2str.xml
scilab/modules/polynomials/macros/pol2str.sci
scilab/modules/polynomials/tests/unit_tests/pol2str.dia.ref
scilab/modules/polynomials/tests/unit_tests/pol2str.tst

index 0b31576..5577451 100644 (file)
@@ -15,6 +15,8 @@ New Features
 
 * test_run() can now separate 32bits systems from 64bits ones.
 
+* pol2str(): support to polynomials with complex coefficients and hypermatrices (See bug #13109).
+
 
 Obsolete & Removed Functions
 ============================
@@ -248,6 +250,8 @@ Scilab Bug Fixes
 
 * Bug #13101 fixed - When x-axis was in reverse position x_location='origin' failed.
 
+* Bug #13109 fixed - pll2str now supports polynomials with complex coefficients and hypermatrices.
+
 
 Xcos Bug Fixes
 ==============
index 2335122..79878bf 100644 (file)
@@ -2,6 +2,7 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2006-2008 - INRIA
+ * Copyright (C) 2013 - Samuel GOUGEON : upgrade for 5.5.0
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
             <varlistentry>
                 <term>p</term>
                 <listitem>
-                    <para>matrix of real polynomial</para>
+                    <para>matrix or hypermatrix of polynomials with real or complex coefficients</para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>strs</term>
                 <listitem>
-                    <para>a matrix of strings</para>
+                    <para>matrix or hypermatrix of strings</para>
                 </listitem>
             </varlistentry>
         </variablelist>
         <para>
             converts polynomial to character string (utility function).
         </para>
+        <para>
+            <note>
+                The output format of coefficients is set through  <link linkend="format">format(..)</link>.
+            </note>
+        </para>
     </refsection>
     
     <refsection>
@@ -51,6 +57,8 @@ pol2str(%z)
 p = poly ([1, 2, 3], "x","coeff");
 pol2str(p)
 
+p = (1+%i+%z)^(1:4)
+pol2str(p)
  ]]></programlisting>
     </refsection>
     
@@ -61,10 +69,20 @@ pol2str(p)
                 <link linkend="string">string</link>
             </member>
             <member>
-                <member>
-                    <link linkend="prettyprint">prettyprint</link>
-                </member>
+                <link linkend="prettyprint">prettyprint</link>
+            </member>
+            <member>
+                <link linkend="sci2exp">sci2exp</link>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history tag">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.5.0</revnumber>
+                <revdescription>pol2str() extended to polynomials with complex coefficients and to hypermatrix. Array processing vectorized.</revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 2bed34e..4cf6807 100644 (file)
@@ -1,8 +1,20 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006-2008 - INRIA
+ * Copyright (C) 2013 - Samuel GOUGEON : upgrade for 5.5.0
+ *
+ * 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.1-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:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="fr" xml:id="pol2str">
     <refnamediv>
         <refname>pol2str</refname>
-        <refpurpose>conversion polynôme vers chaîne de caractères  </refpurpose>
+        <refpurpose>conversion polynôme => texte</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Séquence d'appel</title>
             <varlistentry>
                 <term>p  </term>
                 <listitem>
-                    <para>matrice de polynôme réel
+                    <para>matrice ou hypermatrice de polynômes à coefficients réels ou complexes
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>str  </term>
                 <listitem>
-                    <para>une matrix de chaîne de caractères
+                    <para>matrice ou hypermatrice texte
                     </para>
                 </listitem>
             </varlistentry>
     <refsection>
         <title>Description</title>
         <para>
-            convertit le polynôme p en une chaîne de caractères (fonction utilitaire).
+            convertit les polynômes p en textes les représentant (fonction utilitaire).
+        </para>
+        <para>
+            <note>
+                Le format de sortie des coefficients est fixé par <link linkend="format">format(..)</link>.
+            </note>
         </para>
     </refsection>
     
@@ -42,6 +59,8 @@ pol2str(%z)
 p = poly ([1, 2, 3], "x","coeff");
 pol2str(p)
 
+p = (1+%i+%z)^(1:4)
+pol2str(p)
  ]]></programlisting>
     </refsection>
     
@@ -52,10 +71,20 @@ pol2str(p)
                 <link linkend="string">string</link>
             </member>
             <member>
-                <member>
-                    <link linkend="prettyprint">prettyprint</link>
-                </member>
+                <link linkend="prettyprint">prettyprint</link>
+            </member>
+            <member>
+                <link linkend="sci2exp">sci2exp</link>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history tag">
+        <title>Historique</title>
+        <revhistory>
+            <revision>
+                <revnumber>5.5.0</revnumber>
+                <revdescription>Extension aux polynômes à coefficients complexes et aux hypermatrices. Vectorisation du traitement du tableau de polynômes</revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index bed368b..18febbf 100644 (file)
@@ -2,6 +2,7 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2006-2008 - INRIA
+ * Copyright (C) 2013 - Samuel GOUGEON : upgrade for 5.5.0
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
@@ -25,7 +26,7 @@
             <varlistentry>
                 <term>p</term>
                 <listitem>
-                    <para>実数多項式</para>
+                    <para>実数または複素係数行列多項式</para>
                 </listitem>
             </varlistentry>
             <varlistentry>
         <para>
             多項式を文字列に変換します (ユーティリティ関数).
         </para>
+        <para>
+            <note>
+                係数の出力フォーマットは、<link linkend="format">format(..)</link> によって決定される.
+            </note>
+        </para>
     </refsection>
-    <refsection role="see also">
-        <title>参照</title>
-        <simplelist type="inline">
-            <member>
-                <link linkend="string">string</link>
-            </member>
-            <member>
-                <member>
-                    <link linkend="prettyprint">prettyprint</link>
-                </member>
-            </member>
-        </simplelist>
-    </refsection>
+    <title>例</title>
+    <programlisting role="example"><![CDATA[
+pol2str(%z)
+
+p = poly ([1, 2, 3], "x","coeff");
+pol2str(p)
+
+p = (1+%i+%z)^(1:4)
+pol2str(p)
+ ]]></programlisting>
+</refsection>
+<refsection role="see also">
+    <title>参照</title>
+    <simplelist type="inline">
+        <member>
+            <link linkend="string">string</link>
+        </member>
+        <member>
+            <link linkend="prettyprint">prettyprint</link>
+        </member>
+        <member>
+            <link linkend="sci2exp">sci2exp</link>
+        </member>
+    </simplelist>
+</refsection>
+<refsection role="history tag">
+    <title>ヒストリカル</title>
+    <revhistory>
+        <revision>
+            <revnumber>5.5.0</revnumber>
+            <revdescription>複素係数とhypermatricesと多項式への拡張。多項式のベクトル化処理テーブル</revdescription>
+        </revision>
+    </revhistory>
+</refsection>
 </refentry>
index ddcb029..0742208 100644 (file)
@@ -2,6 +2,7 @@
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2006-2008 - INRIA
+ * Copyright (C) 2013 - Samuel GOUGEON : upgrade for 5.5.0
  *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
  *
  -->
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="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="pol2str" xml:lang="en">
-    <refnamediv>
-        <refname>pol2str</refname>
-        <refpurpose>conversão de polinômio para string</refpurpose>
-    </refnamediv>
-    <refsynopsisdiv>
-        <title> Seqüência de Chamamento </title>
-        <synopsis>[str]=pol2str(p)</synopsis>
-    </refsynopsisdiv>
-    <refsection>
-        <title>Parâmetros</title>
-        <variablelist>
-            <varlistentry>
-                <term>p</term>
-                <listitem>
-                    <para>polinômio real </para>
-                </listitem>
-            </varlistentry>
-            <varlistentry>
-                <term>str</term>
-                <listitem>
-                    <para>string</para>
-                </listitem>
-            </varlistentry>
-        </variablelist>
-    </refsection>
-    <refsection>
-        <title>Descrição</title>
-        <para> Converte um polinômio para um string (função utilitária).</para>
-    </refsection>
-    <refsection>
-        <title> Ver Também </title>
-        <simplelist type="inline">
-            <member>
-                <link linkend="string">string</link>
-            </member>
-            <member>
-                <link linkend="prettyprint">prettyprint</link>
-            </member>
-        </simplelist>
-    </refsection>
+<refnamediv>
+    <refname>pol2str</refname>
+    <refpurpose>conversão de polinômio para string</refpurpose>
+</refnamediv>
+<refsynopsisdiv>
+    <title> Seqüência de Chamamento </title>
+    <synopsis>[str] = pol2str(p)</synopsis>
+</refsynopsisdiv>
+<refsection>
+    <title>Parâmetros</title>
+    <variablelist>
+        <varlistentry>
+            <term>p</term>
+            <listitem>
+                <para>Matriz ou hipermatriz polinômios com coeficientes reais ou complexos</para>
+            </listitem>
+        </varlistentry>
+        <varlistentry>
+            <term>str</term>
+            <listitem>
+                <para>string</para>
+            </listitem>
+        </varlistentry>
+    </variablelist>
+</refsection>
+<refsection>
+    <title>Descrição</title>
+    <para> Converte um polinômio para um string (função utilitária).</para>
+    <para>
+        <note>
+            O formato dos coeficientes de saída é definida através <link linkend="format">format(..)</link>.
+        </note>
+    </para>
+</refsection>
+<refsection>
+    <title>Exemplos</title>
+    <programlisting role="example"><![CDATA[
+pol2str(%z)
+
+p = poly ([1, 2, 3], "x","coeff");
+pol2str(p)
+
+p = (1+%i+%z)^(1:4)
+pol2str(p)
+ ]]></programlisting>
+</refsection>
+<refsection>
+    <title> Ver Também </title>
+    <simplelist type="inline">
+        <member>
+            <link linkend="string">string</link>
+        </member>
+        <member>
+            <link linkend="prettyprint">prettyprint</link>
+        </member>
+        <member>
+            <link linkend="sci2exp">sci2exp</link>
+        </member>
+    </simplelist>
+</refsection>
+<refsection role="history tag">
+    <title>Histórico</title>
+    <revhistory>
+        <revision>
+            <revnumber>5.5.0</revnumber>
+            <revdescription>pol2str () estendido para polinômios com coeficientes complexos e para hipermatriz. Processamento de matriz vetorizado.</revdescription>
+        </revision>
+    </revhistory>
+</refsection>
 </refentry>
index 6980231..05b47fc 100644 (file)
@@ -1,6 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA
-// Copyright (C) 2011 - DIGITEO - Allan CORNET
+// Copyright (C) 2013 - Samuel GOUGEON
 //
 // This file must be used under the terms of the CeCILL.
 // This source file is licensed as described in the file COPYING, which
@@ -8,68 +7,50 @@
 // are also available at
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
-
-function strs = pol2str(p)
-    // polynomial to character string
-    //
-    // p : polynomial (real)
-    // str : chracter string
-    //!
-
-    if type(p) <> 2 then
-        error(msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial expected.\n"), "pol2str", 1));
+function S = pol2str(p)
+    if type(p) <> 2 & (typeof(p)~="hypermat" | type(p(:))~=2) then
+        msg = _("%s: Wrong type for input argument #%d: Polynomial expected.\n")
+        error(msprintf(msg, "pol2str", 1));
     end
-
-    dimp2D = size(p);
-    dimp1D = size(p, "*");
-
-    for i = 1:dimp1D
-        _p = p(i);
-        n = degree(_p);
-        var = varn(_p);
-        nv = length(var);
-
-        while part(var,nv) == " " then
-            nv = nv - 1;
-        end;
-
-        var = part(var, 1:nv);
-
-        _p = coeff(_p);
-        if _p(1) <>0 then
-            if _p(1) < 0 then
-                str = string(_p(1));
-            else
-                str = " " + string(_p(1));
-            end
+    sp = size(p)
+    p = p(:)
+    d = max(degree(p))
+    c = coeff(p)
+    cr = real(c)
+    ci = imag(c)
+    S = stripblanks(string(c))
+    k = find(c==0)
+    S(k) = ""
+    k = find(cr~=0 & ci~=0)
+    k2 = find(k>length(p))
+    S(k(k2)) = "+("+S(k(k2))+")"
+    k = find((cr>0 & ci==0) | (cr==0 & ci>0))
+    S(k) = "+"+S(k)
+    vn = varn(p)
+    clear ci cr k2
+    for j = 2:(d+1)
+        if j==2 then
+            e = vn
         else
-            if n == 0 then
-                str = "0";
-            else
-                str = " ";
-            end
+            e = vn+msprintf("^%d",j-1)
         end
-
-        for k = 1:n
-            if _p(k + 1) <> 0 then
-                if _p(k + 1) < 0 then
-                    str = str + "-";
-                else
-                    str = str + "+";
-                end
-                if abs(_p(k + 1)) <> 1 then
-                    str = str + string(abs(_p(k+1))) + "*" + var;
-                else
-                    str = str + var;
-                end
-                if k > 1 then
-                    str = str + "^" + string(k);
-                end
-            end
+        km1 = find(c(:,j)==-1)
+        if km1~=[]
+            S(km1,j) = "-"+e
+        end
+        kp1 = find(c(:,j)==1)
+        if kp1~=[]
+            S(kp1,j) = "+"+e
+        end
+        ko = find(c(:,j)~=-1 & c(:,j)~=0 & c(:,j)~=1)
+        if ko~=[]
+            S(ko,j) = S(ko,j)+"*"+e
         end
-
-        strs(i) = str;
     end
-    strs = matrix(strs, dimp2D);
-
+    S = strcat(S,"","c")
+    k = find(part(S,1)=="+")
+    S(k) = part(S(k),2:$)
+    k = find(S=="")
+    S(k) = "0"
+    S = matrix(S,sp)
 endfunction
index 095c5e3..5bf724c 100644 (file)
@@ -5,13 +5,16 @@
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- CLI SHELL MODE -->
-assert_checkequal(pol2str(%z), " +z");
-assert_checkequal(pol2str([%z %z]), [" +z", " +z"]);
+assert_checkequal(pol2str(%z), "z");
+assert_checkequal(pol2str([%z %z]), ["z", "z"]);
 p = poly ([1, 2, 3], "x","coeff");
 P = [p, p ,p ; p, p, p];
 R = pol2str(P);
-REF = [" 1+2*x+3*x^2", " 1+2*x+3*x^2", " 1+2*x+3*x^2";
-       " 1+2*x+3*x^2", " 1+2*x+3*x^2", " 1+2*x+3*x^2"];
+REF = ["1+2*x+3*x^2", "1+2*x+3*x^2", "1+2*x+3*x^2";
+       "1+2*x+3*x^2", "1+2*x+3*x^2", "1+2*x+3*x^2"];
 assert_checkequal(R, REF);
 msgerror = msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial expected.\n"), "pol2str", 1);
-assert_checkerror("pol2str(1)", msgerror); 
+assert_checkerror("pol2str(1)", msgerror);
+assert_checkequal(pol2str(%i*%z),"%i*z");
+ref = hypermat([1 1 2], ["1+0.8497452*z";"1+0.685731*z"]);
+assert_checktrue(and(pol2str(1+hypermat([1 1 2], [0.8497452;0.6857310])*%z) == ref));
index 4061442..4ac003f 100644 (file)
@@ -7,16 +7,22 @@
 
 // <-- CLI SHELL MODE -->
 
-assert_checkequal(pol2str(%z), " +z");
-assert_checkequal(pol2str([%z %z]), [" +z", " +z"]);
+assert_checkequal(pol2str(%z), "z");
+assert_checkequal(pol2str([%z %z]), ["z", "z"]);
 
 p = poly ([1, 2, 3], "x","coeff");
 P = [p, p ,p ; p, p, p];
 R = pol2str(P);
-REF = [" 1+2*x+3*x^2", " 1+2*x+3*x^2", " 1+2*x+3*x^2";
-       " 1+2*x+3*x^2", " 1+2*x+3*x^2", " 1+2*x+3*x^2"];
+REF = ["1+2*x+3*x^2", "1+2*x+3*x^2", "1+2*x+3*x^2";
+"1+2*x+3*x^2", "1+2*x+3*x^2", "1+2*x+3*x^2"];
+
 assert_checkequal(R, REF);
+
 msgerror = msprintf(gettext("%s: Wrong type for input argument #%d: Polynomial expected.\n"), "pol2str", 1);
-assert_checkerror("pol2str(1)", msgerror); 
+assert_checkerror("pol2str(1)", msgerror);
+
+assert_checkequal(pol2str(%i*%z),"%i*z");
+ref = hypermat([1 1 2], ["1+0.8497452*z";"1+0.685731*z"]);
+assert_checktrue(and(pol2str(1+hypermat([1 1 2], [0.8497452;0.6857310])*%z) == ref));
+
+