* Bug #11941 fixed - show_margins() failed in 'nyquist' mode if the system is 93/10393/2
Charlotte HECQUET [Mon, 4 Feb 2013 10:01:07 +0000 (11:01 +0100)]
                     in state-space form.

Change-Id: I9a18c0fc17452e94e7ca55a66a271a4ae2393cf5

scilab/CHANGES_5.4.X
scilab/modules/cacsd/macros/show_margins.sci
scilab/modules/cacsd/tests/nonreg_tests/bug_11941.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/nonreg_tests/bug_11941.tst [new file with mode: 0644]

index 9c57246..1fa5302 100644 (file)
@@ -235,6 +235,9 @@ Bug fixes
 
 * Bug #11939 fixed - ssprint formatting was slightly not right.
 
+* Bug #11941 fixed - show_margins() failed in 'nyquist' mode if the system is
+                     in state-space form.
+
 * Bug #11952 fixed - In SciNotes, a Java exception occured on selection of text
                     containing a \E.
 
index 2bbfe55..ed8fa15 100644 (file)
@@ -8,83 +8,86 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
 
 function show_margins(h,typ)
-  if argn(2)<2 then typ='bode',end
-  if and(typ<>['nyquist','bode']) then
-    error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
-                  "show_margins",2,'""nyquist"", ""bode""'))
-  end
-  
-  fig=gcf();
-  immediate_drawing=fig.immediate_drawing;
-  fig.immediate_drawing="off";
+    if argn(2)<2 then typ='bode',end
+    if and(typ<>['nyquist','bode']) then
+        error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),..
+        "show_margins",2,'""nyquist"", ""bode""'))
+    end
 
-  clf();
-  if typ=="bode" then
-    bode(h)
-    f=gcf();
-    axg=f.children(2);
-    axp=f.children(1);
-    fmin=min(axg.x_ticks.locations);
-    fmax=max(axg.x_ticks.locations);
-    gmin=min(axg.y_ticks.locations);
-    gmax=max(axg.y_ticks.locations);
-    pmin=min(axp.y_ticks.locations);
-    pmax=max(axp.y_ticks.locations);
+    fig=gcf();
+    immediate_drawing=fig.immediate_drawing;
+    fig.immediate_drawing="off";
 
-    [gm,fr]=g_margin(h)
-    sca(axp);
-    xpoly([fmin;fmax],[-180;-180])
-    e=gce();e.foreground=color('red');e.line_style=4;
-    if fr<>[] then
-      xpoly([fr;fr],[pmin;pmax])
-      e=gce();e.foreground=color('red');e.line_style=4;
-      sca(axg);
-      xpoly([fr;fr],[gmin;gmax])
-      e=gce();e.foreground=color('red');e.line_style=4;
-      xpoly([fr;fr],[-gm;0])
-      e=gce();e.foreground=color('red');e.thickness=2;
-    end
+    clf();
+    if typ=="bode" then
+        bode(h)
+        f=gcf();
+        axg=f.children(2);
+        axp=f.children(1);
+        fmin=min(axg.x_ticks.locations);
+        fmax=max(axg.x_ticks.locations);
+        gmin=min(axg.y_ticks.locations);
+        gmax=max(axg.y_ticks.locations);
+        pmin=min(axp.y_ticks.locations);
+        pmax=max(axp.y_ticks.locations);
 
