* Bug 12862 fixed: intsplin(x,y) ignored imag(y) 39/19439/3
Samuel GOUGEON [Mon, 2 Oct 2017 00:16:59 +0000 (02:16 +0200)]
 http://bugzilla.scilab.org/12862

Change-Id: I0de699d522caac617b08df27aae2ded417aaed12

scilab/CHANGES.md
scilab/modules/differential_equations/help/en_US/intsplin.xml
scilab/modules/differential_equations/help/fr_FR/intsplin.xml
scilab/modules/differential_equations/help/ja_JP/intsplin.xml
scilab/modules/differential_equations/help/pt_BR/intsplin.xml
scilab/modules/differential_equations/help/ru_RU/intsplin.xml
scilab/modules/differential_equations/macros/intsplin.sci
scilab/modules/differential_equations/tests/nonreg_tests/bug_12862.tst [new file with mode: 0644]

index a497513..608ee37 100644 (file)
@@ -373,6 +373,7 @@ the [development mailing list](dev@lists.scilab.org) for a particular toolbox.
 * [#12195](http://bugzilla.scilab.org/show_bug.cgi?id=12195): `generateBlockImage` sometimes changed the current graphic driver.
 * [#12372](http://bugzilla.scilab.org/show_bug.cgi?id=12372): The `mode` function was poorly documented.
 * [#12771](http://bugzilla.scilab.org/show_bug.cgi?id=12771): xcosPalGenerateAllIcons help example was broken.
+* [#12862](http://bugzilla.scilab.org/show_bug.cgi?id=12862): `intsplin` no longer integrated the imaginary part of given ordinates. 
 * [#13592](http://bugzilla.scilab.org/show_bug.cgi?id=13592): In an axes in a uicontrol frame, setting a `legend` interactively might not follow the mouse accurately.
 * [#13900](http://bugzilla.scilab.org/show_bug.cgi?id=13900): `nanmin` and `nanmax` were useless duplicates of `min` and `max`
 * [#14254](http://bugzilla.scilab.org/show_bug.cgi?id=14254): When installing an ATOMS module that is not locally registered and available, the error message was unclear.
index 229e4af..7625cc7 100644 (file)
@@ -1,14 +1,19 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<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="intsplin" xml:lang="en">
+<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="intsplin" xml:lang="en">
     <refnamediv>
         <refname>intsplin</refname>
-        <refpurpose>integration of experimental data by spline
-            interpolation
+        <refpurpose>integration of experimental data by spline interpolation
         </refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>v = intsplin([x,] s)</synopsis>
+        <synopsis>
+          v = intsplin(y)
+          v = intsplin(x, y)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
                 <term>x</term>
                 <listitem>
                     <para>
-                        vector of increasing <literal>x</literal> coordinate data.
-                        Default value is <literal>1:size(y,'*')</literal>.
+                        Vector of increasing real abscissae. It must have the length of
+                        <literal>y</literal>. Default values are <literal>1:size(y,'*')</literal>.
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>s</term>
+                <term>y</term>
                 <listitem>
                     <para>
-                        vector of <literal>y</literal> coordinate data.
+                        vector of real or complex ordinates.
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
                 <term>v</term>
                 <listitem>
-                    <para>value of the integral.</para>
+                    <para>value of the integral. If <literal>y</literal> are complex numbers, the
+                      real and imaginary parts are integrated separately.
+                    </para>
                 </listitem>
             </varlistentry>
         </variablelist>
     </refsection>
     <refsection>
         <title>Description</title>
-        <para>Сomputes :</para>
         <para>
-            Where <literal>f</literal> is a function described by a set of experimental
-            value:
+            Let <literal>f</literal> be a function defined at some given sampled experimental points
+            <literal>(xi, yi=f(xi))</literal>.
+        </para>
+        <para>
+          <function>intsplin</function> computes an approximate of <literal>integral{f(x).dx}</literal>
+          from <literal>x0=x(1)</literal> to <literal>x1=x($)</literal>.
         </para>
         <para>
-            <literal>s(i)=f(x(i))</literal> and <literal>x0=x(1)</literal>,
-            <literal>x1=x(n)</literal>.
+            Between given points, <literal>f</literal> is approximated using a spline interpolation.
         </para>
-        <para>Between mesh points function is interpolated using spline's.</para>
     </refsection>
     <refsection>
         <title>Examples</title>
         <programlisting role="example"><![CDATA[
-t=0:0.1:%pi
+t = 0:0.1:%pi
 intsplin(t,sin(t))
- ]]></programlisting>
+
+intsplin(1:5)            // 12
+
+x = 0:0.1:0.4;
+intsplin(x, 1:5)         // 1.2
+
+intsplin((1:5)*%i)       // 12i
+intsplin(x, (1:5)*%i)    // 1.2i
+intsplin(x, x+(1:5)*%i)  // 0.08 + 1.2i
+]]></programlisting>
     </refsection>
     <refsection role="see also">
         <title>See also</title>
index 65d63f8..13fc7a2 100644 (file)
  * along with this program.
     *
     -->
-<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="intsplin">
+<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="intsplin">
     <refnamediv>
         <refname>intsplin</refname>
-        <refpurpose>intégration approchée de données expérimentales utilisant une interpolation par une spline.  </refpurpose>
+        <refpurpose>intégration approchée de données expérimentales utilisant une interpolation par une spline.</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Séquence d'appel</title>
-        <synopsis>v = intsplin([x,] s)</synopsis>
+        <synopsis>
+          v = intsplin(y)
+          v = intsplin(x, y)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Paramètres</title>
                 <term>x  </term>
                 <listitem>
                     <para>
-                        vecteur des abscisses, classées par ordre croissant. La valeur par défaut est <literal>1:size(y,'*')</literal>
+                        vecteur des abscisses (nombres réels), classées par ordre croissant.
+                        Il doit avoir autant d'éléments que <literal>y</literal>.
+                        Les valeurs par défaut sont <literal>1:size(y,'*')</literal>
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>s  </term>
+                <term>y</term>
                 <listitem>
-                    <para>vecteur des ordonnées.
+                    <para>vecteur des ordonnées, à valeurs réelles ou complexes.
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>v  </term>
+                <term>v</term>
                 <listitem>
                     <para>valeur de l'approximation de l'intégrale
                     </para>
     <refsection>
         <title>Description</title>
         <para>
-            Calcule une approximation de :
+            Soit <literal>f</literal> une fonction donnée sous forme de valeurs expérimentales
+          échantillonnées <literal>(xi, yi=f(xi))</literal>.
         </para>
         <para>
-            où <literal>f</literal> est donnée sous forme de valeurs expérimentales :
-        </para>
-        <para>
-            <literal>s(i)=f(x(i))</literal>  et <literal>x0=x(1)</literal>, <literal>x1=x(n)</literal>
+          <function>intsplin</function> calcule une approximation de <literal>integrale{f(x).dx}</literal>
+          de <literal>x0=x(1)</literal> à <literal>x1=x($)</literal>
         </para>
         <para>
             Entre les points, <literal>f</literal> est approchée à l'aide d'une spline.
     <refsection>
         <title>Exemples</title>
         <programlisting role="example"><![CDATA[
-t=0:0.1:%pi
+t = 0:0.1:%pi
 intsplin(t,sin(t))
+
+intsplin(1:5)            // 12
+
+x = 0:0.1:0.4;
+intsplin(x, 1:5)         // 1.2
+
+intsplin((1:5)*%i)       // 12i
+intsplin(x, (1:5)*%i)    // 1.2i
+intsplin(x, x+(1:5)*%i)  // 0.08 + 1.2i
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
index 423e25a..714bcde 100644 (file)
     <refsynopsisdiv>
 
         <title>呼び出し手順</title>
-
-        <synopsis>v = intsplin([x,] s)</synopsis>
-
+        <synopsis>
+          v = intsplin(y)
+          v = intsplin(x, y)
+        </synopsis>
     </refsynopsisdiv>
 
     <refsection>
@@ -46,7 +47,7 @@
 
             <varlistentry>
 
-                <term>s</term>
+                <term>y</term>
 
                 <listitem>
 
@@ -90,7 +91,7 @@
 
         <para>
 
-            <literal>s(i)=f(x(i))</literal> および <literal>x0=x(1)</literal>,
+            <literal>y(i)=f(x(i))</literal> および <literal>x0=x(1)</literal>,
 
             <literal>x1=x(n)</literal>
 
         <title>例</title>
 
         <programlisting role="example"><![CDATA[
-t=0:0.1:%pi
+t = 0:0.1:%pi
 intsplin(t,sin(t))
+
+intsplin(1:5)            // 12
+
+x = 0:0.1:0.4;
+intsplin(x, 1:5)         // 1.2
+
+intsplin((1:5)*%i)       // 12i
+intsplin(x, (1:5)*%i)    // 1.2i
+intsplin(x, x+(1:5)*%i)  // 0.08 + 1.2i
  ]]></programlisting>
 
     </refsection>
index c36df1f..a78fb85 100644 (file)
@@ -2,29 +2,32 @@
 <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="intsplin" xml:lang="pt">
     <refnamediv>
         <refname>intsplin</refname>
-        <refpurpose>integração de dados experimentais por interpolação por
+        <refpurpose>integração de dados experimentais por interpolação por
             spline
         </refpurpose>
     </refnamediv>
     <refsynopsisdiv>
-        <title>Seqüência de Chamamento</title>
-        <synopsis>v = intsplin([x,] s)</synopsis>
+        <title>Seqüência de Chamamento</title>
+        <synopsis>
+          v = intsplin(y)
+          v = intsplin(x, y)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
-        <title>Parâmetros</title>
+        <title>Parâmetros</title>
         <variablelist>
             <varlistentry>
                 <term>x</term>
                 <listitem>
                     <para>
                         vetor de dados de coordenadas <literal>x</literal> crescentes.
-                        O valor padrão é
+                        O valor padrão é
                         <literal>1:size(y,'*')</literal>
                     </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>s</term>
+                <term>y</term>
                 <listitem>
                     <para>
                         vetor de dados de coordenadas <literal>y</literal>
         </variablelist>
     </refsection>
     <refsection>
-        <title>Descrição</title>
+        <title>Descrição</title>
         <para>Computa :</para>
         <para>
-            Onde <literal>f</literal> é uma função descrita por um conjunto de valores
+            Onde <literal>f</literal> é uma função descrita por um conjunto de valores
             experimentais:
         </para>
         <para>
-            <literal>s(i)=f(x(i))</literal> e <literal>x0=x(1)</literal>,
+            <literal>y(i)=f(x(i))</literal> e <literal>x0=x(1)</literal>,
             <literal>x1=x(n)</literal>
         </para>
-        <para>Entre os pontos da malha a função é interpolada usando-se
+        <para>Entre os pontos da malha a função é interpolada usando-se
             splines.
         </para>
     </refsection>
     <refsection>
         <title>Exemplos</title>
         <programlisting role="example"><![CDATA[
-t=0:0.1:%pi
+t = 0:0.1:%pi
 intsplin(t,sin(t))
+
+intsplin(1:5)            // 12
+
+x = 0:0.1:0.4;
+intsplin(x, 1:5)         // 1.2
+
+intsplin((1:5)*%i)       // 12i
+intsplin(x, (1:5)*%i)    // 1.2i
+intsplin(x, x+(1:5)*%i)  // 0.08 + 1.2i
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
-        <title>Ver Também</title>
+        <title>Ver Também</title>
         <simplelist type="inline">
             <member>
                 <link linkend="intg">intg</link>
index 24111b8..5f5d68f 100644 (file)
@@ -8,7 +8,10 @@
     </refnamediv>
     <refsynopsisdiv>
         <title>Синтаксис</title>
-        <synopsis>v = intsplin([x,] s)</synopsis>
+        <synopsis>
+          v = intsplin(y)
+          v = intsplin(x, y)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Аргументы</title>
@@ -23,7 +26,7 @@
                 </listitem>
             </varlistentry>
             <varlistentry>
-                <term>s</term>
+                <term>y</term>
                 <listitem>
                     <para>
                         вектор ординат <literal>y</literal>.
@@ -42,7 +45,7 @@
         <title>Описание</title>
         <para>Вычисляет:</para>
         <para>
-            <literal>s(i)=f(x(i))</literal> и <literal>x0=x(1)</literal>,
+            <literal>y(i)=f(x(i))</literal> и <literal>x0=x(1)</literal>,
             <literal>x1=x(n)</literal>,
         </para>
         <para>
     <refsection>
         <title>Примеры</title>
         <programlisting role="example"><![CDATA[
-t=0:0.1:%pi
+t = 0:0.1:%pi
 intsplin(t,sin(t))
+
+intsplin(1:5)            // 12
+
+x = 0:0.1:0.4;
+intsplin(x, 1:5)         // 1.2
+
+intsplin((1:5)*%i)       // 12i
+intsplin(x, (1:5)*%i)    // 1.2i
+intsplin(x, x+(1:5)*%i)  // 0.08 + 1.2i
  ]]></programlisting>
     </refsection>
     <refsection role="see also">
index 92756a3..8f8179d 100644 (file)
@@ -1,5 +1,6 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) INRIA
+// Copyright (C) 2017 - Samuel GOUGEON
 //
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
@@ -10,7 +11,7 @@
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-function v = intsplin(x,s)
+function v = intsplin(x, s)
     //splin  numerical integration.
     //v = intsplin(x,s) computes the integral of y with respect to x using
     //splin interpolation and integration.
@@ -19,19 +20,32 @@ function v = intsplin(x,s)
     //v = intsplin(s) computes the integral of y assuming unit
     //spacing between the data points.
 
-    [lhs,rhs]=argn(0)
-    if rhs<2 then
-        s=x;
-        s=s(:);
-        d=splin((1:size(s,"*"))',s);
-        v=sum((d(1:$-1)-d(2:$))/12 + (s(1:$-1)+s(2:$))/2);
+    x = x(:);
+    if argn(2) < 2 then
+        s = x;
+        x = (1:size(s,"*"))';
     else
+        s = s(:);
         if size(x,"*")<>size(s,"*") then
-            error(msprintf(gettext("%s: Wrong size for input arguments: Same size expected.\n"),"intsplin"));
+            msg = _("%s: Wrong size for input arguments: Same size expected.\n")
+            error(msprintf(msg, "intsplin"));
         end
     end
-    x=x(:);s=s(:);
-    d=splin(x,s);
-    h=x(2:$)-x(1:$-1);
-    v=sum((h.*(d(1:$-1)-d(2:$))/12 + (s(1:$-1)+s(2:$))/2).*h);
+    if ~isreal(x) then
+        if isreal(x,%eps)
+            x = real(x);
+        else
+            msg = _("%s: Argument #%d: Real number(s) expected.\n");
+            error(msprintf(msg, "intsplin",1))
+        end
+    end
+    h = x(2:$) - x(1:$-1);
+    y = real(s);
+    d = splin(x, y);
+    v = sum((h.*(d(1:$-1)-d(2:$))/12 + (y(1:$-1)+y(2:$))/2).*h);
+    if ~isreal(s) then
+        y = imag(s);
+        d = splin(x, y);
+        v = v + %i*sum((h.*(d(1:$-1)-d(2:$))/12 + (y(1:$-1)+y(2:$))/2).*h);
+    end
 endfunction
diff --git a/scilab/modules/differential_equations/tests/nonreg_tests/bug_12862.tst b/scilab/modules/differential_equations/tests/nonreg_tests/bug_12862.tst
new file mode 100644 (file)
index 0000000..c7bfe77
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2017 - Samuel GOUGEON
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+// <-- NO CHECK REF -->
+//
+// <-- Non-regression test for bug 12862 -->
+//
+// <-- Bugzilla URL -->
+//http://bugzilla.scilab.org/12862
+//
+// <-- Short Description -->
+// intsplin() failed for complex ordinates
+
+x = 0.1:0.1:0.5;
+assert_checkequal(intsplin((1:5)*%i), 12*%i);
+assert_checkequal(intsplin(x, (1:5)*%i), 1.2*%i);
+assert_checkequal(intsplin(x, x+(1:5)*%i), 0.12 + 1.2*%i);