* Bug 15363 fixed: h2norm() failed with undefined time domain 07/19707/5
Samuel GOUGEON [Tue, 30 Jan 2018 01:15:18 +0000 (02:15 +0100)]
  http://bugzilla.scilab.org/15363

Change-Id: Ib294c0341382362259bcce690be08fc16893d7bc

scilab/CHANGES.md
scilab/modules/cacsd/help/en_US/control_design/h_infinity/h2norm.xml
scilab/modules/cacsd/help/ja_JP/control_design/h_infinity/h2norm.xml
scilab/modules/cacsd/macros/h2norm.sci
scilab/modules/cacsd/tests/nonreg_tests/bug_15363.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/nonreg_tests/bug_15363.tst [new file with mode: 0644]

index 460e4c5..1307626 100644 (file)
@@ -533,6 +533,7 @@ Known issues
 * [#15347](http://bugzilla.scilab.org/show_bug.cgi?id=15347): `toeplitz` failed with rationals.
 * [#15354](http://bugzilla.scilab.org/show_bug.cgi?id=15354): `invr(%s^2)` returned 0 instead of `1/%s^2`. For any scalar number, polynomial or rational `a`, `coffg(a)` returned `0` instead of `1`. `coffg([])` yielded an error. `invr` and `coffg` had no unitary tests. The `coffg` help page was inaccurate and unclear.
 * [#15360](http://bugzilla.scilab.org/show_bug.cgi?id=15360): `numer()` and `denom()` were almost useless, unused, and with more handy replacements. They are declared obsolete to be removed in Scilab 6.1.0.
+* [#15363](http://bugzilla.scilab.org/show_bug.cgi?id=15363): `h2norm()` could no longer be applied to undefined time domain systems, and made the residu() right example failing.
 * [#15370](http://bugzilla.scilab.org/show_bug.cgi?id=15370): `bezout()` mishandled its output arguments.
 * [#15375](http://bugzilla.scilab.org/show_bug.cgi?id=15375): A .zcos file opened as a palette was greyed out.
 * [#15395](http://bugzilla.scilab.org/show_bug.cgi?id=15395): `ones(2,3,2) / %z` yielded an error..
index 6fb831d..2414a57 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="en" xml:id="h2norm">
+<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="en" xml:id="h2norm">
     <refnamediv>
         <refname>h2norm</refname>
         <refpurpose>H2 norm of a continuous time proper dynamical system</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>Syntax</title>
-        <synopsis>[n]=h2norm(Sl [,tol])</synopsis>
+        <synopsis>
+          n = h2norm(Sl)
+          n = h2norm(Sl, tol)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>Arguments</title>
             <varlistentry>
                 <term>Sl</term>
                 <listitem>
-                    <para>continuous time proper linear dynamical system</para>
+                    <para>
+                      Proper linear dynamical system in non-discrete (continuous or undefined)
+                      time domain
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
@@ -42,7 +51,7 @@
     <refsection>
         <title>Description</title>
         <para>
-            produces the H2 norm  of a linear continuous time system <literal>Sl</literal>.
+            produces the H2 norm of a linear continuous time system <literal>Sl</literal>.
         </para>
         <para>
             (For <literal>Sl</literal> in state-space form <literal>h2norm</literal> uses the observability
@@ -62,9 +71,8 @@
             <revision>
                 <revnumber>5.4.0</revnumber>
                 <revremark>
-                    <literal>Sl</literal> is now checked for
-                    continuous time linear dynamical system.  This modification
-                    has been introduced by this <ulink url="http://gitweb.scilab.org/?p=scilab.git;a=commit;h=3d7083daae3339813ba747c8adcda1f9599bb80d">commit</ulink>
+                    <literal>Sl</literal> is now checked for non-discrete (continuous or undefined)
+                    time linear dynamical system.
                 </revremark>
             </revision>
         </revhistory>
index 65d7d5d..de5877e 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="ja" xml:id="h2norm">
+<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="ja" xml:id="h2norm">
     <refnamediv>
         <refname>h2norm</refname>
         <refpurpose>連続時間プロパー動的システムのH2ノルム</refpurpose>
     </refnamediv>
     <refsynopsisdiv>
         <title>呼び出し手順</title>
-        <synopsis>[n]=h2norm(Sl [,tol])</synopsis>
+        <synopsis>
+          n = h2norm(Sl)
+          n = h2norm(Sl, tol)
+        </synopsis>
     </refsynopsisdiv>
     <refsection>
         <title>引数</title>
@@ -29,7 +35,7 @@
                 <term>Sl</term>
                 <listitem>
                     <para>
-                        連続時間プロパー線形動的システム
+                        非離散(連続または未定義)時間領域における適切な線形動的システム
                     </para>
                 </listitem>
             </varlistentry>
@@ -67,9 +73,8 @@
             <revision>
                 <revnumber>5.4.0</revnumber>
                 <revremark>
-                    <literal>Sl</literal>が
-                    連続時間線形システムであることを確認するようになりました.
-                    この修正は,この <ulink url="http://gitweb.scilab.org/?p=scilab.git;a=commit;h=3d7083daae3339813ba747c8adcda1f9599bb80d">コミット</ulink>により導入されました.
+                  <literal>Sl</literal>は、非離散(連続または未定義)
+                  の時間領域線形システムであることが検査されるようになりました。
                 </revremark>
             </revision>
         </revhistory>
index 759d6c3..b9a3d72 100644 (file)
@@ -24,10 +24,12 @@ function [nh]=h2norm(g,tol)
 
     if type(g)==1,if norm(g)==0,nh=0,return,end,end,
     if and(typeof(g)<>["rational","state-space"]) then
-        error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"h2norm",1))
+        msg = gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n")
+        error(msprintf(msg, "h2norm", 1))
     end
-    if g.dt<>"c" then
-        error(msprintf(gettext("%s: Wrong type for argument #%d: In continuous time expected.\n"),"h2norm",1))
+    if g.dt<>"c" & g.dt<>[] then
+        msg = gettext("%s: Wrong type for argument #%d: In continuous or undefined time domain expected.\n")
+        error(msprintf(msg,"h2norm",1))
     end
 
     [lhs,rhs]=argn(0),
@@ -35,43 +37,51 @@ function [nh]=h2norm(g,tol)
         tol=1000*%eps,
     else
         if type(tol)<>1|size(tol,"*")<>1 then
-            error(msprintf(gettext("%s: Wrong type for input argument: Scalar expected.\n"),"h2norm",2))
+            msg = gettext("%s: Wrong type for input argument: Scalar expected.\n")
+            error(msprintf(msg, "h2norm", 2))
         end
         if ~isreal(tol)|tol<=0 then
-            error(msprintf(gettext( "%s: Input argument #%d must be strictly positive.\n"),"h2norm",2))
+            msg = gettext( "%s: Input argument #%d must be strictly positive.\n")
+            error(msprintf(msg, "h2norm", 2))
         end
     end;
     select typeof(g)
     case "state-space" then
         if norm(g.D)>0 then
-            error(msprintf(gettext("%s: Wrong value for input argument #%d: Proper system expected.\n"),"h2norm",1)),
+            msg = gettext("%s: Wrong value for input argument #%d: Proper system expected.\n")
+            error(msprintf(msg, "h2norm", 1)),
         end;
-        sp=spec(g.A),
+        sp = spec(g.A),
         if max(real(sp))>=-tol then
-            error(msprintf(gettext("%s: Wrong value for input argument #%d: Stable system expected.\n"),"h2norm",1)),
+            msg = gettext("%s: Wrong value for input argument #%d: Stable system expected.\n")
+            error(msprintf(msg, "h2norm", 1)),
         end,
         w=obs_gram(g.A,g.C,"c"),
         nh=abs(sqrt(sum(diag(g.B'*w*g.B)))),return,
     case "rational" then
-        num=g.num;
-        den=g.den;
-        s=poly(0,varn(den)),
-        [t1,t2]=size(num),
-        for i=1:t1,
-            for j=1:t2,
-                n=num(i,j),d=den(i,j),
+        num = g.num;
+        den = g.den;
+        s = poly(0,varn(den))
+        [t1,t2] = size(num)
+        for i = 1:t1,
+            for j = 1:t2,
+                n = num(i,j)
+                d = den(i,j),
                 if coeff(n)==0 then
-                    nh(i,j)=0,
+                    nh(i,j) = 0
                 else
-                    if degree(n)>=degree(d) then
-                        error(msprintf(gettext("%s: Wrong value for input argument #%d: Proper system expected.\n"),"h2norm",1)),
+                    if degree(n) >= degree(d) then
+                        msg = gettext("%s: Wrong value for input argument #%d: Proper system expected.\n")
+                        error(msprintf(msg, "h2norm", 1)),
                     end
-                    pol=roots(d),
+                    pol = roots(d),
                     if max(real(pol))>-tol then
-                        error(msprintf(gettext("%s: Wrong value for input argument #%d: Stable system expected.\n"),"h2norm",1)),
+                        msg = gettext("%s: Wrong value for input argument #%d: Stable system expected.\n")
+                        error(msprintf(msg, "h2norm", 1))
                     end,
-                    nt=horner(n,-s),dt=horner(d,-s),
-                    nh(i,j)=residu(n*nt,d,dt),
+                    nt = horner(n,-s)
+                    dt = horner(d,-s)
+                    nh(i,j) = residu(n*nt,d,dt)
                 end,
             end
         end
diff --git a/scilab/modules/cacsd/tests/nonreg_tests/bug_15363.dia.ref b/scilab/modules/cacsd/tests/nonreg_tests/bug_15363.dia.ref
new file mode 100644 (file)
index 0000000..b352f59
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - ESI-Group - Adeline CARNIS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 15363 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=15363
+//
+// <-- Short Description -->
+// `h2norm()` could no longer be applied to undefined time domain systems, and 
+// made the residu() right example failing.
+s = poly(0,'s');
+H = [s/(s+1)^2,1/(s+2)];N=H.num;D=H.den;
+w = residu(N.*horner(N,-s),D,horner(D,-s));  //N(s) N(-s) / D(s) D(-s)
+assert_checkalmostequal(sqrt(sum(w)), h2norm(tf2ss(H)));
diff --git a/scilab/modules/cacsd/tests/nonreg_tests/bug_15363.tst b/scilab/modules/cacsd/tests/nonreg_tests/bug_15363.tst
new file mode 100644 (file)
index 0000000..a6a3fed
--- /dev/null
@@ -0,0 +1,22 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2018 - ESI-Group - Adeline CARNIS
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 15363 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=15363
+//
+// <-- Short Description -->
+// `h2norm()` could no longer be applied to undefined time domain systems, and 
+// made the residu() right example failing.
+
+s = poly(0,'s');
+H = [s/(s+1)^2,1/(s+2)];N=H.num;D=H.den;
+w = residu(N.*horner(N,-s),D,horner(D,-s));  //N(s) N(-s) / D(s) D(-s)
+assert_checkalmostequal(sqrt(sum(w)), h2norm(tf2ss(H)));