-    [phm,fr]=p_margin(h)
-    sca(axg);
-    xpoly([fmin;fmax],[0;0])
-    e=gce();e.foreground=color('blue');e.line_style=4;
-    if fr<>[] then
-      xpoly([fr;fr],[gmin;gmax])
-      e=gce();e.foreground=color('blue');e.line_style=4;
-      sca(axp);
-      xpoly([fr;fr],[pmin;pmax])
-      e=gce();e.foreground=color('blue');e.line_style=4;
-      xpoly([fr;fr],[-180;phm-180])
-      e=gce();e.foreground=color('blue');e.thickness=2;
-    end
-  else
-    nyquist(h)
-    ax=gca();
-    [gm,fr]=g_margin(h)
-    xpoly([min(ax.x_ticks.locations);0],[0;0]);
-    e=gce();e.foreground=color('blue');e.line_style=4;
-    if fr<>[] then
-      if h.dt=='c' then
-       f=horner(h,2*%i*%pi*fr)
-      else
-       dt=h.dt;if dt=='d' then dt=1,end
-       f=horner(h,exp(2*%i*%pi*fr*dt))
-      end
-      xpoly([real(f);0],[0;0]);
-      e=gce();e.foreground=color('blue');e.thickness=2;
-    end
-    [phm,fr]=p_margin(h)
-    //unit circle
-    t=linspace(0,2*%pi,100);
-    xpoly(sin(t),cos(t))
-    e=gce();e.foreground=color('red');e.line_style=4;
-    if fr<>[] then
-      t=phm*%pi/180+%pi;
-      xpoly([cos(t);0],[sin(t);0])
-      e=gce();e.foreground=color('red');e.thickness=2;
+        [gm,fr]=g_margin(h)
+        sca(axp);
+        xpoly([fmin;fmax],[-180;-180])
+        e=gce();e.foreground=color('red');e.line_style=4;
+        if fr<>[] then
+            xpoly([fr;fr],[pmin;pmax])
+            e=gce();e.foreground=color('red');e.line_style=4;
+            sca(axg);
+            xpoly([fr;fr],[gmin;gmax])
+            e=gce();e.foreground=color('red');e.line_style=4;
+            xpoly([fr;fr],[-gm;0])
+            e=gce();e.foreground=color('red');e.thickness=2;
+        end
+
+        [phm,fr]=p_margin(h)
+        sca(axg);
+        xpoly([fmin;fmax],[0;0])
+        e=gce();e.foreground=color('blue');e.line_style=4;
+        if fr<>[] then
+            xpoly([fr;fr],[gmin;gmax])
+            e=gce();e.foreground=color('blue');e.line_style=4;
+            sca(axp);
+            xpoly([fr;fr],[pmin;pmax])
+            e=gce();e.foreground=color('blue');e.line_style=4;
+            xpoly([fr;fr],[-180;phm-180])
+            e=gce();e.foreground=color('blue');e.thickness=2;
+        end
+    else
+        if typeof(h)=='state-space' then
+            h=ss2tf(h);
+        end
+        nyquist(h)
+        ax=gca();
+        [gm,fr]=g_margin(h)
+        xpoly([min(ax.x_ticks.locations);0],[0;0]);
+        e=gce();e.foreground=color('blue');e.line_style=4;
+        if fr<>[] then
+            if h.dt=='c' then
+                f=horner(h,2*%i*%pi*fr)
+            else
+                dt=h.dt;if dt=='d' then dt=1,end
+                f=horner(h,exp(2*%i*%pi*fr*dt))
+            end
+            xpoly([real(f);0],[0;0]);
+            e=gce();e.foreground=color('blue');e.thickness=2;
+        end
+        [phm,fr]=p_margin(h)
+        //unit circle
+        t=linspace(0,2*%pi,100);
+        xpoly(sin(t),cos(t))
+        e=gce();e.foreground=color('red');e.line_style=4;
+        if fr<>[] then
+            t=phm*%pi/180+%pi;
+            xpoly([cos(t);0],[sin(t);0])
+            e=gce();e.foreground=color('red');e.thickness=2;
+        end
     end
-  end
-  fig.immediate_drawing=immediate_drawing; 
+    fig.immediate_drawing=immediate_drawing; 
 
 endfunction
diff --git a/scilab/modules/cacsd/tests/nonreg_tests/bug_11941.dia.ref b/scilab/modules/cacsd/tests/nonreg_tests/bug_11941.dia.ref
new file mode 100644 (file)
index 0000000..06a58a0
--- /dev/null
@@ -0,0 +1,19 @@
+// =============================================================================
+// 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.
+// =============================================================================
+//
+// <-- Non-regression test for bug 11941 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=11941
+//
+// <-- Short Description -->
+// show_margins() fails in 'nyquist' mode if the system is in state-space form. It
+// assumes the system is in transfer function form and calls horner() with it.
+h=syslin('c',0.02909+0.11827*%s+0.12823*%s^2+0.35659*%s^3+0.256*%s^4+0.1*%s^5,..
+             0.0409+0.1827*%s+1.28225*%s^2+3.1909*%s^3+2.56*%s^4+%s^5);
+h1=tf2ss(h);
+assert_checktrue(execstr("show_margins(h1,""nyquist"");","errcatch")==0);
diff --git a/scilab/modules/cacsd/tests/nonreg_tests/bug_11941.tst b/scilab/modules/cacsd/tests/nonreg_tests/bug_11941.tst
new file mode 100644 (file)
index 0000000..711e3b6
--- /dev/null
@@ -0,0 +1,20 @@
+// =============================================================================
+// 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.
+// =============================================================================
+//
+// <-- Non-regression test for bug 11941 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=11941
+//
+// <-- Short Description -->
+// show_margins() fails in 'nyquist' mode if the system is in state-space form. It
+// assumes the system is in transfer function form and calls horner() with it.
+
+h=syslin('c',0.02909+0.11827*%s+0.12823*%s^2+0.35659*%s^3+0.256*%s^4+0.1*%s^5,..
+             0.0409+0.1827*%s+1.28225*%s^2+3.1909*%s^3+2.56*%s^4+%s^5);
+h1=tf2ss(h);
+assert_checktrue(execstr("show_margins(h1,""nyquist"");","errcatch")==0);