missing functions for zpk representation added 09/18209/8
Serge Steer [Thu, 2 Jun 2016 13:31:27 +0000 (15:31 +0200)]
Change-Id: I0d6de81fc308ce33436194bdf44e3699bd9f3d98

183 files changed:
scilab/CHANGES.md
scilab/modules/cacsd/help/en_US/control_design/pole_placement/kpure.xml
scilab/modules/cacsd/help/en_US/control_design/pole_placement/krac2.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/black.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/bode.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/calfrq.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/freson.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/gainplot.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/nyquist.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/nyquistfrequencybounds.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/phasemag.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/phaseplot.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/repfreq.xml
scilab/modules/cacsd/help/en_US/linear_analysis/freq_domain/trzeros.xml
scilab/modules/cacsd/help/en_US/linear_analysis/stability/plzr.xml
scilab/modules/cacsd/help/en_US/linear_analysis/time_domain/csim.xml
scilab/modules/cacsd/help/en_US/linear_analysis/time_domain/damp.xml
scilab/modules/cacsd/help/en_US/linear_analysis/time_domain/flts.xml
scilab/modules/cacsd/help/en_US/linear_system_representation/ss2zp.xml [new file with mode: 0644]
scilab/modules/cacsd/help/en_US/linear_system_representation/tf2zp.xml [new file with mode: 0644]
scilab/modules/cacsd/help/en_US/linear_system_representation/zp2ss.xml [new file with mode: 0644]
scilab/modules/cacsd/help/en_US/linear_system_representation/zp2tf.xml [new file with mode: 0644]
scilab/modules/cacsd/help/en_US/linear_system_representation/zpk.xml [new file with mode: 0644]
scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2ss.xml [new file with mode: 0644]
scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2tf.sci [new file with mode: 0644]
scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2tf.xml [new file with mode: 0644]
scilab/modules/cacsd/macros/black.sci
scilab/modules/cacsd/macros/bode.sci
scilab/modules/cacsd/macros/bode_asymp.sci
scilab/modules/cacsd/macros/calfrq.sci
scilab/modules/cacsd/macros/csim.sci
scilab/modules/cacsd/macros/damp.sci
scilab/modules/cacsd/macros/dscr.sci
scilab/modules/cacsd/macros/findCommonValues.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/flts.sci
scilab/modules/cacsd/macros/freson.sci
scilab/modules/cacsd/macros/g_margin.sci
scilab/modules/cacsd/macros/gainplot.sci
scilab/modules/cacsd/macros/krac2.sci
scilab/modules/cacsd/macros/nearly_multiples.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/nyquist.sci
scilab/modules/cacsd/macros/nyquistfrequencybounds.sci
scilab/modules/cacsd/macros/overloadname.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/p_margin.sci
scilab/modules/cacsd/macros/phaseplot.sci
scilab/modules/cacsd/macros/plzr.sci
scilab/modules/cacsd/macros/reduceToCommonDenominator.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/repfreq.sci
scilab/modules/cacsd/macros/rlocus.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/simplify_zp.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/ss2zp.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/tf2zp.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/trzeros.sci
scilab/modules/cacsd/macros/zp2ss.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/zp2tf.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/zpk.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/zpk2ss.sci [new file with mode: 0644]
scilab/modules/cacsd/macros/zpk2tf.sci [new file with mode: 0644]
scilab/modules/cacsd/tests/nonreg_tests/bug_11092.dia.ref
scilab/modules/cacsd/tests/nonreg_tests/bug_13816.dia.ref
scilab/modules/cacsd/tests/nonreg_tests/bug_13831.dia.ref
scilab/modules/cacsd/tests/nonreg_tests/bug_4319.dia.ref
scilab/modules/cacsd/tests/nonreg_tests/bug_4596.dia.ref
scilab/modules/cacsd/tests/nonreg_tests/bug_8162.dia.ref
scilab/modules/cacsd/tests/unit_tests/arma2ss.dia.ref
scilab/modules/cacsd/tests/unit_tests/bode.dia.ref
scilab/modules/cacsd/tests/unit_tests/bode.tst
scilab/modules/cacsd/tests/unit_tests/calfrq.dia.ref
scilab/modules/cacsd/tests/unit_tests/calfrq.tst
scilab/modules/cacsd/tests/unit_tests/csim.dia.ref
scilab/modules/cacsd/tests/unit_tests/csim.tst
scilab/modules/cacsd/tests/unit_tests/damp.dia.ref
scilab/modules/cacsd/tests/unit_tests/damp.tst
scilab/modules/cacsd/tests/unit_tests/dhinf.dia.ref
scilab/modules/cacsd/tests/unit_tests/dscr.dia.ref
scilab/modules/cacsd/tests/unit_tests/dscr.tst
scilab/modules/cacsd/tests/unit_tests/dscr.tst.orig [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/flts.dia.ref
scilab/modules/cacsd/tests/unit_tests/flts.tst
scilab/modules/cacsd/tests/unit_tests/freqplots.dia.ref
scilab/modules/cacsd/tests/unit_tests/freqplots.tst
scilab/modules/cacsd/tests/unit_tests/freson.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/freson.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/margins.dia.ref
scilab/modules/cacsd/tests/unit_tests/margins.tst
scilab/modules/cacsd/tests/unit_tests/nyquist.dia.ref
scilab/modules/cacsd/tests/unit_tests/nyquist.tst
scilab/modules/cacsd/tests/unit_tests/ss2zp.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/ss2zp.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/tf2zp.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/tf2zp.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zp2ss.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zp2ss.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zp2tf.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zp2tf.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zpk.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zpk.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zpk2ss.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zpk2ss.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zpk2tf.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/zpk2tf.tst [new file with mode: 0644]
scilab/modules/helptools/etc/images_md5.txt
scilab/modules/helptools/images/_LaTeX_ss2zp.xml_1.png [new file with mode: 0644]
scilab/modules/helptools/images/freson_1.png
scilab/modules/helptools/images/freson_2.png [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_a_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_c_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_d_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_f_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_l_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_m_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_q_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_s_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%lss_x_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_a_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_c_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_d_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_f_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_l_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_m_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_q_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_s_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%r_x_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_a_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_c_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_d_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_f_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_i_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_l_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_m_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_q_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_s_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%s_x_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_a_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_a_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_a_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_a_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_c_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_c_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_c_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_c_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_d_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_d_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_d_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_d_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_e.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_f_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_f_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_f_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_f_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_i_h.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_i_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_i_st.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_i_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_l_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_m_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_m_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_m_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_m_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_n_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_o_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_p.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_q_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_q_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_q_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_q_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_r_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_r_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_r_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_r_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_s_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_s_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_s_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_s_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_size.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_sum.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_t.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_v_zpk.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_x_lss.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_x_r.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_x_s.sci [new file with mode: 0644]
scilab/modules/overloading/macros/%zpk_x_zpk.sci [new file with mode: 0644]

index dd2d2ef..ec3d65c 100644 (file)
@@ -200,7 +200,9 @@ or a 3-components vector to set the position in axes coordinates to draw the dat
 * The `grand` non-free `fsultra` generator was removed.
 * The original `rpoly` algorithm was removed in favor of a C++11 implementation
 * When the view property of Axes object is set at `2d`, the rotation becomes impossible.
+* The zero-pole-gain (zpk) representation added for linear dynamical systems.
 
 Help pages:
 -----------
 
index 97bde0b..e3a18c0 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
+ * Copyright (C) 2000 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
             <varlistentry>
                 <term>sys</term>
                 <listitem>
-                    <para>SISO linear system (syslin)</para>
+                    <para>
+                        A SISO linear dynamical system, in state space,
+                        transfer function or zpk representations, in
+                        continuous or discrete time.
+                    </para>
                 </listitem>
             </varlistentry>
             <varlistentry>
@@ -118,4 +122,16 @@ plot(real(Y),imag(Y),'+r')
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>Handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
index b8f2ca3..e8b7115 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
+ * Copyright (C) 2000 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -28,7 +28,9 @@
             <varlistentry>
                 <term>sys</term>
                 <listitem>
-                    <para>SISO linear system (syslin)</para>
+                    A SISO linear dynamical system, in state space,
+                    transfer function or zpk representations, in
+                    continuous or discrete time.
                 </listitem>
             </varlistentry>
             <varlistentry>
@@ -67,4 +69,16 @@ hf2=h/.g(2);roots(denom(hf2))
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
index c57f5d7..47b086d 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA
+ * Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
             <varlistentry>
                 <term>sl</term>
                 <listitem>
-                    <para>a continuous or discrete time SIMO linear dynamical
-                        system ( see: <link linkend="syslin">syslin</link>).
+                    <para>
+                        A siso or simo linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
     <refsection>
         <title>Description</title>
         <para>
-            Black's diagram (Nichols'chart) for a linear system ( see: <link linkend="syslin">syslin</link>). <literal>sl</literal> can be a continuous-time or
-            discrete-time SIMO system. In case of
-            multi-output the outputs are plotted with different colors.
+            Black's diagram (Nichols'chart) for a linear dynamical system .
         </para>
-        <para>The frequencies are given by the bounds
-            <literal>fmin</literal>,<literal>fmax</literal> (in Hz) or by a row-vector
-            (or a matrix for multi-output) <literal>frq</literal>.
+
+        <para>
+            <literal>sl</literal> can be a continuous-time or
+            discrete-time SIMO system given by its state space,
+            rational transfer function (see <link
+            linkend="syslin">syslin</link>) or <link
+            linkend="zpk">zpk</link> representation. In case of
+            multi-output the outputs are plotted with different
+            colors.
+        </para>
+
+        <para>
+            The frequencies are given by the bounds
+            <literal>fmin</literal>,<literal>fmax</literal> (in Hz) or
+            by a row-vector (or a matrix for multi-output)
+            <literal>frq</literal>.
         </para>
         <para>
-            <literal>step</literal> is the ( logarithmic ) discretization step.
-            (see <link linkend="calfrq">calfrq</link> for the choice of default value).
+            <literal>step</literal> is the ( logarithmic )
+            discretization step.  (see <link
+          linkend="calfrq">calfrq</link> for the choice of default
+            value).
         </para>
         <para>
             <literal>comments</literal> is a vector of character strings
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index c5c7659..1719712 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA
+ *  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -36,8 +36,7 @@
                 <term>sl</term>
                 <listitem>
                     <para>
-                        <literal>syslin</literal> list (SISO or SIMO linear system)
-                        in continuous or discrete time.
+                        A siso or simo linear dynamical system, in state space, transfer function or zpk representations, in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
     </refsection>
     <refsection>
         <title>Description</title>
-        <para>Bode plot, i.e magnitude and phase of the frequency response of
-            <literal>sl</literal>.
+        <para>Bode plot, i.e magnitude and phase of the frequency
+            response of the linear dynamical system <literal>sl</literal>.
         </para>
         <para>
-            <literal>sl</literal> can be a continuous-time or discrete-time SIMO
-            system (see <literal>syslin</literal>). In case of multi-output the
-            outputs are plotted with different symbols.
+            <literal>sl</literal> can be a continuous-time or
+            discrete-time SIMO system given by its state space,
+            rational transfer function (see <link
+            linkend="syslin">syslin</link>) or <link
+            linkend="zpk">zpk</link> representation. In case of
+            multi-output the outputs are plotted with different
+            colors.
         </para>
         <para>
             The frequencies are given by the bounds <literal>fmin,fmax</literal>
@@ -233,4 +236,15 @@ clf(); bode(sys, f_min, f_max, "rad"); // Converts Hz to rad/s
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 05da2b5..90d9378 100644 (file)
             <varlistentry>
                 <term>h</term>
                 <listitem>
-                    <para>Linear system in state space or transfer representation
-                        (
-                        <literal>
-                            see <link linkend="syslin">syslin</link>
-                        </literal>
-                        )
+                    <para>
+                        A siso or simo linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
@@ -123,4 +121,15 @@ plot2d(real(rf)',imag(rf)')
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 9ee12cd..0122b90 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
+ * Copyright (C) 2000 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -29,7 +29,7 @@
                 <term>h</term>
                 <listitem>
                     <para>
-                        <literal>syslin</literal> list
+                        A siso linear dynamical system, in state space, transfer function or zpk representations.
                     </para>
                 </listitem>
             </varlistentry>
     <refsection>
         <title>Description</title>
         <para>
-            returns the vector of peak frequencies in Hz for the SISO plant
-            <literal>h</literal>
+            returns the vector frequencies at which the response
+            amplitude of a siso dynamical system is a relative maximum
+            also called resonance frequencies.
+
         </para>
     </refsection>
     <refsection>
         <title>Examples</title>
+        <para>Continuous time system</para>
         <programlisting role="example"><![CDATA[
-h=syslin('c',-1+%s,(3+2*%s+%s^2)*(50+0.1*%s+%s^2))
+h=syslin('c',-1+%s,(3+2*%s+%s^2)*(50+0.1*%s+%s^2));
 fr=freson(h)
-bode(h)
-g=20*log(abs(repfreq(h,fr)))/log(10)
- ]]></programlisting>
+clf;bode(h);
+fig=gcf();sca(fig.children(2));
+[phi,db]=phasemag(repfreq(h,fr));
+plot(fr,db(:),'+r')
+]]></programlisting>
         <scilab:image>
-            h=syslin('c',-1+%s,(3+2*%s+%s^2)*(50+0.1*%s+%s^2))
+            h=syslin('c',-1+%s,(3+2*%s+%s^2)*(50+0.1*%s+%s^2));
             fr=freson(h)
-            bode(h)
-            g=20*log(abs(repfreq(h,fr)))/log(10)
+            clf;bode(h);
+            fig=gcf();sca(fig.children(2));
+            [phi,db]=phasemag(repfreq(h,fr));
+            plot(fr,db(:),'+r');
+        </scilab:image>
+        <para>Discrete time system</para>
+        <programlisting role="example"><![CDATA[
+hd=dscr(h,0.01)
+fr=freson(hd)
+clf;bode(hd);
+fig=gcf();sca(fig.children(2));
+[phi,db]=phasemag(repfreq(hd,fr));
+plot(fr,db(:),'+r');
+
+ ]]></programlisting>
+        <scilab:image>
+            h=syslin('c',-1+%s,(3+2*%s+%s^2)*(50+0.1*%s+%s^2));
+            hd=dscr(h,0.05);
+            fr=freson(hd);
+            clf;bode(hd);
+            fig=gcf();sca(fig.children(2));
+            [phi,db]=phasemag(repfreq(hd,fr));
+            plot(fr,db(:),'+r');
         </scilab:image>
     </refsection>
     <refsection role="see also">
@@ -77,4 +103,17 @@ g=20*log(abs(repfreq(h,fr)))/log(10)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling discrete systems and zpk
+                        representation, peak detection improved.
+                    </para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 4f7df31..94b72d0 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) INRIA
-*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
+ *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -32,7 +32,9 @@
                 <term>sl</term>
                 <listitem>
                     <para>
-                        list (<literal>syslin</literal> SIMO linear system).
+                        A siso or simo linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
index 693612e..3afcea0 100644 (file)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) INRIA
-*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
+ *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -34,7 +34,9 @@
                 <term>sl</term>
                 <listitem>
                     <para>
-                        a continuous or discrete time SIMO linear dynamical system ( see: <link linkend="syslin">syslin</link>).
+                        A siso or simo linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
             discretized systems )
         </para>
         <para>
-            <literal>sl</literal> can be a continuous-time or discrete-time SIMO
-            system (see <literal>syslin</literal>). In case of multi-output the
-            outputs are plotted with different symbols.
+            <literal>sl</literal> can be a continuous-time or
+            discrete-time SIMO system given by its state space,
+            rational transfer function (see <link
+            linkend="syslin">syslin</link>) or <link
+            linkend="zpk">zpk</link> representation. In case of
+            multi-output the outputs are plotted with different
+            colors.
+
         </para>
         <para>
             The frequencies are given by the bounds <literal>fmin,fmax</literal>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 84c55dc..c400de7 100644 (file)
@@ -1,6 +1,17 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
- * Add some comments about XML file
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
+ *
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * 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_US" xml:id="nyquistfrequencybounds">
     <refnamediv>
@@ -18,7 +29,9 @@
                 <term>H</term>
                 <listitem>
                     <para>
-                        A SISO linear dynamical system.
+                        A SISO or SIMO linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
                 <term>fmin</term>
                 <listitem>
                     <para>
-                        a real: the lowest frequency (Hz) such that the nyquist
-                        locus enters the given rectangle or 0 if the 0 Hz point
-                        lies in the rectangle or [] if the locus is completely
-                        outside the rectangle.
+                        a real: the lowest frequency (Hz) such that the
+                        nyquist locus enters the given rectangle or 0 if
+                        the 0 Hz point lies in the rectangle or [] if
+                        the locus is completely outside the rectangle.
                     </para>
                 </listitem>
             </varlistentry>
                 <term>fmax</term>
                 <listitem>
                     <para>
-                        a real: the highest frequency (Hz) such that the nyquist
-                        locus leaves the given rectangle or %inf if the %inf (hz)
-                        point is in the rectangle or [] if the locus is completely
-                        outside the rectangle.
+                        a real: the highest frequency (Hz) such that the
+                        nyquist locus leaves the given rectangle or %inf
+                        if the %inf (hz) point is in the rectangle or []
+                        if the locus is completely outside the
+                        rectangle.
                     </para>
                 </listitem>
             </varlistentry>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index cac7787..b00733a 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
+ *  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
index ed26c9c..34799a6 100644 (file)
@@ -1,16 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-*  Copyright (C) 2011 - INRIA - Serge Steer <serge.steer@inria.fr>
+*  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
 *
- * Copyright (C) 2012 - 2016 - Scilab Enterprises
- *
- * This file is hereby licensed under the terms of the GNU GPL v2.0,
- * pursuant to article 5.3.4 of the CeCILL v.2.1.
- * This file was originally licensed under the terms of the CeCILL v2.1,
- * and continues to be available under such terms.
- * For more information, see the COPYING file which you should have received
- * along with this program.
+* Copyright (C) 2012 - 2016 - Scilab Enterprises
+*
+* This file is hereby licensed under the terms of the GNU GPL v2.0,
+* pursuant to article 5.3.4 of the CeCILL v.2.1.
+* This file was originally licensed under the terms of the CeCILL v2.1,
+* and continues to be available under such terms.
+* For more information, see the COPYING file which you should have received
+* 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="phaseplot">
@@ -34,7 +34,9 @@
                 <term>sl</term>
                 <listitem>
                     <para>
-                        a single input multiple output (SIMO) linear dynamical system (see <link linkend="syslin">syslin</link>).
+                        A siso or simo linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
                     <literal>phaseplot(sl,...)</literal> case
                 </para>
                 <para>
-                    <literal>sl</literal> can be a continuous-time or discrete-time SIMO
-                    system (see <link linkend="syslin">syslin</link>). In case of multi-output the
-                    outputs are plotted with different symbols.
+                    <literal>sl</literal> can be a continuous-time or
+                    discrete-time SIMO system given by its state space,
+                    rational transfer function (see <link
+                  linkend="syslin">syslin</link>) or <link
+                  linkend="zpk">zpk</link> representation. In case of
+                    multi-output the outputs are plotted with different
+                    colors.
                 </para>
                 <para>In this case the frequencies can be  given by:</para>
                 <itemizedlist mark="point">
                     <listitem>
-                        <para>the lower and upper bounds in Hz
-                            <literal>fmin</literal>, <literal>fmax</literal> and an
-                            optional frequency step <literal>step</literal>. The
+                        <para>
+                            the lower and upper bounds in Hz
+                            <literal>fmin</literal>,
+                            <literal>fmax</literal> and an optional
+                            frequency step <literal>step</literal>. The
                             default values for <literal>fmin</literal> and
-                            <literal>fmax</literal>are <literal>1.e-3</literal>,
-                            <literal>1.e3</literal> if <literal>sl</literal> is
-                            continuous-time or <literal>1.e-3</literal>,
-                            <literal>0.5/sl.dt</literal> (nyquist frequency) if
-                            <literal>sl</literal> is discrete-time. If the
-                            <literal>step</literal> argument is omitted the function
-                            use an adaptative frequency step (see <link linkend="calfrq">calfrq</link>).
+                            <literal>fmax</literal>are
+                            <literal>1.e-3</literal>,
+                            <literal>1.e3</literal> if
+                            <literal>sl</literal> is continuous-time or
+                            <literal>1.e-3</literal>,
+                            <literal>0.5/sl.dt</literal> (nyquist
+                            frequency) if <literal>sl</literal> is
+                            discrete-time. If the <literal>step</literal>
+                            argument is omitted the function use an
+                            adaptative frequency step (see <link
+                        linkend="calfrq">calfrq</link>).
                         </para>
                     </listitem>
                     <listitem>
                         <para>
-                            a row vector or a 2D array <literal>frq</literal> which
-                            gives the frequency values in Hz. 2D array can be used for
-                            multi-output systems if one wants to have different frequency
-                            discretization for each input/output couple.
+                            a row vector or a 2D array
+                            <literal>frq</literal> which gives the
+                            frequency values in Hz. 2D array can be used
+                            for multi-output systems if one wants to
+                            have different frequency discretization for
+                            each input/output couple.
                         </para>
                     </listitem>
                 </itemizedlist>
             </listitem>
         </itemizedlist>
         <para>
-            The <link linkend="datatips">datatips</link> tool may be used to display data along the phase curves.
+            The <link linkend="datatips">datatips</link> tool may be
+            used to display data along the phase curves.
         </para>
     </refsection>
     <refsection>
                 <revnumber>5.4.0</revnumber>
                 <revremark>Function phaseplot introduced.</revremark>
             </revision>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revremark>handling zpk representation.</revremark>
+            </revision>
         </revhistory>
     </refsection>
 </refentry>
index 75a7741..9b2e60d 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA - Serge STEER
+ *  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -33,7 +33,9 @@
                 <term>sys</term>
                 <listitem>
                     <para>
-                        <literal>syslin</literal> list : SIMO linear system
+                        A siso or simo linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
@@ -139,4 +141,16 @@ repf(2)-x
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
index 0c3c942..453ee2a 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
+ * Copyright (C) 2008 - 2016 - F.D. - INRIA -
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -128,4 +128,16 @@ roots(St1(rowf,colf)), nt./dt     //By Kronecker form
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
index 8e34da0..5b22a81 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA
+ * Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
                 <term>sl</term>
                 <listitem>
                     <para>
-                        list ( <literal>syslin</literal>)
+                        A  linear dynamical system, in
+                        state space, transfer function or zpk
+                        representations, in continuous or discrete
+                        time.
                     </para>
                 </listitem>
             </varlistentry>
@@ -39,7 +42,7 @@
         <title>Description</title>
         <para>
             <code>plzr(sl)</code> produces a pole-zero plot of the linear system
-            <varname>sl</varname> (<literal>syslin</literal> list).
+            <varname>sl</varname>.
         </para>
     </refsection>
     <!--
@@ -73,6 +76,20 @@ plzr(h);
             <member>
                 <link linkend="syslin">syslin</link>
             </member>
+            <member>
+                <link linkend="zpk">zpk</link>
+            </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
 </refentry>
index 7dd4408..a6c5d6e 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
+ *  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -45,8 +45,9 @@
                 <term>sl</term>
                 <listitem>
                     <para>
-                        <literal>syslin</literal> list (SIMO linear system)
-                        in continuous time.
+                        A SISO or SIMO linear dynamical system, in state
+                        space, transfer function or zpk representations,
+                        in continuous  time.
                     </para>
                 </listitem>
             </varlistentry>
@@ -229,4 +230,16 @@ clf();plot2d([t',t'],[(csim(timefun,t,w))',0*t'])
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
index 955fe11..97616ff 100644 (file)
@@ -1,4 +1,18 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2010 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
+ *
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * 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_US" xml:id="damp">
     <refnamediv>
         <refname>damp</refname>
@@ -19,7 +33,9 @@
                 <term>sys</term>
                 <listitem>
                     <para>
-                        A linear dynamical system (see <link linkend="syslin">syslin</link>).
+                        A linear dynamical system, in state space,
+                        transfer function or zpk representations, in
+                        continuous or discrete time.
                     </para>
                 </listitem>
             </varlistentry>
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
index 75c24b0..061fe3d 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) INRIA -
+ *  Copyright (C) 1996 - 2016 - INRIA - Serge Steer <serge.steer@inria.fr>
  *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
  *
@@ -37,7 +37,9 @@
                 <term>sl</term>
                 <listitem>
                     <para>
-                        list (linear system <literal>syslin</literal>)
+                        A linear dynamical system, in state space,
+                        transfer function or zpk representations, in
+                        discrete time.
                     </para>
                 </listitem>
             </varlistentry>
@@ -221,4 +223,16 @@ norm([yh1,yh2]-rh)
             </member>
         </simplelist>
     </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>handling zpk representation</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
 </refentry>
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/ss2zp.xml b/scilab/modules/cacsd/help/en_US/linear_system_representation/ss2zp.xml
new file mode 100644 (file)
index 0000000..e004993
--- /dev/null
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Serge Steer - INRIA
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * For more information, see the COPYING file which you should have received
+ * 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="ss2zp">
+    <refnamediv>
+        <refname>ss2zp</refname>
+        <refpurpose>SIMO state space system to zero pole gain representation</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>[z,p,k]=ss2zp(S)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>S</term>
+                <listitem>
+                    <para>
+                        a single input linear system in state space representation.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>z</term>
+                <listitem>
+                    <para>
+                        a matrix, the ith column contains the transmission zeros relative to the ith output.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>p</term>
+                <listitem>
+                    <para>
+                        a column vector, the poles of the system
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>k</term>
+                <listitem>
+                    <para>
+                        a column vector, the ith element contains the gain  relative to the ith output.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            Converts a SIMO state space system into zero pole gain representation.
+        </para>
+        <para>
+            The zeros and gain are computed using the upper triangular
+            Kronecker form (see <link linkend="kroneck">kroneck</link>)
+            of the matrix pencil
+            <latex><![CDATA[\left[\begin{array}{ll}A-s I& B\\C &
+          D\end{array}\right]]]></latex>
+        </para>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+a=[ 0.9, 0,   -4.2;
+    0.2, 0.1,  0.6;
+    6.4, 0.1,  -4];
+
+b=[-0.1;0;-0.1];
+c=[2,0,-2;0,-1,3];
+d=[2;0];
+S=syslin('c',a,b,c,d);
+[z,p,k]=ss2zp(S)
+
+h=ss2tf(S(1,1))
+roots(h.num)
+ ]]></programlisting>
+        </refsection>
+        <refsection>
+            <title>References</title>
+            <para>
+                A. Emami-Naeini, P. Van Dooren "CComputation of zeros of linear multivariable systems" Automatica. Vol. 18, 1982, p. 415
+            </para>
+        </refsection>
+        <refsection role="see also">
+            <title>See Also</title>
+            <simplelist type="inline">
+                <member>
+                    <link linkend="trzeros">trzeros</link>
+                </member>
+                <member>
+                    <link linkend="systmat">systmat</link>
+                </member>
+                <member>
+                    <link linkend="kroneck">kroneck</link>
+                </member>
+                <member>
+                    <link linkend="zp2ss">zp2ss</link>
+                </member>
+            </simplelist>
+        </refsection>
+        <refsection role="history">
+            <title>History</title>
+            <revhistory>
+                <revision>
+                    <revnumber>6.0</revnumber>
+                    <revdescription>
+                        <para>Function added.</para>
+                    </revdescription>
+                </revision>
+            </revhistory>
+        </refsection>
+
+    </refentry>
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/tf2zp.xml b/scilab/modules/cacsd/help/en_US/linear_system_representation/tf2zp.xml
new file mode 100644 (file)
index 0000000..d9f2f90
--- /dev/null
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Serge Steer - INRIA
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * For more information, see the COPYING file which you should have received
+ * 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="tf2zp">
+    <refnamediv>
+        <refname>tf2zp</refname>
+        <refpurpose>SIMO transfer function to zero pole gain representation</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>[z,p,k]=tf2zp(S)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>S</term>
+                <listitem>
+                    <para>
+                        a single input transfer function.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>z</term>
+                <listitem>
+                    <para>
+                        a matrix, the ith column contains the transmission zeros relative to the ith output.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>p</term>
+                <listitem>
+                    <para>
+                        a column vector, the poles of the system
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>k</term>
+                <listitem>
+                    <para>
+                        a row vector, the ith element contains the gain  relative to the ith output.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            Converts a SIMO transfer function into zero pole gain representation.
+        </para>
+
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+H=syslin("d",[45.76+6*%z+2*%z^2;0.64*%z],[23.28+3.1*%z+%z^2;23.28+3.1*%z+%z^2])
+[z,p,k]=tf2zp(H)
+ ]]></programlisting>
+    </refsection>
+
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="ss2zp">ss2zp</link>
+            </member>
+            <member>
+                <link linkend="zp2tf">zp2tf</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>Function added.</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
+</refentry>
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/zp2ss.xml b/scilab/modules/cacsd/help/en_US/linear_system_representation/zp2ss.xml
new file mode 100644 (file)
index 0000000..9451121
--- /dev/null
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Serge Steer - INRIA
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+  * For more information, see the COPYING file which you should have received
+ * 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="zp2ss">
+    <refnamediv>
+        <refname>zp2ss</refname>
+        <refpurpose>Zero pole gain to  state space</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>S=zp2ss(z,p,k [,dt])</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+
+            <varlistentry>
+                <term>z</term>
+                <listitem>
+                    <para>
+                        a real or complex matrix, the ith column
+                        contains the transmission zeros relative to
+                        the ith output. If some zeros are complex,
+                        they must appear in complex conjugate pairs.
+                    </para>
+                    <para>
+                        If the number of poles relative to the ith
+                        output is less than the max number of poles for
+                        each output, the ith column must be padded with
+                        %inf values.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>p</term>
+                <listitem>
+                    <para>
+                        a real or complex vector, the poles of the
+                        system. If some poles are complex, they must
+                        appear in complex conjugate pairs.
+                    </para>
+                    <para>
+                        If the number of poles relative to the ith
+                        output is less than the max number of poles for
+                        each output, the ith column must be padded with
+                        %inf values.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>k</term>
+                <listitem>
+                    <para>
+                        a real scalar or a real vector, the ith
+                        element contains the gain relative to the ith
+                        output.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>dom</term>
+                <listitem>
+                    <para>
+                        a character string with possible values "c" or "d", [] or a real positive scalar, the system time domain (see <link linkend="syslin">syslin</link>).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>S</term>
+                <listitem>
+                    <para>
+                        a single input linear system in state space
+                        representation.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            Converts a  zero pole gain representation to  SIMO state space
+        </para>
+
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+Z=[2;1];P=[-5-%i;-5+%i;-3-%i;-3+%i];K=1;
+S=zp2ss(Z,P,K,"c")
+ssprint(S)
+trzeros(S)
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="ss2zp">ss2zp</link>
+            </member>
+            <member>
+                <link linkend="trzeros">trzeros</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>Function added.</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
+</refentry>
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/zp2tf.xml b/scilab/modules/cacsd/help/en_US/linear_system_representation/zp2tf.xml
new file mode 100644 (file)
index 0000000..4b88c95
--- /dev/null
@@ -0,0 +1,127 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Serge Steer - INRIA
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * For more information, see the COPYING file which you should have received
+ * 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="zp2tf">
+    <refnamediv>
+        <refname>zp2tf</refname>
+        <refpurpose>Zero pole gain to transfer function</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>S=zp2tf(z,p,k [,dt])</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+
+            <varlistentry>
+                <term>z</term>
+                <listitem>
+                    <para>
+                        a real or complex matrix, the ith column
+                        contains the transmission zeros relative to
+                        the ith output. If some zeros are complex,
+                        they must appear in complex conjugate pairs.
+
+                    </para>
+                    <para>
+                        If the number of zeros relative to the ith
+                        output is less than the max number of zeros for
+                        each output, the ith column must be padded with
+                        %inf values.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>p</term>
+                <listitem>
+                    <para>
+                        a real or complex vector, the poles of the
+                        system. If some poles are complex, they must
+                        appear in complex conjugate pairs.
+                    </para>
+                    <para>
+                        If the number of poles relative to the ith
+                        output is less than the max number of poles for
+                        each output, the ith column must be padded with
+                        %inf values.
+                    </para>
+
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>k</term>
+                <listitem>
+                    <para>
+                        a real scalar or a real vector, the ith
+                        element contains the gain relative to the ith
+                        output.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>dom</term>
+                <listitem>
+                    <para>
+                        a character string with possible values "c" or
+                        "d", [] or a real positive scalar, the system
+                        time domain (see <link
+                        linkend="syslin">syslin</link>).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>S</term>
+                <listitem>
+                    <para>
+                        a single input transfer function.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            Converts a  zero pole gain representation to rational transfer function
+        </para>
+
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+Z=[2;1];P=[0;-3-%i;-3+%i];K=2.5;
+S=zp2tf(Z,P,K,"c")
+roots(S.num)
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="zp2ss">zp2ss</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>Function added.</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
+</refentry>
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk.xml b/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk.xml
new file mode 100644 (file)
index 0000000..18e7468
--- /dev/null
@@ -0,0 +1,237 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Serge Steer - INRIA
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * For more information, see the COPYING file which you should have received
+ * 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="zpk">
+    <refnamediv>
+        <refname>zpk</refname>
+        <refpurpose>Zero pole gain system representation</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>S=zpk(Z,P,K,dt)</synopsis>
+        <synopsis> S=zpk(z,p,k,dt))</synopsis>
+        <synopsis>S=zpk(sys))</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>Z</term>
+                <listitem>
+                    <para>
+                        a m by n cell of real or complex vectors, Z{i,j} is
+                        the transmission zeros of the transfer from the the
+                        jth intput to the ith output.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>P</term>
+                <listitem>
+                    <para>
+                        a m by n cell of real or complex vectors, P{i,j} is
+                        the poles of the transfer from the the jth intput to
+                        the ith output.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>K</term>
+                <listitem>
+                    <para>
+                        a m by n matrix of real numbers, K(i,j) is the gain of the
+                        transfer from the the jth intput to the ith output.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>z</term>
+                <listitem>
+                    <para>
+                        a real or complex vector, the transmission zeros of
+                        the siso transfer function.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>p</term>
+                <listitem>
+                    <para>
+                        a real or complex vector, the poles of the siso
+                        transfer function.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>k</term>
+                <listitem>
+                    <para>
+                        a real scalar, the gain of the siso transfer function.
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>dt</term>
+                <listitem>
+                    <para>
+                        a character string with possible values "c" or "d", []
+                        or a real positive scalar, the system time domain (see
+                        <link linkend="syslin">syslin</link>).
+                    </para>
+                </listitem>
+            </varlistentry>
+
+            <varlistentry>
+                <term>sys</term>
+                <listitem>
+                    <para>
+                        A linear dynamical system in transfer function or
+                        state spece representation (see <link linkend="syslin">syslin</link>).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>S</term>
+                <listitem>
+                    <para>
+                        a mlist with the fields Z , P, K and  dt.
+                    </para>
+                    <variablelist>
+                        <varlistentry>
+                            <term>Z</term>
+                            <listitem>
+                                <para>
+                                    a m by n cell array of real or complex vectors,
+                                    S.Z{i,j} contains the zeros  of the transfer from the
+                                    the jth intput to the ith output
+                                </para>
+                            </listitem>
+                        </varlistentry>
+                        <varlistentry>
+                            <term>P</term>
+                            <listitem>
+                                <para>
+                                    a m by n cell array of real or complex vectors,
+                                    S.P{i,j} contains the poles of the transfer from the
+                                    the jth intput to the ith output
+                                </para>
+                            </listitem>
+                        </varlistentry>
+                        <varlistentry>
+                            <term>K</term>
+                            <listitem>
+                                <para>
+                                    a m by n matrix of real numbers, S.K(i,j) is
+                                    the gain of the transfer from the the jth
+                                    intput to the ith output.  output.
+                                </para>
+                            </listitem>
+                        </varlistentry>
+                        <varlistentry>
+                            <term>dt</term>
+                            <listitem>
+                                <para>
+                                    a positive scalar or "c" or "d" the time domain
+                                </para>
+                            </listitem>
+                        </varlistentry>
+
+                    </variablelist>
+
+                </listitem>
+            </varlistentry>
+
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            <literal>S=zpk(Z,P,K,dt)</literal> forms the multi-input,
+            multi-output zero pole gain system representation given the
+            cell arrays of the transmission zeros,poles and gain.
+        </para>
+        <para>
+            <literal>S=zpk(z,p,k,dt)</literal> forms the single-input,
+            single output zero pole gain system representation given the
+            vecteors of the transmission zeros and poles and the scalar
+            gain.
+        </para>
+        <para>
+            <literal>S=zpk(sys)</literal> converts the system
+            representation into a zero-pole-gain representation.
+        </para>
+        <para>
+            The poles and zeros of each transfer function are sorted in decreasing order of the real part.
+        </para>
+        <para>
+            Most functions and operations than can act on state-space or
+            rational transfer function representations can be also
+            applied to zero-pole-gain representations.
+        </para>
+
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+//Form system from zeros, poles and gain
+//SISO case
+z11=[1 -0.5];p11=[-3+2*%i -3-2*%i  -2];k11=1;
+S11=zpk(z11,p11,k11,"c")
+
+//MIMO case
+z21=0.3;p21=[-3+2*%i -3-2*%i];k21=1.5;
+S21=zpk(z21,p21,k21,"c")
+S=zpk({z11 [];z21 1},{p11,0;p21 -3},[k11 1;k21 1],"c")
+
+//system representation conversion
+h=syslin("c",5*(%s^2+2*%s+1)/(%s^2-4))
+sh=zpk(h)
+
+//operations with zpk representations
+S(1,:)
+
+S'
+
+S(1,1)=sh
+
+sh*S11
+
+sh./S11
+ ]]></programlisting>
+    </refsection>
+
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="tf2zp">tf2zp</link>
+            </member>
+            <member>
+                <link linkend="zpk2tf">zpk2tf</link>
+            </member>
+            <member>
+                <link linkend="zpk2ss">zpk2ss</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>Function added.</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+</refentry>
+
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2ss.xml b/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2ss.xml
new file mode 100644 (file)
index 0000000..a492e89
--- /dev/null
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Serge Steer - INRIA
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * For more information, see the COPYING file which you should have received
+ * 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="zpk2ss">
+    <refnamediv>
+        <refname>zpk2ss</refname>
+        <refpurpose>Zero pole gain to state space</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>S=zpk2ss(sys)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+
+            <varlistentry>
+                <term>sys</term>
+                <listitem>
+                    <para>
+                        A linear dynamical system in zero-pole-gain
+                        representation (see <link
+                        linkend="zpk">zpk</link>).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>S</term>
+                <listitem>
+                    <para>
+                        The state space representation of sys.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+
+
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            Converts a zero pole gain representation to state space.
+        </para>
+
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+sys=zpk([2;1],0;-3-%i;-3+%i],2.5,"c")
+S=zpk2ss(sys)
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="zp2ss">zp2ss</link>
+            </member>
+            <member>
+                <link linkend="zpk2tf">zpk2tf</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>Function added.</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
+</refentry>
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2tf.sci b/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2tf.sci
new file mode 100644 (file)
index 0000000..aba8eca
--- /dev/null
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2016 - Serge Steer - INRIA
+*
+* This file is hereby licensed under the terms of the GNU GPL v2.0,
+* pursuant to article 5.3.4 of the CeCILL v.2.1.
+* For more information, see the COPYING file which you should have received
+* 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="zpk2tf.sci">
+<refnamediv>
+<refname>zpk2tf</refname>
+<refpurpose>Zero pole gain to transfer function</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+    <title>Syntax</title>
+    <synopsis>S=zpk2tf(sys)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+    <title>Arguments</title>
+    <variablelist>
+
+    <varlistentry>
+    <term>z</term>
+    <listitem>
+    <para>
+    a real or complex matrix, the ith column
+    contains the transmission zeros relative to
+    the ith output. If some zeros are complex,
+    they must appear in complex conjugate pairs.
+    </para>
+    </listitem>
+    </varlistentry>
+    <varlistentry>
+    <term>p</term>
+    <listitem>
+    <para>
+    a real or complex vector, the poles of the
+    system. If some poles are complex, they must
+    appear in complex conjugate pairs.
+    </para>
+    </listitem>
+    </varlistentry>
+    <varlistentry>
+    <term>k</term>
+    <listitem>
+    <para>
+    a real scalar or a real vector, the ith
+    element contains the gain relative to the ith
+    output.
+    </para>
+    </listitem>
+    </varlistentry>
+    <varlistentry>
+    <term>dom</term>
+    <listitem>
+    <para>
+    a character string with possible values "c" or
+    "d", [] or a real positive scalar, the system
+    time domain (see <link
+    linkend="syslin">syslin</link>).
+    </para>
+    </listitem>
+    </varlistentry>
+    <varlistentry>
+    <term>S</term>
+    <listitem>
+    <para>
+    a single input transfer function.
+        </para>
+        </listitem>
+        </varlistentry>
+
+        </variablelist>
+        </refsection>
+        <refsection>
+        <title>Description</title>
+        <para>
+        Converts a  zero pole gain representation to  SIMO state space
+        </para>
+
+        </refsection>
+        <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+        Z=[2;1];P=[0;-3-%i;-3+%i];K=2.5;
+        S=zpk2tf.sci(Z,P,K,"c")
+        roots(S.num)
+        ]]></programlisting>
+        </refsection>
+        <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+        <member>
+        <link linkend="zp2ss">zp2ss</link>
+        </member>
+        </simplelist>
+        </refsection>
+        <refsection role="history">
+        <title>History</title>
+        <revhistory>
+        <revision>
+        <revnumber>6.0</revnumber>
+        <revdescription>
+        <para>Function added.</para>
+        </revdescription>
+        </revision>
+        </revhistory>
+        </refsection>
+
+        </refentry>
diff --git a/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2tf.xml b/scilab/modules/cacsd/help/en_US/linear_system_representation/zpk2tf.xml
new file mode 100644 (file)
index 0000000..335098d
--- /dev/null
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2016 - Serge Steer - INRIA
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * For more information, see the COPYING file which you should have received
+ * 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="zpk2tf">
+    <refnamediv>
+        <refname>zpk2tf</refname>
+        <refpurpose>Zero pole gain to transfer function</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Syntax</title>
+        <synopsis>S=zpk2tf(sys)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+
+            <varlistentry>
+                <term>sys</term>
+                <listitem>
+                    <para>
+                        A linear dynamical system in zero-pole-gain
+                        representation (see <link
+                        linkend="zpk">zpk</link>).
+                    </para>
+                </listitem>
+            </varlistentry>
+            <varlistentry>
+                <term>S</term>
+                <listitem>
+                    <para>
+                        The rational transfer function representation of sys.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+
+
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            Converts a  zero pole gain representation to  rational transfer function
+        </para>
+
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <programlisting role="example"><![CDATA[
+sys=zpk([2;1],0;-3-%i;-3+%i],2.5,"c")
+S=zpk2tf(sys)
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="zp2tf">zp2tf</link>
+            </member>
+            <member>
+                <link linkend="zpk2ss">zpk2ss</link>
+            </member>
+        </simplelist>
+    </refsection>
+    <refsection role="history">
+        <title>History</title>
+        <revhistory>
+            <revision>
+                <revnumber>6.0</revnumber>
+                <revdescription>
+                    <para>Function added.</para>
+                </revdescription>
+            </revision>
+        </revhistory>
+    </refsection>
+
+</refentry>
index 4b09b96..88781c9 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 1998-2010 - INRIA - Serge Steer
+// Copyright (C) 1998-2016 - INRIA - Serge Steer
 // Copyright (C) 2010 - DIGITEO - Yann COLLETTE
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
@@ -55,7 +55,7 @@ function black(varargin)
     end
     fname="black";//for error messages
     fmax=[]
-    if or(typeof(varargin(1))==["state-space" "rational"]) then
+    if or(typeof(varargin(1))==["state-space" "rational", "zpk"]) then
         //sys,fmin,fmax [,pas] or sys,frq
         refdim=1 //for error message
         if rhs==1 then
@@ -99,10 +99,15 @@ function black(varargin)
                 fname,1,3))
             end
         else
+
             error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
         end
     else
-        error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        ierr=execstr("%"+overloadname(varargin(1))+"_black(varargin(:))","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        end
+        return
     end;
 
     if size(frq,1)==1 then
index e1d4fb3..74589c3 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C)  1985-2010 - INRIA - Serge Steer
+// Copyright (C) 1985 - 2016 - INRIA - Serge Steer
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -44,8 +44,8 @@ function [] = bode(varargin)
     fname = "bode"; // For error messages
     fmax = [];
     discr = %f; // For Shannon limit
-    if or(typeof(varargin(1)) == ["state-space" "rational"]) then
-// sys, fmin, fmax [,pas] or sys, frq
+    if or(typeof(varargin(1)) == ["state-space" "rational" "zpk"]) then
+        // sys, fmin, fmax [,pas] or sys, frq
         refdim = 1; // for error message
         discr = varargin(1).dt<>"c";
         if rhs == 1 then // sys
@@ -53,7 +53,7 @@ function [] = bode(varargin)
         elseif rhs == 2 then // sys, frq
             if size(varargin(2), 2) < 2 then
                 error(msprintf(_("%s: Wrong size for input argument #%d: A row vector with length>%d expected.\n"), ..
-                               fname, 2, 1))
+                fname, 2, 1))
             end
             [frq, repf] = repfreq(varargin(1:rhs));
         elseif or(rhs == (3:4)) then // sys, fmin, fmax [,pas]
@@ -64,35 +64,39 @@ function [] = bode(varargin)
         [phi, d] = phasemag(repf);
         if rhs >= 3 then fmax = varargin(3); end
     elseif type(varargin(1)) == 1 then
-// frq, db, phi [,comments] or frq, repf [,comments]
+        // frq, db, phi [,comments] or frq, repf [,comments]
         refdim = 2;
         select rhs
-            case 2 then // frq,repf
-                frq = varargin(1);
-                if size(frq, 2) < 2 then
-                    error(msprintf(_("%s: Wrong size for input argument #%d: A row vector with length>%d expected.\n"), ..
-                                   fname, 1, 1))
-                end
-                if size(frq, 2) <> size(varargin(2), 2) then
-                    error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"), ..
-                                   fname, 1, 2))
-                end
-                [phi, d] = phasemag(varargin(2));
-            case 3 then  // frq, db, phi
-                [frq, d, phi] = varargin(1:rhs);
-                if size(frq, 2) <> size(d, 2) then
-                    error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"), ..
-                                   fname, 1, 2))
-                end
-                if size(frq, 2) <> size(phi, 2) then
-                    error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"), ..
-                                   fname, 1, 3))
-                end
+        case 2 then // frq,repf
+            frq = varargin(1);
+            if size(frq, 2) < 2 then
+                error(msprintf(_("%s: Wrong size for input argument #%d: A row vector with length>%d expected.\n"), ..
+                fname, 1, 1))
+            end
+            if size(frq, 2) <> size(varargin(2), 2) then
+                error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"), ..
+                fname, 1, 2))
+            end
+            [phi, d] = phasemag(varargin(2));
+        case 3 then  // frq, db, phi
+            [frq, d, phi] = varargin(1:rhs);
+            if size(frq, 2) <> size(d, 2) then
+                error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"), ..
+                fname, 1, 2))
+            end
+            if size(frq, 2) <> size(phi, 2) then
+                error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions expected.\n"), ..
+                fname, 1, 3))
+            end
         else
             error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"), fname, 2, 4))
         end
     else
-        error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        ierr=execstr("%"+overloadname(varargin(1))+"_bode(varargin(:))","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        end
+        return
     end
     frq = frq';
     d = d';
@@ -104,7 +108,7 @@ function [] = bode(varargin)
     else
         if size(comments, "*") <> mn then
             error(mprintf(_("%s: Incompatible input arguments #%d and #%d: Same number of elements expected.\n"), ...
-                          fname, refdim, rhs+1))
+            fname, refdim, rhs+1))
         end
         hx = 0.43;
     end
@@ -118,7 +122,7 @@ function [] = bode(varargin)
     wrect = axes.axes_bounds;
 
 
-// Magnitude
+    // Magnitude
     axes.axes_bounds = [wrect(1)+0, wrect(2)+0, wrect(3)*1.0, wrect(4)*hx*0.95];
     axes.data_bounds = [min(frq), min(d); max(frq), max(d)];
     axes.log_flags = "lnn";
@@ -130,7 +134,7 @@ function [] = bode(varargin)
     else
         xpolys(frq, d, 1:mn);
     end
-// Set datatips info
+    // Set datatips info
     e = gce();
 
     for i=1:size(e.children, "*")
@@ -144,7 +148,7 @@ function [] = bode(varargin)
     end
     xtitle("", _("Frequency (Hz)"), _("Magnitude (dB)"));
 
-// Phase
+    // Phase
     axes = newaxes();
     axes.axes_bounds = [wrect(1)+0, wrect(2)+wrect(4)*hx, wrect(3)*1.0, wrect(4)*hx*0.95];
     axes.data_bounds = [min(frq), min(phi); max(frq), max(phi)];
@@ -158,7 +162,7 @@ function [] = bode(varargin)
         xpolys(frq, phi, 1:mn);
     end
     ephi = gce();
-// Set datatips info
+    // Set datatips info
     for i=1:size(ephi.children, "*")
         ephi.children(i).display_function = "formatBodePhaseTip";
     end
@@ -169,19 +173,19 @@ function [] = bode(varargin)
         e.foreground = 5;
     end
     xtitle("", _("Frequency (Hz)"), _("Phase (degree)"));
-// Create legend
+    // Create legend
     if comments <> [] then
         c = captions(ephi.children, comments, "lower_caption");
         c.background = get(gcf(), "background");
     end
     fig.immediate_drawing = immediate_drawing;
-// Return to the previous scale
+    // Return to the previous scale
     set("current_axes", sciCurAxes);
 
     if rad == %t then
-// This function modifies the Bode diagrams for a rad/s display instead of Hz.
-// h is a hanlde of a figure containing Bode diagrams.
-// Ref: http://forge.scilab.org/index.php/p/cpge/source/tree/HEAD/macros/bode_Hz2rad_2.sci
+        // This function modifies the Bode diagrams for a rad/s display instead of Hz.
+        // h is a hanlde of a figure containing Bode diagrams.
+        // Ref: http://forge.scilab.org/index.php/p/cpge/source/tree/HEAD/macros/bode_Hz2rad_2.sci
         labels = [_("Phase (degree)"); _("Magnitude (dB)")];
         pos_h = [9, 5];
         for k=1:2
index c83975c..f640520 100644 (file)
@@ -27,46 +27,53 @@ function [] = bode_asymp(sl, w_min, w_max)
 
     rhs = argn(2);
 
-    if and(typeof(sl) <> ["state-space" "rational"]) then
-        msg = _("Wrong type for argument #%d: Rational or State-space matrix expected.\n");
-        error(msprintf(msg, 1))
-        return;
+    if and(typeof(sl) <> ["state-space" "rational" "zpk"]) then
+        args=["sl", "w_min", "w_max"]
+        ierr=execstr("%"+overloadname(sl)+"_bode_asymp("+strcat(args(1:rhs),",")+")","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),"bode_asymp",1))
+        end
+        return
     end
 
     typeSL = typeof(sl);
+    domain=sl.dt
+    var = "s";
+    if type(domain) == 1 then
+        var = "z";
+    elseif domain == "c" then
+        var = "s";
+    elseif domain == "d" then
+        var = "z";
+    end
+    if domain == [] then
+        var = "s";
+    end
+    s = poly(0, var);
+
 
     for elem=1:size(sl, "r") // Individually draw each asymptote of "sl" elements (row vector).
         if typeSL == "rational" then
             h = sl(elem, 1);
-        else
+            root_num = roots(h.num);
+            root_den = roots(h.den);
+        elseif typeSL == "state-space" then
             h = clean(ss2tf(sl(elem, 1)), 1e-8);
-            // Also removing all the coefficients smaller than < 1e-8
+            root_num=roots(h.num);
+            root_den=roots(h.den);
+        elseif typeSL == "zpk" then
+            h=sl(elem,1)
+            root_num=h.Z{1}
+            root_den=h.P{1}
+            h=zpk2tf(h)
         end
 
-        root_num = roots(h.num);
-        root_den = roots(h.den);
-
         if (find(root_num==0))
             disp("Problem class of system is negative")
         end
         rac_nul = find(root_den==0);
         alpha = length(rac_nul);
-        var = "s";
-        domain = h.dt;
-        if type(domain) == 1 then
-            var = "z";
-        elseif domain == "c" then
-            var = "s";
-        elseif domain == "d" then
-            var = "z";
-        end
-        if domain == [] then
-            var = "s";
-            if type(h.D) == 2 then
-                var = varn(h.D);
-            end
-        end
-        s = poly(0, var);
+
         msg = _("%s: Wrong value for input argument #%d: Evaluation failed.\n")
         try K = horner(h*s^alpha, 0); catch error(msprintf(msg, "bode_asymp")); end
 
index d309919..8d83a9d 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA -
+// Copyright (C) 1985 - 2016 - INRIA - Serge Steer
 //
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
@@ -22,11 +22,20 @@ function [frq, bnds, splitf] = calfrq(h, fmin, fmax)
 
     // Check inputs
     // ------------
-    if and(typeof(h) <> ["state-space" "rational"])
-        error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"), "calfrq", 1))
+    if and(typeof(h) <> ["state-space" "rational" "zpk"]) then
+        args=["h", "fmin", "fmax"]
+        ierr=execstr("%"+overloadname(h)+"_calfrq("+strcat(args(1:rhs),",")+")","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),"calfrq",1))
+        end
+        return
     end
+
+
     if typeof(h) == "state-space" then
         h = ss2tf(h)
+    elseif typeof(h) == "zpk" then
+        h=zpk2tf(h)
     end
 
     [m, n] = size(h.num)
index dce3da5..ed0f34b 100644 (file)
@@ -1,5 +1,7 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ???? - 2016 - Serge Steer - INRIA 
+// Copyright (C) ???? - 2016 - INRIA - Serge Steer
+//
+// Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
 // pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -7,8 +9,6 @@
 // and continues to be available under such terms.
 // For more information, see the COPYING file which you should have received
 // along with this program.
-
-
 function [y,x]=csim(u,dt,sl,x0,tol)
     //Syntax:
     //  [y [,x]]=csim(u,dt,sl,[x0])
@@ -45,10 +45,19 @@ function [y,x]=csim(u,dt,sl,x0,tol)
     //
     if rhs<3 then error(39),end
     sltyp=typeof(sl)
-    if and(sltyp<>["state-space" "rational"]) then
-        error(msprintf(_("%s: Wrong type for input argument #%d: %s data structure expected.\n"),"csim",3,"syslin"))
+    if and(sltyp<>["state-space" "rational" "zpk"]) then
+        args=["u","dt","sl","x0","tol"];
+        ierr=execstr("[y,x]=%"+overloadname(sl)+"_csim("+strcat(args(1:rhs),",")+")","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"csim",3))
+        end
+        return
+    end
+    if sltyp=="rational" then
+        sl=tf2ss(sl)
+    elseif sltyp=="zpk" then
+        sl=zpk2ss(sl),
     end
-    if sltyp=="rational" then sl=tf2ss(sl),end
     if sl.dt<>"c" then
         warning(msprintf(gettext("%s: Input argument #%d is assumed continuous time.\n"),"csim",1));
     end
@@ -57,6 +66,7 @@ function [y,x]=csim(u,dt,sl,x0,tol)
     if degree(d)>0 then
         error(msprintf(gettext("%s: Wrong type for input argument #%d: A proper system expected\n"),"csim",1));
     end
+    //[ma,mb]=size(b) replaced by  ma=size(a,1);mb=size(d,2);in case of no-state system
     ma=size(a,1);
     mb=size(d,2);
     //
@@ -66,7 +76,7 @@ function [y,x]=csim(u,dt,sl,x0,tol)
     select type(u)
     case 10 then //input given by its type (step or impuls)
         if mb<>1 then
-          error(msprintf(gettext("%s: Wrong type for input argument #%d: A SIMO expected.\n"),"csim",1));
+            error(msprintf(gettext("%s: Wrong type for input argument #%d: A SIMO expected.\n"),"csim",1));
         end;
         if part(u,1)=="i" then
             //impulse response
index ef3a40e..b913e88 100644 (file)
@@ -1,3 +1,10 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
 function [wn,z,p] = damp(R,dt1)
     //Natural frequency and damping factor for continuous systems.
     //   [Wn,Z,P] = damp(R) returns vectors Wn and Z containing the
@@ -47,6 +54,18 @@ function [wn,z,p] = damp(R,dt1)
             dt=1
         end
         p=roots(lcm(R.den))
+    case "zpk" then
+        dt=R.dt
+        if dt=="c" then
+            dt=0
+        elseif dt=="d" then
+            dt=1
+        end
+        [m,n]=size(R)
+        [p,P]=findCommonValues(R.P)
+        for i=1:size(P,"*")
+            p=[p;P{i}]
+        end
     case "state-space" then
         dt=R.dt
         if dt=="c" then
@@ -59,8 +78,13 @@ function [wn,z,p] = damp(R,dt1)
         p=R;
         toBeOrdered=%f
     else
-        error(msprintf(_("%s: Wrong type for input argument #%d: Array of floats or Polynomial expected.\n"),..
-        "damp",1))
+        ierr=execstr("[wn,z,p]=%"+overloadname(R)+"_damp(R)","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Array of floats, Polynomial or linear dynamical system expected.\n"),..
+            "damp",1))
+        end
+        return
+
     end
     if dt==[] then
         //R does not furnish time domain
@@ -77,7 +101,6 @@ function [wn,z,p] = damp(R,dt1)
     // Initialize
     wn=zeros(p);
     z=-ones(p);
-    im=ieee();ieee(2);//to allow inf and nan's
     if dt>0 then // Discrete  time case
         ind=find(p<>1)
         s=p(ind);
@@ -88,7 +111,6 @@ function [wn,z,p] = damp(R,dt1)
     end
     wn(ind)=abs(s)
     z(ind)=-real(s)./abs(s)
-    ieee(im)
     if toBeOrdered then
         [wn,k]=gsort(wn,"g","i");
         z=z(k);
index a997d60..709cd6c 100644 (file)
@@ -1,6 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA -
-//
+// Copyright (C) 1996 - 2016 - INRIA - Serge Steer
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
 // For more information, see the COPYING file which you should have received
 // along with this program.
 
-
-function [f,r]=dscr(a,dt,m)
+function [f,r]=dscr(sys,dt,m)
 
     [lhs,rhs]=argn(0);
+    if and(typeof(sys) <> ["state-space" "rational" "zpk"]) then
+        args=["sys","dt","m"]
+        ierr=execstr("%"+overloadname(sys)+"_dscr("+strcat(args(1:rhs),",")+")","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"dscr",1))
+        end
+        return
+    end
+    dom=sys.dt
+    if dom<>"c" then
+        warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"dscr",1))
+    end
     if type(dt)<>1 then
         error(msprintf(gettext("%s: Wrong type for input argument #%d: A real expected.\n"),"dscr",2))
     end
@@ -28,17 +38,18 @@ function [f,r]=dscr(a,dt,m)
         error(msprintf(gettext("%s: Input argument #%d must be strictly positive.\n"),"dscr",2))
     end
 
-    select typeof(a)
-    case "rational" then
-        a=tf2ss(a);
-        [a,b,c,d,x0,dom]=a(2:7);
+    select typeof(sys)
     case "state-space" then
-        [a,b,c,d,x0,dom]=a(2:7)
-    else
-        error(97,1),
-    end;
-    if dom<>"c" then
-        warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"dscr",1))
+        S=sys
+    case "rational" then
+        S=tf2ss(sys);
+    case "zpk" then
+        S=zpk2ss(sys);
+    end
+
+    [a,b,c,d,x0]=S(2:6);
+    if degree(d)>0 then
+        error(msprintf(_("%s: Wrong value for input argument #%d: Proper system expected.\n"),"dscr",1));
     end
     [n1,m1]=size(b),
     s=expm([a,b;0*ones(m1,n1+m1)]*dt),
diff --git a/scilab/modules/cacsd/macros/findCommonValues.sci b/scilab/modules/cacsd/macros/findCommonValues.sci
new file mode 100644 (file)
index 0000000..3d8e9c1
--- /dev/null
@@ -0,0 +1,40 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function [c,v]=findCommonValues(v)
+    if typeof(v)<>"ce" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Cell expected.\n"),...
+        "findCommonValues",1))
+    end
+
+    nv=size(v,"*")
+    v1=v{1}
+    for i=2:size(v,"*")
+        if typeof(v{i})<>typeof(v1) then
+            error(msprintf(_("%s: Wrong type for input argument #%d: cell entries must have the same type\n"),...
+            "findCommonValues",1))
+        end
+    end
+    r=v
+    c=[]
+    d1=[]
+    for k=size(v1,"*"):-1:1
+        L=zeros(1,nv);L(1)=k;
+        for i=2:size(v,"*")
+            l=find(v1(k)==v{i},1)
+            if l==[] then break,end
+            L(i)=l
+        end
+        if L(nv)<>0 then
+            //v1(k) is a common value
+            c=[c;v1(k)]
+            for i=1:size(v,"*")
+                v{i}(L(i))=[]
+            end
+        end
+    end
+endfunction
index eb9a0d4..386bb52 100644 (file)
 // along with this program.
 
 function [y,xf]=flts(u,sl,x0)
-
+    fname="flts";
     [lhs,rhs]=argn(0)
     if type(u)<>1 then error(53,1),end
     if rhs<=1 then error(39),end
     [nu,mu]=size(u)
-
+    if typeof(sl)=="zpk" then sl=zpk2tf(sl);end
     select typeof(sl)
     case "state-space" then
         if rhs==2 then x0=sl.X0,end
@@ -73,6 +73,10 @@ function [y,xf]=flts(u,sl,x0)
         l=size(y,2);
         y=y(:,1:min(mu,l));
     else
-        error(97,2)
+        args=["u","sl","x0"]
+        ierr=execstr("[y,xf]=%"+overloadname(sl)+"_flts("+strcat(args(1:rhs),",")+")","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),fname,2))
+        end
     end;
 endfunction
index 63d13fc..123c0e7 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA -
+// Copyright (C) 2000 - 2016 - INRIA - Serge Steer
 //
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 
 function fr=freson(h)
     [lhs,rhs]=argn(0);
+
+    if argn(2) < 1 then
+        error(msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"),"freson",1));
+    end
+    if and(typeof(h)<>["state-space","rational","zpk"]) then
+        ierr=execstr("[gm,fr]=%"+overloadname(sys)+"_freson(h)","errcatch")
+        if ierr<>0 then
+            error(msprintf(gettext("%s: Wrong type for input argument: Linear dynamical system expected.\n"),"freson",1))
+        end
+        return
+    end
+    if size(h,"*")<>1 then
+        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"freson",1))
+    end
+
+    if typeof(h)=="state-space" then
+        h=ss2tf(h)
+    elseif typeof(h)=="zpk" then
+        h=zpk2tf(h)
+    end
+    dt=h.dt
     [n,d]=h(["num","den"]);
     if type(n)==1 then
         n=poly(n,varn(d),"c");
@@ -19,27 +40,27 @@ function fr=freson(h)
     if coeff(d,0)==0 then
         error(msprintf(_("%s: Wrong value for input argument #%d: infinite gain at zero frequency.\n"),"freson",1))
     end
-    //look for  omega such that derivative of magn. is zero
-    niw=horner(n,%i*poly(0,"w"));
-    diw=horner(d,%i*poly(0,"w"));
-    niw=real(niw*conj(niw));diw=real(diw*conj(diw));
-    modul_d=derivat(niw/diw);w=roots(modul_d.num);
-
-    // get extreme points
-    k=find(imag(w)==0&real(w)>=0);
-    if k==[] then
-        fr=[];
-        g=[];
-        return
-    end
-    w=gsort(real(w(k)),"g","i");
 
-    //find maximums
-    wx=max(w)+0.5;
-    if horner(modul_d,wx)<0 then
-        w=w($:-2:1);
+    //look for  omega such that derivative of magn. is zero
+    if dt=="c" then
+        //find frequencies which zeros the magnitude derivative
+        hh=h*horner(h,-%s)
+        r=roots(derivat(hh).num)
+        k=find(imag(r)>0&abs(real(r))<%eps*abs(r));
+        fr=imag(r(k))/(2*%pi)
     else
-        w=w($-1:-2:1);
+        if dt=="d"|dt==[] then dt=1;end
+        //find frequencies which zeros the magnitude derivative
+        hh=h*horner(h,1/%z)
+        r=roots(derivat(hh).num);
+        k=find(abs(abs(r)-1)<=sqrt(%eps)*abs(r));
+        r=imag(log(r(k)));
+        fr=r(r>0&r<0.999*%pi)/(2*%pi*dt)
     end
-    fr=w/(2*%pi);
+    if fr==[] then return;end
+    //find frequencies that correspond to a magnitude peak
+    k=find(abs(repfreq(h,fr))-abs(repfreq(h,fr*0.999))>0)
+    fr=fr(k)
+    if fr==[] then return;end
+    fr=gsort(fr,"g","i");
 endfunction
index 3bb52ae..9cda690 100644 (file)
@@ -9,24 +9,28 @@
 // along with this program.
 
 function [gm,fr] = g_margin(h)
-// Compute the gain margin of a SISO transfer function
+    // Compute the gain margin of a SISO transfer function
 
-  if argn(2) < 1 then
-    error(msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"),"g_margin",1));
-  end
-  if and(typeof(h)<>["state-space","rational"]) then
-    error(msprintf(gettext("%s: Wrong type for input argument: Linear dynamical system expected.\n"),"g_margin",1))
-  end
-  if size(h,"*")<>1 then
-    error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"g_margin",1))
-  end
-
-  if typeof(h)=="state-space" then
-    h=ss2tf(h)
-  end
+    if argn(2) < 1 then
+        error(msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"),"g_margin",1));
+    end
+    if and(typeof(h)<>["state-space","rational","zpk"]) then
+        ierr=execstr("[gm,fr]=%"+overloadname(h)+"_g_margin(h)","errcatch")
+        if ierr<>0 then
+            error(msprintf(gettext("%s: Wrong type for input argument: Linear dynamical system expected.\n"),"g_margin",1))
+        end
+        return
+    end
+    if size(h,"*")<>1 then
+        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"g_margin",1))
+    end
 
+    if typeof(h)=="state-space" then
+        h=ss2tf(h)
+    elseif typeof(h)=="zpk" then
+        h=zpk2tf(h)
+    end
 
-    ieee_save=ieee();ieee(2);
     //
     epsr=1.e-7;//used for testing if complex numbers are real
     eps1=1.e-7;//used for testing if complex numbers have a modulus near 1
@@ -41,14 +45,14 @@ function [gm,fr] = g_margin(h)
         w=roots(num,"e");
         ws=[];
         if w<>[] then
-          ws=real(w(abs(imag(w))<epsr&real(w)<=0)) //points where phase is -180°
+            ws=real(w(abs(imag(w))<epsr&real(w)<=0)) //points where phase is -180°
         end
         if ws<>[] then
-          //remove nearly singular points
-          ws(abs(horner(num,ws))>=epssing*abs(horner(den,ws)))=[]
+            //remove nearly singular points
+            ws(abs(horner(num,ws))>=epssing*abs(horner(den,ws)))=[]
         end
         if ws==[] then gm=%inf,fr=[],return,end
-        mingain=real(freq(h.num,h.den,%i*ws))
+        mingain=real(freq(clean(h.num),clean(h.den),%i*ws))
     else  //discrete time case
         if h.dt=="d" then dt=1,else dt=h.dt,end
         //get z such as h(z)=h(1/z) and z=e^(%i*w*dt)
@@ -58,20 +62,19 @@ function [gm,fr] = g_margin(h)
         //find the numerator roots
         z=roots(hh.num,"e");
         if z<>[] then
-          z(abs(abs(z)-1)>eps1)=[]// retain only roots with modulus equal to 1
+            z(abs(abs(z)-1)>eps1)=[]// retain only roots with modulus equal to 1
         end
         if z<>[] then
-          //remove nearly singular points
-          z(abs(horner(hh.num,z))>=epssing*abs(horner(hh.den,z)))=[];
+            //remove nearly singular points
+            z(abs(horner(hh.num,z))>=epssing*abs(horner(hh.den,z)))=[];
         end
         ws=[];
         if z<>[] then
-          w=log(z)/(%i*dt)
-          ws=real(w(abs(imag(w))<epsr)) //points where phase is -180°
+            w=log(z)/(%i*dt)
+            ws=real(w(abs(imag(w))<epsr)) //points where phase is -180°
         end
         if ws==[] then gm=%inf,fr=[],return,end
         mingain=real(horner(h,exp(%i*ws*dt)))
-        ieee(ieee_save)
     end
 
     k=find(mingain<0)
@@ -83,5 +86,4 @@ function [gm,fr] = g_margin(h)
     [gm,k]=min(gm);ws=ws(k);//select the minimum
 
     fr=ws/(2*%pi) //transform in Hz
-    ieee(ieee_save)
 endfunction
index 104fc4a..f361433 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2010 - INRIA - Serge Steer
+// Copyright (C) 2010 - 2016 - INRIA - Serge Steer
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -32,7 +32,7 @@ function []=gainplot(varargin)
     fname="gainplot";//for error messages
 
     fmax=[];
-    if or(typeof(varargin(1))==["state-space" "rational"]) then
+    if or(typeof(varargin(1))==["state-space" "rational" "zpk"]) then
         //sys,fmin,fmax [,pas] or sys,frq
         refdim=1 //for error message
         if rhs==1 then
@@ -75,7 +75,11 @@ function []=gainplot(varargin)
             error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
         end
     else
-        error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        ierr=execstr("%"+overloadname(varargin(1))+"_gainplot(varargin(:))","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        end
+        return
     end;
 
     frq=frq';
index 29965c3..c8f65cf 100644 (file)
@@ -1,6 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA - Serge Steer
-//
+// Copyright (C) 1996 - 2016 - INRIA - Serge Steer
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -18,27 +17,35 @@ function [kp,s]=krac2(sys)
     // K'=-(den'*num-den*num')/num^2
     // K'= 0 --> den'*num-den*num'=0
     //  http://www.scribd.com/doc/21374148/An-Introduction-to-Control-Systems
-    select typeof(sys)
-    case "rational" then
-    case "state-space" then
-        sys=ss2tf(sys);
-    else
-        error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"krac2",1))
+    if and(typeof(sys)<>["state-space" "rational" "zpk"]) then
+        ierr=execstr("[kp,s]=%"+overloadname(sys)+"_krac2(sys)","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"krac2",1))
+        end
+        return
     end
+
     if size(sys,"*")<>1 then
         error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"krac2",1))
     end
-    num=sys.num
-    den=sys.den
+
+    if typeof(sys)=="state-space" then
+        sys=ss2tf(sys)
+    elseif typeof(sys)=="zpk" then
+        sys=zpk2tf(sys)
+    end
+    num=sys.num;
+    den=sys.den;
+
     s=roots(derivat(num)*den-derivat(den)*num,"e")
     //collect the real roots only
     i=find(abs(imag(s))<=10*%eps)
     if i==[] then kp=[],s=[];return,end
-    s=s(i)';
+    s=real(s(i))'
     s=s(horner(num,s)<>0);
-
     kp=-real(freq(den,num,real(s)));
     i=find(kp>=0);
     kp=kp(i)
     s=s(i)
 endfunction
+
diff --git a/scilab/modules/cacsd/macros/nearly_multiples.sci b/scilab/modules/cacsd/macros/nearly_multiples.sci
new file mode 100644 (file)
index 0000000..0f9ca09
--- /dev/null
@@ -0,0 +1,66 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// and continues to be available under such terms.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function [u,m]=nearly_multiples(v,tol)
+    //Find nearly multiple values in v  and their multiplicity
+    //v   : complex array, the given values
+    //tol : positive relative tolerance, two values v1 and v2 are considered nearly
+    //      equals if abs(v1-v2)/abs(v1)<tol
+    //u   : the "unique" values. Nearly equal values are replaced by their
+    //      mean
+    //m   : the multiplicity of the "unique" values/ (u(i) is nearly equal to
+    //      m(i) values in v
+    v=v(:);
+    if argn(2)<2 then
+        tol=1e-10
+    end
+    kz=find(abs(v)<=tol);
+    mz=size(kz,"*")
+    v(kz)=[]
+    ir=find((abs(imag(v))<=tol*abs(v)))
+    v(ir)=real(v(ir))
+    v=gsort(v(imag(v)>=0),"g","d")
+    //[s,k]=gsort([real(v) imag(v)],"lr","d"); v=v(k)
+    keq=find(abs(v(2:$)-v(1:$-1))<tol*abs(v(2:$)))
+    if keq<>[] then
+        //There is nearly mutiple values
+        keq=[keq keq($)+2]
+        n=size(keq,"*")
+        u=[];m=[];del=[];
+        //locate clusters of nearly equal values . ith  cluster starts at keq(i)
+        //and stops at keq(j) where j is the first value greater than i such as keq(j+1)>keq(j)+1
+        //or j=size(keq,"*")
+        i=1;
+        while i<n
+            j=i+1;
+            while j<n&keq(j)==keq(j-1)+1 do j=j+1;end
+            sel=keq(i):keq(j-1)+1;
+            i=j;
+            u=[u;mean(v(sel))];
+            m=[m;size(sel,"*")];
+            del=[del sel];
+        end
+        v(del)=[];
+        u=[u;v];
+        m=[m;ones(v)];
+    else
+        u=v
+        m=ones(v)
+    end
+
+    //add the complex conjugate
+    kc=find(imag(u)>0)
+    kr=find(imag(u)==0)
+    u=[u(kr);matrix([u(kc).';u(kc)'],-1,1)]
+    m=[m(kr);matrix([m(kc)';m(kc)'],-1,1)]
+
+    if mz<>0 then
+        u=[0;u]
+        m=[mz;m]
+    end
+endfunction
index c5fd221..90369de 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 1984-2011 - INRIA - Serge STEER
+// Copyright (C) 1985 - 2016 - INRIA - Serge Steer
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -42,7 +42,7 @@ function nyquist(varargin)
     end
     fname="nyquist";//for error messages
     fmax=[];
-    if or(typeof(varargin(1))==["state-space" "rational"]) then
+    if or(typeof(varargin(1))==["state-space" "rational" "zpk"]) then
         //sys,fmin,fmax [,pas] or sys,frq
         refdim=1; //for error message
         sltyp=varargin(1).dt;
@@ -89,7 +89,11 @@ function nyquist(varargin)
             error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
         end
     else
-        error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1));
+        ierr=execstr("%"+overloadname(varargin(1))+"_nyquist(varargin(:))","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        end
+        return
     end;
     if size(frq,1)==1 then
         ilf=0;
index 63f9e7a..c1d466c 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2011 - INRIA - Serge Steer
+// Copyright (C) 2011 - 2016 - INRIA - Serge Steer
 //
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
@@ -21,15 +21,22 @@ function [fmin,fmax]=nyquistfrequencybounds(H,bounds)
     if or(bounds(2,:)<bounds(1,:)) then
         error(msprintf(_("%s: Wrong value for input argument #%d: second row must be greater than first one.\n"),fname,2))
     end
-    if and(typeof(H)<>["state-space" "rational"]) then
-        error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),fname,1))
+    if and(typeof(H)<>["state-space" "rational" "zpk"]) then
+        ierr=execstr("[fmin,fmax]=%"+overloadname(H)+"_nyquistfrequencybounds(H,bounds)","errcatch")
+        if ierr<>0 then
+            error(msprintf(gettext("%s: Wrong type for input argument: Linear dynamical system expected.\n"),"nyquistfrequencybounds",1))
+        end
+        return
     end
+
     if size(H,"*")<>1 then
         error(msprintf(_("Wrong type for argument #%d: SISO expected.\n"),fname,1))
     end
 
     if typeof(H)=="state-space" then
         H=ss2tf(H)
+    elseif typeof(H)=="zpk" then
+        H=zpk2tf(H)
     end
 
     dom=H.dt
diff --git a/scilab/modules/cacsd/macros/overloadname.sci b/scilab/modules/cacsd/macros/overloadname.sci
new file mode 100644 (file)
index 0000000..7e7cb31
--- /dev/null
@@ -0,0 +1,19 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function name=overloadname(a)
+    //return the short name associated with input variable a to be used for
+    //function overloading
+    t=type(a)
+    if or(t==(15:17)) then
+        name=typeof(a)
+    else
+        [types,names]=typename()
+        k=find(types==t)
+        name=names(k)
+    end
+endfunction
index ebbaa40..ad1eb39 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2010-2011 - INRIA - Serge Steer
+// Copyright (C) 2010 - 2016 - INRIA - Serge Steer
 //
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 
 function [phm,fr]=p_margin(h)
     //compute the phase margin of a SISO transfer function
-    select typeof(h)
-    case "rational" then
-    case "state-space" then
-        h=ss2tf(h);
-    else
-        error(97,1)
+    if argn(2) < 1 then
+        error(msprintf(_("%s: Wrong number of input argument(s): %d expected.\n"),"g_margin",1));
     end
-    if or(size(h)<>[1 1]) then
-        error(msprintf(_("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"p_margin",1))
+    if and(typeof(h)<>["state-space","rational","zpk"]) then
+        ierr=execstr("[phm,fr]=%"+overloadname(h)+"_p_margin(h)","errcatch")
+        if ierr<>0 then
+            error(msprintf(gettext("%s: Wrong type for input argument: Linear dynamical system expected.\n"),"p_margin",1))
+        end
+        return
+    end
+    if size(h,"*")<>1 then
+        error(msprintf(gettext("%s: Wrong size for input argument #%d: Single input, single output system expected.\n"),"p_margin",1))
     end
+
+    if typeof(h)=="state-space" then
+        h=ss2tf(h)
+    elseif typeof(h)=="zpk" then
+        h=zpk2tf(h)
+    end
+
     eps=1.e-7;// threshold used for testing if complex numbers are real or pure imaginary
 
     if h.dt=="c" then  //continuous time case
index b58ffdf..9b21709 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2011 - INRIA - Serge Steer
+// Copyright (C) 2011 - 2016 - INRIA - Serge Steer
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -20,7 +20,7 @@ function []=phaseplot(varargin)
     fname="phaseplot";//for error messages
 
     fmax=[];
-    if or(typeof(varargin(1))==["state-space" "rational"]) then
+    if or(typeof(varargin(1))==["state-space" "rational" "zpk"]) then
         //sys,fmin,fmax [,pas] or sys,frq
         refdim=1 //for error message
         if rhs==1 then
@@ -63,7 +63,11 @@ function []=phaseplot(varargin)
             error(msprintf(_("%s: Wrong number of input arguments: %d to %d expected.\n"),fname,2,4))
         end
     else
-        error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        ierr=execstr("%"+overloadname(varargin(1))+"_phaseplot(varargin(:))","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system or row vector of floats expected.\n"),fname,1))
+        end
+        return
     end;
 
     frq=frq';
index ed6a6fb..e10f882 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA
+// Copyright (C) 2000 - 2016 - INRIA - Serge Steer
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
 // This file is hereby licensed under the terms of the GNU GPL v2.0,
@@ -28,30 +28,24 @@ function plzr(a,b,c,d)
         if rhs<>1 then
             error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"plzr",1)),
         end
-        a=tf2ss(a),
         dt=a.dt;
-        [a,b,c,d]=a(2:5)
-        if type(d)<>1 then
-            error(msprintf(gettext("%s: Wrong value of input argument #%d: Proper system expected.\n"),"plzr",1));
-        end
+        [a,b,c,d]=abcd(tf2ss(a)),
+
     case "state-space" then
         if rhs<>1 then
             error(msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"plzr",1)),
         end
-        dt=a(7);
-        [a,b,c,d]=a(2:5)
-        if type(d)<>1 then
-            error(msprintf(gettext("%s: Wrong value of input argument #%d: Proper system expected.\n"),"plzr",1));
-        end
+        dt=a.dt
+        [a,b,c,d]=abcd(a)
     case "constant" then
         if rhs<>4 then
             error(msprintf(gettext("%s: Wrong number of input argument: %d expected.\n"),"plzr",4)),
         end
-        if type(d)<>1 then
-            error(msprintf(gettext("%s: Wrong type for input argument #%d: Array of floating point numbers expected.\n"),..
-            "plzr",4));
-        end
+
         dt=[];
+    case "zpk" then
+        dt=a.dt;
+        [a,b,c,d]=abcd(zpk2ss(a));
     else
         if rhs==1 then
             error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"plzr",1))
@@ -59,6 +53,7 @@ function plzr(a,b,c,d)
             error(msprintf(gettext("%s: Wrong type of input argument #%d: Array of floating point numbers expected.\n"),"plzr",1))
         end
     end
+
     if type(d)<>1 then
         error(msprintf(gettext("%s: Wrong type for input argument #%d: Array of floating point numbers expected.\n"),..
         "plzr",4));
diff --git a/scilab/modules/cacsd/macros/reduceToCommonDenominator.sci b/scilab/modules/cacsd/macros/reduceToCommonDenominator.sci
new file mode 100644 (file)
index 0000000..a4fd5ff
--- /dev/null
@@ -0,0 +1,49 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function [Zc,Pc]=reduceToCommonDenominator(Z,P,K)
+    if typeof(Z)<>"ce" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Cell expected.\n"),...
+        "reduceToCommonDenominator",1))
+    end
+    if typeof(P)<>"ce" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Cell expected.\n"),...
+        "reduceToCommonDenominator",2))
+    end
+    if type(K)<>1|~isreal(K) then
+        error(msprintf(_("%s: Wrong type for input argument #%d: real matix expected.\n"),...
+        "reduceToCommonDenominator",3))
+    end
+
+    Pc=P{1};
+    mn=size(Z)
+    if or(size(P)<>mn) then
+        error(msprintf(_("%s: Arguments %d and %d must have equal dimensions.\n"),...
+        "reduceToCommonDenominator",1,2))
+    end
+    if or(size(K)<>mn) then
+        error(msprintf(_("%s: Arguments %d and %d must have equal dimensions.\n"),...
+        "reduceToCommonDenominator",1,3))
+    end
+    n=prod(mn)
+    Zc=Z;
+    for k=2:n
+        if K(k)<>0 then
+            if P{k}<>[]then
+                [pc,pk,c]=simplify_zp(Pc,P{k});
+                Pc=[pc;pk;c];
+                for i=1:k-1,Zc{i}=[Zc{i};pk];end
+                Zc{k}=[Zc{k};pc];
+            else
+                Zc{k}=[Zc{k};Pc];
+            end
+        else
+            Zc{k}=[]
+        end
+    end
+endfunction
+
index 7cef7d2..188ef7b 100644 (file)
@@ -1,5 +1,5 @@
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 1984-2011 - INRIA - Serge STEER
+// Copyright (C) 1984 - 2011 - INRIA - Serge STEER
 //
 // Copyright (C) 2012 - 2016 - Scilab Enterprises
 //
@@ -16,9 +16,15 @@ function [frq,rep,splitf]=repfreq(sys,fmin,fmax,pas)
     l10=log(10);
     [lhs,rhs]=argn(0)
     //discretization
-    if and(typeof(sys)<>[ "rational" "state-space" ]) then
-        error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"repfreq",1))
+    if and(typeof(sys)<>[ "rational" "state-space" "zpk"]) then
+        args=["sys","fmin","fmax","pas"];
+        ierr=execstr("[frq,rep,splitf]=%"+overloadname(sys)+"_repfreq("+strcat(args(1:rhs),",")+")","errcatch")
+        if ierr<>0 then
+            error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"repfreq",1))
+        end
+        return
     end
+    if typeof(sys)=="zpk" then sys=zpk2tf(sys);end
     dom=sys.dt
     if dom==[]|dom==0 then error(96,1),end
     if dom=="d" then dom=1;end
@@ -98,13 +104,22 @@ function [frq,rep,splitf]=repfreq(sys,fmin,fmax,pas)
             rep=freq(n,d,exp(2*%pi*%i*dom*frq)),
         end;
     case "lss" then
-        [a,b,c,d,x0]=sys(2:6),
-        [mn,nn]=size(b)
+        [a,b,c,d]=abcd(sys)
+        [mn,nn]=size(d)
         if nn<>1 then error(95,1),end
+
         if dom=="c" then
-            rep=freq(a,b,c,d,2*%pi*%i*frq)
+            if a==[] then
+                rep=(d*2*%pi*%i)*frq
+            else
+                rep=freq(a,b,c,d,2*%pi*%i*frq)
+            end
         else
-            rep=freq(a,b,c,d,exp(2*%pi*%i*dom*frq))
+            if a==[] then
+                rep=d*exp(2*%pi*%i*dom*frq)
+            else
+                rep=freq(a,b,c,d,exp(2*%pi*%i*dom*frq))
+            end
         end;
     else error(97,1),
     end;
diff --git a/scilab/modules/cacsd/macros/rlocus.sci b/scilab/modules/cacsd/macros/rlocus.sci
new file mode 100644 (file)
index 0000000..98f8a2a
--- /dev/null
@@ -0,0 +1,253 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2015 - 2016 - INRIA - Serge STEER
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function [kk,ol_poles,ol_zeros,cl_poles,AsymptotesOrigin,AsymptotesAngles]=rlocus(sys,kmax)
+    //Calling sequence analysis
+    rhs=argn(2)
+
+    kmax_ind=0; //for error messages
+    sltyp=typeof(sys)
+    if and(sltyp<>["state-space" "rational" "zpk"]) then
+        args=["sys","kmax"];
+        ierr=execstr("[kk,ol_poles,ol_zeros,cl_poles,AsymptotesOrigin,AsymptotesAngles]=%"+overloadname(sys)+"_rlocus("+strcat(args(1:rhs),",")+")","errcatch")
+        if ierr<>0 then
+            error(msprintf(_("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"rlocus",1))
+        end
+        return
+    end
+    if or(size(sys)<>1) then
+        error(msprintf(gettext("%s: Wrong value for input argument #%d: Single input, single output system expected.\n"),"rlocus",1));
+    end
+
+    if sltyp=="rational" then
+        den=sys.den;
+        num=sys.num;
+        ol_zeros=roots(num,"e");
+        ol_poles=roots(den,"e");
+    elseif sltyp=="state-space" then
+        [ol_zeros,ol_poles,k]=ss2zp(sys);
+        den=real(poly(ol_poles,"x","r"))
+        num=real(poly(ol_zeros,"x","r"))*k
+    elseif  sltyp=="zpk" then
+        ol_zeros=sys.Z{1};
+        ol_poles=sys.P{1}
+        k=sys.K
+        den=real(poly(ol_poles,"x","r"))
+        num=real(poly(ol_zeros,"x","r"))*k
+    end
+
+
+    if rhs<2 then
+        kmax=0,
+    else
+        if type(kmax)<>1|~isreal(kmax)|kmax<0 then
+            error(msprintf(gettext("%s: Wrong type for input argument #%d: A positive real expected.\n"),"rlocus",2));
+        end
+    end
+
+    inproper=degree(num)>degree(den)
+    if inproper then
+        [num, den]=(den, num);
+        [ol_zeros,ol_poles]=(ol_poles,ol_zeros);
+    end
+
+
+    [AsymptotesOrigin,AsymptotesAngles]=rlocusAsymptotes(ol_zeros,ol_poles)
+    if size(kmax,"*")>1 then // discretization of k given
+        kk=gsort(kmax,"g","i");
+        cl_poles=rlocusClpoles(num,den,kk)
+    else // Computed discretization
+        [cl_poles,kk]=rlocusGainAndClpoles(num,den,ol_zeros,ol_poles,AsymptotesOrigin,AsymptotesAngles,kmax)
+    end  //end of locus computation
+    if inproper then
+        kk(kk==0)=[];
+        kk=1 ./ kk,
+    end
+endfunction
+
+function ord=rlocusOrderRoots(ref,r)
+    //ref : reference roots
+    //r   : roots to be ordered
+    //ord  : orders such as max(abs(r(ord(i))-ref(i))) is minimum
+    n=size(r,"*")
+    not_yet=1:n
+    for k=1:n
+        //find the nearest root in ref
+        [mn,l]=min(abs(r(k)-ref(not_yet)))
+        kmn=not_yet(l);
+        not_yet(l)=[];
+        ord(kmn)=k;
+        if not_yet==[] then break,end
+    end
+endfunction
+
+function ok=rlocusCheckEnd(RootsAtK,OpenLoopZeros,AsymptotesAngles,AsymptotesOrigin,Threshold)
+    // Threshold : relative distance threshold used to decides if current
+    //             roots are sufficiently close to open loops zeros and
+    //             asymptotes
+    // if x0=AsymptotesOrigin(1), y0=AsymptotesOrigin(2) and a=AsymptotesAngles(k)
+    // The kth asymptote equation is given by: -sin(a)*y+cos(a)*x -y0*cos(a)+x0*sin(a)=0
+    ok=%f
+    // Check distance to open loop zeros
+    if OpenLoopZeros<>[] then
+        w=abs([OpenLoopZeros;RootsAtK]);
+        ratio=max(max(w)-min(w))
+        //ratio=abs(OpenLoopZeros);ratio(ratio<1d-10)=1;
+        nz=size(OpenLoopZeros,"*");
+        nr=size(RootsAtK,"*");
+
+        Tz(nz)=%f;
+        Rz(nr)=%f;
+        for kz=1:nz
+            d=abs(OpenLoopZeros(kz)-RootsAtK)./ratio//(kz);
+            lok=find(d< Threshold);
+            if lok==[] then return,end
+            Tz(kz)=%t;
+            Rz(lok)=%t;
+        end
+        if ~and(Tz) then return,end
+    else
+        Rz=%f(ones(RootsAtK));
+        ratio=max(abs(RootsAtK))
+    end
+
+    // Check distance with asymptotes
+    na=size(AsymptotesAngles,"*")
+    if na==0 then ok=%t,return;end
+    Ta(na)=%f;
+
+    //consider only current roots which did not match an open loop zero
+    R=RootsAtK(~Rz) - AsymptotesOrigin
+    //ratio=abs(R);ratio(ratio<1d-10)=1;
+    a=exp(%i*AsymptotesAngles);
+    d=abs(imag(R*a))/ratio;// d(i,j) =distance from roots(i) to the asymptotes(j)
+    //lambda=real(R*conj(a))   //factors along asymptotes direction vectors
+    [i,j]=find(d<Threshold)//&lambda>0)
+    ok=size(unique(j),"*")>=na
+endfunction
+
+function cl_poles=rlocusClpoles(num,den,kk)
+    nk=size(kk,"*")
+    cl_poles=zeros(degree(den),nk);
+    cl_poles(:,1)=roots(den+kk(1)*num,"e");
+    for i=2:nk
+        r=roots(den+kk(i)*num,"e");
+        // look for order that minimize the distance
+        ord=rlocusOrderRoots(cl_poles(:,i-1),r);
+        cl_poles(:,i)=r(ord);
+    end
+endfunction
+
+function [cl_poles,kk]=rlocusGainAndClpoles(num,den,ol_zeros,ol_poles,AsymptotesOrigin,AsymptotesAngles,kmax)
+    smax=0.02;smin=smax/3;//boundaries on relative closed roots distances
+    //for 2 consecutive gain values.
+    nptmax=5000 //nbre maxi de pt de discretisation en k
+
+    //Find  gains  where locus branches intersect
+    klim=gsort(krac2(rlist(num,den,"c")),"g","i");
+    nlim=size(klim,"*");
+    dmax=max(degree(num),degree(den))
+    nrm=max([norm(ol_poles,1),norm(ol_zeros,1)]) //normalization ratio
+
+    ord=1:size(ol_poles,"*");
+    nr=max(size(ol_poles,"*"),size(ol_zeros,"*"))
+    k=0;//initialize current gain (open loop)
+    kk=k; //initialize  gain discretization array
+    cl_poles=ol_poles; //initialize closed loop poles array
+    k_step=0.99; //initialize gain step
+    ilim=1;
+
+    if degree(num)==degree(den) then
+        ksing=abs(coeff(den,degree(den))/coeff(num,degree(num)))
+    else
+        ksing=%inf
+    end
+
+    while %t then
+        k=k+k_step;
+        if (kmax>0&k>kmax) then break;end
+
+        if k>0.95*ksing then
+
+            //jump over the singularity
+            k=1.05*ksing
+            cl_poles(:,$+1)=%nan;
+            cl_poles(:,$+1)=roots(den+k*num,"e")
+            kk=[kk %nan k]
+            k=k+k_step;
+            ksing=%inf
+        end
+        point=%f;
+        r=roots(den+k*num,"e");
+        r=r(ord);
+        mx=max(abs(cl_poles(:,$)))
+        if mx>0 then
+            dist=max(abs(cl_poles(:,$)-r))./mx
+
+            if dist > smax //Try to find a best closed loop poles order
+                ord1=rlocusOrderRoots(cl_poles(:,$),r)
+                r=r(ord1)
+                ord=ord(ord1)
+                // recompute the distance
+                //dist=max(abs(cl_poles(:,$)-r))/nrm
+                dist=max(abs(cl_poles(:,$)-r))./max(abs(cl_poles(:,$)))
+            end
+        else
+            dist=smax
+        end
+        if dist <= smax then //step small enough
+            if dist<smin then //Too small step, ignore point and enlarge step size
+                k=k-k_step
+                k_step=2*k_step;
+                if k_step>1e5 then break;end
+            else //step ok
+                point=%t
+                if nlim>0&(ilim<=nlim&k>=klim(ilim)&klim(ilim)<>0) then
+                    //rlocus intersection detected, add a point exactly at the intersection
+                    k=klim(ilim),
+                    ilim=ilim+1
+                    r=roots(den+k*num,"e");
+                    ord1=rlocusOrderRoots(cl_poles(:,$),r)
+                    r=r(ord1)
+                    ord=ord(ord1)
+                end
+                cl_poles=[cl_poles,r]; //store current closed loop poles
+                kk=[kk,k]  //store current gain
+
+                //check if k is large enough
+                if kmax==0 then
+                    if rlocusCheckEnd(r,ol_zeros,AsymptotesAngles,AsymptotesOrigin,smax) then break,end
+                elseif k>kmax then
+                    break
+                end
+                if size(kk,"*")>nptmax then
+                    warning(msprintf(_("%s: Curve truncated to the first %d discretization points.\n"),"rlocus",nptmax))
+                    break
+                end
+            end
+        else //Too big step, /reduce the step size
+            k=k-k_step,k_step=k_step/2.5
+        end
+
+    end //end of discretization loop
+
+endfunction
+
+function  [AsymptotesOrigin,AsymptotesAngles]=rlocusAsymptotes(ol_zeros,ol_poles)
+    //Find the asymptotes equations
+    //see http://en.wikibooks.org/wiki/Control_Systems/Root_Locus#Root_Locus_Equations
+    na=size(ol_poles,"*")-size(ol_zeros,"*"); //number of asymptotes
+    if  na>0 then
+        AsymptotesOrigin=(sum(ol_poles)-sum(ol_zeros))/na; //real axis with asymptotes intersection point
+        AsymptotesAngles=%pi/na*(2*(0:na-1)+1); //slope of the asymptotes
+        //the kth asymptote parametric equation in complex plane is
+        //s=AsymptotesOrigin+t*exp(%i*AsymptotesAngles(k)) for t>0
+    else
+        AsymptotesAngles=[]
+        AsymptotesOrigin=%nan
+    end
+endfunction
diff --git a/scilab/modules/cacsd/macros/simplify_zp.sci b/scilab/modules/cacsd/macros/simplify_zp.sci
new file mode 100644 (file)
index 0000000..aef6567
--- /dev/null
@@ -0,0 +1,78 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function [z,p,C]=simplify_zp(z,p,tol)
+    iszpk=typeof(z)=="zpk"
+    if iszpk then //simplify_zp(sys,tol)
+        if argn(2)>2 then
+            error(msprintf(_("%s: Wrong number of input argument: at most %d expected.\n"),"simplify_zp",2))
+        else
+            if argn(2)==1 then
+                tol=0;
+            else
+                tol=p;
+            end
+            sys=z;
+        end
+        if type(tol)<>1|~isreal(tol)|size(tol)<>1|tol<0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: A scalar (>= 0) expected.\n"),"simplify_zp",2))
+        end
+        if argn(1)>1 then
+            error(msprintf(_("%s: Wrong number of output argument: %d expected.\n"),"simplify_zp",1))
+        end
+    else
+        if argn(2)==2 then  tol=0;end
+        if type(z)<>1 then
+            error(msprintf(_("Wrong type for input argument %d: Real or complex array expected.\n"),"simplify_zp",1))
+        end
+        if type(p)<>1 then
+            error(msprintf(_("Wrong type for input argument %d: Real or complex array expected.\n"),"simplify_zp",2))
+        end
+        if type(tol)<>1|~isreal(tol)|size(tol)<>1|tol<0 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: A scalar (>= 0) expected.\n"),"simplify_zp",3))
+        end
+        g=1
+        dt=[]
+        sys=zpk(z,p,g,dt)
+    end
+
+    [ny,nu]=size(sys)
+    C=cell(ny,nu);
+    for k=1:nu
+        for l=1:ny
+            slk=sys(l,k)
+            z=slk.Z{1}
+            p=slk.P{1}
+            //find common values
+            iz=[];ip=[];
+            for i=1:size(z,"*")
+                for j=1:size(p,"*")
+                    if and(j<>ip)&abs(z(i)-p(j))<=tol*(1+abs(z(i))) then
+                        iz=[iz,i];
+                        ip=[ip,j];
+                        break
+                    end
+                end
+            end
+            C{l,k}=p(ip)
+            //remove common values
+            p(ip)=[]
+            z(iz)=[]
+
+
+            slk.Z={z};slk.P={p}
+            sys(l,k)=slk;
+        end
+    end
+    if ~iszpk then
+        z=sys.Z{1}
+        p=sys.P{1}
+        C=C{1}
+    else
+        z=sys,p=C;
+    end
+endfunction
diff --git a/scilab/modules/cacsd/macros/ss2zp.sci b/scilab/modules/cacsd/macros/ss2zp.sci
new file mode 100644 (file)
index 0000000..fffb949
--- /dev/null
@@ -0,0 +1,62 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function [z,p,k]=ss2zp(S)
+    if typeof(S)<>"state-space" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Linear state space system expected.\n"),"ss2zp",1))
+    end
+    [ny,nu]=size(S)
+    if nu<>1 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: a single input system expected.\n"),"ss2zp",1))
+    end
+    p=spec(S.A);
+    z=[];
+    k=[];
+    for i=1:ny
+        //F=systmat(minss(S(i,1))); //Should be an alternative
+        F=systmat(S(i,1));
+        if type(S.D)==2&degree(S.D(i,1))>0 then
+            //non proper system
+            num=det(F)
+            zi=roots(num);
+            k=[k coeff(num,degree(num))];
+        else
+            [Q,Z,Qd,Zd]=kroneck(F);
+            sgn=sign(det(Z))
+            k_inf=1:Qd(2);
+            F_inf=Q(k_inf,:)*F*Z(:,k_inf);
+            if Qd(3)==0 then //no transmission zeros
+                k=[k;prod(coeff(diag(F_inf),0))];
+                zi=[];
+            else
+                k_finite=Qd(2)+(1:Qd(3));
+                F_finite=Q(k_finite,:)*F*Z(:,k_finite);
+                k=[k;sgn*prod(coeff(diag(F_inf),0))*prod(coeff(diag(F_finite),1))];
+                zi=spec(-coeff(F_finite,0),coeff(F_finite,1));
+                //force complex values to be exactly conjugate (spec may return
+                //nearly complex conjugate pairs
+                ii=find(imag(zi)>0)
+                if ii<>[] then zi(ii+1)=conj(zi(ii));end
+            end
+        end
+
+        if i==1 then
+            z=zi
+        else
+            nz=size(z,1);
+            nzi=size(zi,1);
+            if nzi>nz then
+                z(nz+1:nzi)=%inf;
+            elseif nz>nzi then
+                zi($+1:nz)=%inf
+            end
+            z=[z zi];
+        end
+    end
+    if and(imag(z)==0) then z=real(z);end
+
+endfunction
diff --git a/scilab/modules/cacsd/macros/tf2zp.sci b/scilab/modules/cacsd/macros/tf2zp.sci
new file mode 100644 (file)
index 0000000..1d3a2d0
--- /dev/null
@@ -0,0 +1,45 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function [z,p,k]=tf2zp(S)
+    if typeof(S)<>"rational" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: transfer function expected.\n"),"tf2zp",1))
+    end
+    [ny,nu]=size(S)
+    if nu<>1 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: a single input system expected.\n"),"tf2zp",1))
+    end
+    if ny==1 then //siso case
+        p=roots(S.den);
+        z=roots(S.num);
+        k=coeff(S.num,degree(S.num))./coeff(S.den,degree(S.den));
+    else
+        //find common denominator
+        [den,fact]=lcm(S.den);
+        num=S.num.*fact;
+        p=roots(den,"e");
+
+        k=[];
+        for i=1:ny
+            k=[k;coeff(num(i),degree(num(i)))];
+            zi=roots(num(i),"e")
+            if i==1 then
+                z=zi
+            else
+                nz=size(z,1);
+                nzi=size(zi,1);
+                if nzi>nz then
+                    z(nz+1:nzi)=%inf;
+                elseif nz>nzi then
+                    zi($+1:nz)=%inf
+                end
+                z=[z,zi];
+            end
+        end
+        k=k/coeff(den,degree(den));
+    end
+endfunction
index 576ed41..0d6e642 100644 (file)
@@ -34,14 +34,26 @@ function [nt,dt,rk]=trzeros(Sl)
 
     if sltyp == "rational" then
         if size(Sl)==1 then
-            nt=roots(Sl("num"));dt=[];rk=1;
+            nt=roots(Sl.num);dt=[];rk=1;
             return;
         end
         Sl=tf2ss(Sl);
     end
 
+    if sltyp == "zpk" then
+        if size(Sl)==1 then
+            nt=Sl.Z{1};dt=[];rk=1;
+            return;
+        end
+        Sl=zpk2ss(Sl);
+    end
+
     if typeof(Sl)<>"state-space" then
-        error(msprintf(gettext("%s: Wrong type for input argument #%d: A linear dynamical system or a polynomial expected.\n"),"trzeros",1))
+        ierr=execstr("[nt,dt,rk]=%"+overloadname(Sl)+"_trzeros(Sl)","errcatch")
+        if ierr<>0 then
+            error(msprintf(gettext("%s: Wrong type for input argument: Linear dynamical system expected.\n"),"trzeros",1))
+        end
+        return
     end
 
     //Sl=minss(Sl);
diff --git a/scilab/modules/cacsd/macros/zp2ss.sci b/scilab/modules/cacsd/macros/zp2ss.sci
new file mode 100644 (file)
index 0000000..650c954
--- /dev/null
@@ -0,0 +1,132 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function s=zp2ss(Z,P,K,dt)
+    //zero pole gain to state space (simo system)
+    if argn(2)<4 then dt=[];end
+    if type(Z)<>1 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex array expected.\n"),"zp2ss",1))
+    end
+    siso=and(size(K)==1)
+    if siso then Z=Z(:);end
+
+    for k=1:size(Z,2)
+        z=Z(:,k);
+        Zc=z(imag(z)<>0);nc=size(Zc,"*");
+        if modulo(nc,2)<>0|size(intersect(Zc,conj(Zc)),"*")<nc/2 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: complex zeros  must appear in complex conjugate pairs.\n"),"zp2ss",1))
+        end
+    end
+
+    if type(P)<>1 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),"zp2ss",2))
+    end
+    Pc=P(imag(P)<>0);nc=size(Pc,"*");
+    if modulo(nc,2)<>0|size(intersect(Pc,conj(Pc)),"*")<nc/2 then
+        error(msprintf(_("%s: Wrong value for input argument #%d: complex poles  must appear in complex conjugate pairs.\n"),"zp2ss",2))
+    end
+
+    if type(K)<>1  then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A real vector expected.\n"),"zp2ss",3))
+    end
+    if Z<>[]&(size(K,"*")<>size(Z,2)) then
+        error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions ""expected.\n"),"zp2ss",1,3))
+    end
+    if and(type(dt)<>[1 10])|and(size(dt,"*")<>[0 1]) then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A scalar or a string expected.\n"),"zp2ss",4))
+    end
+
+    if siso then
+        s=zp2ss_siso(Z,P,K,dt)
+    else
+        s=[];
+        for k=1:size(Z,2)
+            s=[s;zp2ss_siso(Z(:,k),P,K(k),dt)];
+        end
+        s=minss(s)
+    end
+endfunction
+
+function s=zp2ss_siso(Z,P,K,dt)
+    //remove poles and zeros at infinity
+    Z(Z==%inf)=[];
+    P(P==%inf)=[];
+
+    //Split real and complex
+    Zr=real(Z(imag(Z)==0));nZr=size(Zr,"*");
+    Zc=Z(imag(Z)<0);nZc=size(Zc,"*");
+
+    Pr=real(P(imag(P)==0));nPr=size(Pr,"*");
+    Pc=P(imag(P)<0);nPc=size(Pc,"*");
+
+    //real (zero pole) pairs
+    nr=min(nZr,nPr)
+    s=syslin(dt,[],[],[],1);
+    for k=1:nr
+        s=s*syslin(dt,Pr(k),1,Pr(k)-Zr(k),1);
+    end
+    Zr=Zr(nr+1:$);nZr=nZr-nr;
+    Pr=Pr(nr+1:$);nPr=nPr-nr;
+    //complex (zero pole) pairs
+    nc=min(nZc,nPc) ;
+    for k=1:nc
+        wn=abs(Pc(k));
+        A=[2*real(Pc(k)) -wn;wn 0];
+        B=[1;0];
+        C=[2*real(Pc(k)-Zc(k)), (abs(Zc(k))^2-wn^2)/wn]
+        s=s*syslin(dt,A,B,C,1);
+    end
+    Zc=Zc(nc+1:$);nZc=nZc-nc;
+    Pc=Pc(nc+1:$);nPc=nPc-nc;
+    // (complex zeros real poles)
+    nc=min(nZc,floor(nPr/2)) ;
+    l=1
+    for k=1:nc
+        A=[Pr(l)+Pr(l+1) -Pr(l)*Pr(l+1);1 0];
+        B=[1;0];
+        C=[-2*real(Zc(k))+Pr(l)+Pr(l+1),abs(Zc(k))^2-Pr(l)*Pr(l+1)]
+        l=l+2
+        s=s*syslin(dt,A,B,C,1);
+    end
+    Zc=Zc(nc+1:$);nZc=nZc-nc;
+    Pr=Pr(2*nc+1:$);nPr=nPr-2*nc;
+    // (real zero, complex poles) pairs
+    nrc=min(nZr,nPc)
+    for k=1:nrc
+        wn=abs(Pc(k));
+        A=[2*real(Pc(k)) -wn;wn 0];
+        B=[1;0];
+        C=[1,-Zr(k)/wn];
+        s=s*syslin(dt,A,B,C,0);
+    end
+    Zr=Zr(nrc+1:$);nZr=nZr-nrc;
+    Pc=Pc(nrc+1:$);nPc=nPc-nrc;
+
+    // remaining real poles
+    for k=1:nPr
+        s=s*syslin(dt,Pr(k),1,1,0);
+    end
+    //remaining complex poles
+    for k=1:nPc
+        wn=abs(Pc(k));
+        A=[2*real(Pc(k)) -wn;wn 0];
+        s=s*syslin(dt,A,[1;0],[0 1/wn],0);
+    end
+    //remaining real zeros (unproper system)
+    if nZr>0 then
+        if dt=="c" then var="s"; else var="z";end
+        s=s*syslin(dt,[],[],[],poly(Zr,var,"r"));
+    end
+    //remaining complex zeros (unproper system)
+    if nZc>0 then
+        if dt=="c" then var="s"; else var="z";end
+        s=s*syslin(dt,[],[],[],real(poly([Zc(:),conj(Zc(:))],var,"r")));
+    end
+    //apply gain
+    s.C=s.C*K;
+    s.D=s.D*K;
+endfunction
diff --git a/scilab/modules/cacsd/macros/zp2tf.sci b/scilab/modules/cacsd/macros/zp2tf.sci
new file mode 100644 (file)
index 0000000..1d8f5c3
--- /dev/null
@@ -0,0 +1,59 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function s=zp2tf(Z,P,K,dt)
+    //zero pole gain to state space (simo system)
+    if argn(2)<4 then dt=[];end
+    if argn(2)<3 then K=1;end
+    if type(Z)<>1 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex array expected.\n"),"zp2tf",1))
+    end
+    siso=and(size(K)==1)
+    if siso then Z=Z(:);end
+    for k=1:size(Z,2)
+        z=Z(:,k);
+        Zc=z(imag(z)<>0);nc=size(Zc,"*");
+        if modulo(nc,2)<>0|size(intersect(Zc,conj(Zc)),"*")<nc/2 then
+            error(msprintf(_("%s: Wrong value for input argument #%d: complex zeros  must appear in complex conjugate pairs.\n"),"zp2tf",1))
+        end
+    end
+
+    if type(P)<>1 then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),"zp2tf",2))
+    end
+    Pc=P(imag(P)<>0);nc=size(Pc,"*");
+    if modulo(nc,2)<>0|size(intersect(Pc,conj(Pc)),"*")<nc/2 then
+        error(msprintf(_("%s: Wrong value for input argument #%d: complex poles  must appear in complex conjugate pairs.\n"),"zp2tf",2))
+    end
+
+    if type(K)<>1  then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A real vector expected.\n"),"zp2tf",3))
+    end
+    if Z<>[]&(size(K,"*")<>size(Z,2)) then
+        error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same column dimensions ""expected.\n"),"zp2tf",1,3))
+    end
+    if and(type(dt)<>[1 10])|and(size(dt,"*")<>[0 1]) then
+        error(msprintf(_("%s: Wrong type for input argument #%d: A scalar or a string expected.\n"),"zp2tf",4))
+    end
+
+    if siso then
+        s=zp2tf_siso(Z,P,K,dt)
+    else
+        s=[];
+        for k=1:size(Z,2)
+            s=[s;zp2tf_siso(Z(:,k),P,K(k),dt)];
+        end
+    end
+endfunction
+
+function s=zp2tf_siso(Z,P,K,dt)
+    //remove poles and zeros at infinity
+    Z(Z==%inf)=[];
+    P(P==%inf)=[];
+    if dt=="c" then var="s"; else var="z";end
+    s=syslin(dt,(real(poly(Z,var,"r"))*K)/real(poly(P,var,"r")))
+endfunction
diff --git a/scilab/modules/cacsd/macros/zpk.sci b/scilab/modules/cacsd/macros/zpk.sci
new file mode 100644 (file)
index 0000000..ab30601
--- /dev/null
@@ -0,0 +1,109 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function s=zpk(varargin)
+    if size(varargin)==1 then //zpk(sys)
+        sys=varargin(1)
+        dt=sys.dt
+        select typeof(sys)
+        case "state-space"
+            [ny,nu]=size(sys);
+            z=cell(ny,nu);
+            p=cell(ny,nu)
+            k=zeros(ny,nu);
+            for i=1:ny
+                for j=1:nu
+                    [z{i,j},p{i,j},k(i,j)]=ss2zp(minss(sys(i,j)))
+                end
+            end
+        case "rational"
+            [ny,nu]=size(sys);
+            z=cell(ny,nu);
+            p=cell(ny,nu);
+            k=zeros(ny,nu);
+            for i=1:ny
+                for j=1:nu
+                    [z{i,j},p{i,j},k(i,j)]=tf2zp(sys(i,j))
+                end
+            end
+        case "zpk"
+            s=sys
+            return
+        else
+            error(msprintf(_("Wrong type for argument %d: A system in state space or transfer matrix form expected.\n"),"zpk",1))
+        end
+    elseif size(varargin)==4 then//zpk(z,p,k,dt)
+        z=varargin(1);
+        p=varargin(2);
+        k=varargin(3);
+        dt=varargin(4);
+        if and(type(dt)<>[1 10])|and(size(dt,"*")<>[0 1]) then
+            error(msprintf(_("%s: Wrong type for input argument #%d: A scalar or a string expected.\n"),"zpk",4))
+        end
+        if typeof(z)=="ce" then
+            if typeof(p)<>"ce" then
+                error(msprintf(_("%s: Wrong type for input argument  #%d: Cell expected.\n"),"zpk",2))
+            end
+            if typeof(k)<>"constant"|~isreal(k) then
+                error(msprintf(_("%s: Wrong type for input argument #%d: A real vector expected.\n"),"zpk",3))
+            end
+
+            if or(size(z)<>size(p)) then
+                error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"zpk",1,2))
+            end
+            if or(size(z)<>size(k)) then
+                error(msprintf(_("%s: Incompatible input arguments #%d and #%d: Same sizes expected.\n"),"zpk",1,3))
+            end
+            [ny,nu]=size(z);
+            for iy=1:ny
+                for iu=1:nu
+                    if type(z{iy,iu})<>1 then
+                        error(msprintf(_("%s: Wrong type for input argument  #%d: Cell elements must be numerical arrays.\n"),"zpk",1))
+                    end
+                    if type(p{iy,iu})<>1 then
+                        error(msprintf(_("%s: Wrong type for input argument  #%d: Cell elements must be numerical arrays.\n"),"zpk",2))
+                    end
+                end
+            end
+
+        elseif typeof(z)=="constant" then
+            if and(size(z)>1) then
+                error(msprintf(_("%s: Wrong type for input argument #%d: A vector expected.\n"),"zpk",1))
+            end
+            if and(size(p)>1) then
+                error(msprintf(_("%s: Wrong type for input argument #%d: A vector expected.\n"),"zpk",2))
+            end
+            if size(k,"*")<>1|~isreal(k) then
+                error(msprintf(_("%s: Wrong type for input argument #%d: Real scalar expected.\n"),"zpk",3))
+            end
+            ny=1;nu=1;
+            z={z};p={p};
+        else
+            error(msprintf(_("%s: Wrong type for input argument #%d: A vector or a cell of vectors expected.\n"),"zpk",1))
+        end
+    else
+        error(msprintf(_("%s: Wrong number of input argument(s): %d or %d expected."),"zpk",1,4))
+    end
+    //order poles ans zeros
+    for iy=1:ny
+        for iu=1:nu
+            if k(iy,iu)<>0 then
+                zz=z{iy,iu}(:);
+                [s,l]=gsort([real(zz),imag(zz)],"lr","d");
+                z{iy,iu}=zz(l);
+
+                pp=p{iy,iu}(:);
+                [s,l]=gsort([real(pp),imag(pp)],"lr","d");
+                p{iy,iu}=pp(l);
+            else
+                z{iy,iu}=[];
+                p{iy,iu}=[];
+            end
+        end
+    end
+    s=mlist(["zpk","Z","P","K","dt"],z,p,k,dt)
+endfunction
diff --git a/scilab/modules/cacsd/macros/zpk2ss.sci b/scilab/modules/cacsd/macros/zpk2ss.sci
new file mode 100644 (file)
index 0000000..7bdc977
--- /dev/null
@@ -0,0 +1,109 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function s=zpk2ss(sys)
+    //zero pole gain to state space (simo system)
+
+    if typeof(sys)<>"zpk" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: zero-pole-gain representation expected.\n"),"zpk2ss",1))
+    end
+    [ny,nu]=size(sys)
+    siso=ny*nu==1
+
+
+    if siso then
+        s=zp2ss_siso(sys.Z{1},sys.P{1},sys.K,sys.dt);
+    else
+        s=[];
+        for l=1:ny
+            for k=1:nu
+                s(l,k)=zp2ss_siso(sys.Z{l,k},sys.P{l,k},sys.K(l,k),sys.dt);
+            end
+        end
+        s=minss(s);
+    end
+endfunction
+
+function s=zp2ss_siso(Z,P,K,dt)
+    //remove poles and zeros at infinity
+    Z(Z==%inf)=[];
+    P(P==%inf)=[];
+
+    //Split real and complex
+    Zr=real(Z(imag(Z)==0));nZr=size(Zr,"*");
+    Zc=Z(imag(Z)<0);nZc=size(Zc,"*");
+
+    Pr=real(P(imag(P)==0));nPr=size(Pr,"*");
+    Pc=P(imag(P)<0);nPc=size(Pc,"*");
+
+    //real (zero pole) pairs
+    nr=min(nZr,nPr)
+    s=syslin(dt,[],[],[],1);
+    for k=1:nr
+        s=s*syslin(dt,Pr(k),1,Pr(k)-Zr(k),1);
+    end
+    Zr=Zr(nr+1:$);nZr=nZr-nr;
+    Pr=Pr(nr+1:$);nPr=nPr-nr;
+    //complex (zero pole) pairs
+    nc=min(nZc,nPc) ;
+    for k=1:nc
+        wn=abs(Pc(k));
+        A=[2*real(Pc(k)) -wn;wn 0];
+        B=[1;0];
+        C=[2*real(Pc(k)-Zc(k)), (abs(Zc(k))^2-wn^2)/wn]
+        s=s*syslin(dt,A,B,C,1);
+    end
+    Zc=Zc(nc+1:$);nZc=nZc-nc;
+    Pc=Pc(nc+1:$);nPc=nPc-nc;
+    // (complex zeros real poles)
+    nc=min(nZc,floor(nPr/2)) ;
+    l=1
+    for k=1:nc
+        A=[Pr(l)+Pr(l+1) -Pr(l)*Pr(l+1);1 0];
+        B=[1;0];
+        C=[-2*real(Zc(k))+Pr(l)+Pr(l+1),abs(Zc(k))^2-Pr(l)*Pr(l+1)]
+        l=l+2
+        s=s*syslin(dt,A,B,C,1);
+    end
+    Zc=Zc(nc+1:$);nZc=nZc-nc;
+    Pr=Pr(2*nc+1:$);nPr=nPr-2*nc;
+    // (real zero, complex poles) pairs
+    nrc=min(nZr,nPc)
+    for k=1:nrc
+        wn=abs(Pc(k));
+        A=[2*real(Pc(k)) -wn;wn 0];
+        B=[1;0];
+        C=[1,-Zr(k)/wn];
+        s=s*syslin(dt,A,B,C,0);
+    end
+    Zr=Zr(nrc+1:$);nZr=nZr-nrc;
+    Pc=Pc(nrc+1:$);nPc=nPc-nrc;
+
+    // remaining real poles
+    for k=1:nPr
+        s=s*syslin(dt,Pr(k),1,1,0);
+    end
+    //remaining complex poles
+    for k=1:nPc
+        wn=abs(Pc(k));
+        A=[2*real(Pc(k)) -wn;wn 0];
+        s=s*syslin(dt,A,[1;0],[0 1/wn],0);
+    end
+    //remaining real zeros (unproper system)
+    if nZr>0 then
+        if dt=="c" then var="s"; else var="z";end
+        s=s*syslin(dt,[],[],[],poly(Zr,var,"r"));
+    end
+    //remaining complex zeros (unproper system)
+    if nZc>0 then
+        if dt=="c" then var="s"; else var="z";end
+        s=s*syslin(dt,[],[],[],real(poly([Zc(:),conj(Zc(:))],var,"r")));
+    end
+    //apply gain
+    s.C=s.C*K;
+    s.D=s.D*K;
+endfunction
diff --git a/scilab/modules/cacsd/macros/zpk2tf.sci b/scilab/modules/cacsd/macros/zpk2tf.sci
new file mode 100644 (file)
index 0000000..2f90e61
--- /dev/null
@@ -0,0 +1,35 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C)  2016 - INRIA - Serge Steer
+//
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+function s=zpk2tf(sys)
+    //zero pole gain to state space (simo system)
+
+    if typeof(sys)<>"zpk" then
+        error(msprintf(_("%s: Wrong type for input argument #%d: zero-pole-gain representation expected.\n"),"zpk2tf",1))
+    end
+    [ny,nu]=size(sys)
+    siso=ny*nu==1
+
+    if siso then
+        s=zp2tf_siso(sys.Z{1},sys.P{1},sys.K,sys.dt)
+    else
+        s=[];
+        for l=1:ny
+            for k=1:nu
+                s(l,k)=zp2tf_siso(sys.Z{l,k},sys.P{l,k},sys.K(l,k),sys.dt);
+            end
+        end
+    end
+endfunction
+
+function s=zp2tf_siso(Z,P,K,dt)
+    //remove poles and zeros at infinity
+    Z(Z==%inf)=[];
+    P(P==%inf)=[];
+    if dt=="c" then var="s"; else var="z";end
+    s=syslin(dt,(real(poly(Z,var,"r"))*K)/real(poly(P,var,"r")))
+endfunction
index ec0c6e1..9cda1db 100644 (file)
@@ -17,8 +17,7 @@
 //Incorrect argument check in h_inf
 G=syslin("c",1/%s^3);
 [P,r]=macglov(G);
-assert_checktrue(execstr("[K,ro]=h_inf(P,r,0,1,30)","errcatch")==0);
-h_inf: P22 is stabilizable.
+assert_checktrue(execstr("[K,ro]=h_inf(P,r,0,1,30)","errcatch")==0);h_inf: P22 is stabilizable.
 h_inf: P22 is detectable.
  gama =       1.4142135624 Unfeasible (Hx hamiltonian)   test =     0.30000E+01
  gama =       2.0000000000 Unfeasible (Hx hamiltonian)   test =     0.15613E+01
index 51fe7bd..92e2ca0 100644 (file)
@@ -5,11 +5,11 @@
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- TEST WITH GRAPHIC -->
-s=poly(0,'s')
+s=poly(0,"s")
  s  = 
     
    s
 num=10*s+20;
 den=s^3+14*s^2+35*s-50;
-h=syslin('c',num/den);
-show_margins(h,'bode');
+h=syslin("c",num/den);
+show_margins(h,"bode");
index 7f3a27b..c4f5a00 100644 (file)
@@ -13,6 +13,6 @@
 //
 // <-- Short Description -->
 // ss2ss does not transform initial state
-before = syslin('c',-1,1,1,0,1);
+before = syslin("c",-1,1,1,0,1);
 after = ss2ss(before, 2);
 assert_checkequal(after.x0, before.x0 / 2);
index b2462bf..7712eb9 100644 (file)
 A = [-5,-6;
      6,-4]
  A  = 
-  - 5.  - 6.
-    6.  - 4.
+  -5.  -6.
+   6.  -4.
 //five inputs
 B = [0,-14,17,2,9;
      2,17,19,-10,-9]
  B  = 
-    0.  - 14.    17.    2.     9.
-    2.    17.    19.  - 10.  - 9.
+   0.  -14.   17.   2.    9.
+   2.   17.   19.  -10.  -9.
 //three outputs
 C = [0,-17;
      3,-14;
      8,7]
  C  = 
-    0.  - 17.
-    3.  - 14.
-    8.    7. 
+   0.  -17.
+   3.  -14.
+   8.   7. 
 D = [1,1,1,3,4;
      1,1,6,0,2;
      1,1,7,5,5]
  D  = 
-    1.    1.    1.    3.    4.
-    1.    1.    6.    0.    2.
-    1.    1.    7.    5.    5.
+   1.   1.   1.   3.   4.
+   1.   1.   6.   0.   2.
+   1.   1.   7.   5.   5.
 PP=syslin('c',A,B,C,D);
 gopt=gamitg(PP,[1 1]);
 if execstr('KK=ccontrg(PP,[1 1],gopt+0.1)','errcatch')<>0 then bugmes();quit;end
index 191a1b9..422198e 100644 (file)
@@ -17,8 +17,8 @@ K=485000.;
 h=syslin('c', K / ( s * (s+100)^2 ) );
 [gm,fr]=g_margin(h)
  fr  = 
-    15.915494
+   15.915494
  gm  = 
-    12.305765
+   12.305765
 if gm==[] then bugmes();quit;end
 if abs(2*%pi*fr-100)>100*%eps then bugmes();quit;end
index 73fa768..dd5172a 100644 (file)
@@ -17,7 +17,7 @@
 s=poly(0,'s');
 n=[1+s   2+3*s+4*s^2        5; 0        1-s             s];
 d=[1+3*s   5-s^3           s+1;1+s     1+s+s^2      3*s-1];
-h=syslin('c',n./d); 
+h=syslin('c',n./d);
 assert_checktrue(execstr("plzr(h)","errcatch")==0);
 fig=gcf();
 ax=fig.children;
index 4953dd8..ca9fb46 100644 (file)
@@ -8,9 +8,9 @@
 //
 ny=1,nu=1,sig=0.01;
  ny  = 
-    1.
+   1.
  nu  = 
-    1.
+   1.
 ar=armac(1,[0,0.2],[0,1],ny,nu,sig);
 [S,Sn]=arma2ss(ar);
 A=[0,0.2;0,0];B=[0;1];C=[1,0];D=0;
@@ -26,7 +26,7 @@ assert_checkequal(Sn.D,D);
 //
 ny=1,nu=1;
  ny  = 
-    1.
+   1.
 ar=armac([1,-0.8,0.2],0.001,0,ny,nu,0);
 [S,Sn]=arma2ss(ar);
 A=[0.8,-0.2;1,0];B=[0.001;0];C=[1,0];D=0;
index e0c1eff..c789235 100644 (file)
@@ -9,6 +9,7 @@
 //
 // <-- ENGLISH IMPOSED -->
 //
+old=driver("null");
 function r=checkbode(h,leg)
     fig=gcf();
     r=%t;
@@ -43,71 +44,78 @@ hd=ss2tf(sld);
 [w,rf]=repfreq(h,0.01,100);
 // Continuous time
 clf();bode(h);
-if ~checkbode(h) then bugmes();quit;end
+assert_checktrue(checkbode(h));
 clf();bode(h,"h");
-if ~checkbode(h,"h") then bugmes();quit;end
+assert_checktrue(checkbode(h,"h"));
 clf();bode(h,0.01,100);
-if ~checkbode(h) then bugmes();quit;end
+assert_checktrue(checkbode(h));
 clf();bode(h,0.01,100,"h");
-if ~checkbode(h,"h") then bugmes();quit;end
+assert_checktrue(checkbode(h,"h"));
 clf();bode(h,0.01,100,0.01);
-if ~checkbode(h) then bugmes();quit;end
+assert_checktrue(checkbode(h));
 clf();bode(sl,0.01,100);
-if ~checkbode(sl) then bugmes();quit;end
+assert_checktrue(checkbode(sl));
 clf();bode(sl,0.01,100,0.01);
 // Continuous time SIMO
 h=[h;h+1];sl=[sl;sl+1];
 clf();bode(h);
-if ~checkbode(h) then bugmes();quit;end
+assert_checktrue(checkbode(h));
+clf();bode(zpk(h));
+assert_checktrue(checkbode(zpk(h)));
 clf();bode(h,["h";"h+1"]);
-if ~checkbode(h,["h";"h+1"]) then bugmes();quit;end
+assert_checktrue(checkbode(h,["h";"h+1"]));
+clf();bode(zpk(h),["h";"h+1"]);
+assert_checktrue(checkbode(zpk(h),["h";"h+1"]));
 clf();bode(h,0.01,100);
-if ~checkbode(h) then bugmes();quit;end
+assert_checktrue(checkbode(h));
 clf();bode(h,0.01,100,["h";"h+1"]);
-if ~checkbode(h,["h";"h+1"]) then bugmes();quit;end
+assert_checktrue(checkbode(h,["h";"h+1"]));
 clf();bode(h,0.01,100,0.01);
-if ~checkbode(h) then bugmes();quit;end
+assert_checktrue(checkbode(h));
 clf();bode(sl,0.01,100);
-if ~checkbode(sl) then bugmes();quit;end
+assert_checktrue(checkbode(sl));
 clf();bode(sl,0.01,100,0.01);
 // Discrete case
 clf();bode(hd);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd) then bugmes();quit;end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,"h");
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd,"h") then bugmes();quit;end
+assert_checktrue(checkbode(hd,"h"));
 clf();bode(hd,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd) then bugmes();quit;end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,0.01,100,"h");
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd,"h") then bugmes();quit;end
+assert_checktrue(checkbode(hd,"h"));
 clf();bode(hd,0.01,100,0.01);
-if ~checkbode(hd) then bugmes();quit;end
+assert_checktrue(checkbode(hd));
 clf();bode(sld,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(sld) then bugmes();quit;end
+assert_checktrue(checkbode(sld));
 clf();bode(sl,0.01,100,0.01);
 // Discrete case SIMO
 hd=[hd;hd+1];sld=[sld;sld+1];
 clf();bode(hd);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd) then bugmes();quit;end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,["h";"h+1"]);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd,["h";"h+1"]) then bugmes();quit;end
+assert_checktrue(checkbode(hd,["h";"h+1"]));
+clf();bode(zpk(hd),["h";"h+1"]);
+WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
+assert_checktrue(checkbode(zpk(hd),["h";"h+1"]));
 clf();bode(hd,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd) then bugmes();quit;end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,0.01,100,["h";"h+1"]);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(hd,["h";"h+1"]) then bugmes();quit;end
+assert_checktrue(checkbode(hd,["h";"h+1"]));
 clf();bode(hd,0.01,100,0.01);
-if ~checkbode(hd) then bugmes();quit;end
+assert_checktrue(checkbode(hd));
 clf();bode(sld,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if ~checkbode(sld) then bugmes();quit;end
+assert_checktrue(checkbode(sld));
 clf();bode(sl,0.01,100,0.01);
 // bode given by precomputed frequency response
 h=syslin("c",n,d);
@@ -131,3 +139,6 @@ sys = syslin("c", G); // A continuous-time linear system in transfer matrix repr
 f_min = .0001; f_max = 1600; // Frequencies in Hz
 clf(); bode(sys, f_min, f_max, "rad"); // The optional argument "rad" converts Hz to rad/s
 bode_asymp(sys, 10, 1000); // Plots asymptotes in the given range of frequency (in rad/s).
+clf(); bode(zpk(sys), f_min, f_max, "rad"); // The optional argument "rad" converts Hz to rad/s
+bode_asymp(zpk(sys), 10, 1000); // Plots asymptotes in the given range of frequency (in rad/s).
+driver(old);
index 36a9417..6ed972e 100644 (file)
@@ -9,7 +9,7 @@
 //
 // <-- ENGLISH IMPOSED -->
 //
-
+old=driver("null");
 function r=checkbode(h,leg)
     fig=gcf();
     r=%t;
@@ -41,6 +41,7 @@ s=poly(0,"s");
 n=1+s;d=1+2*s;
 h=syslin("c",n,d);
 sl=tf2ss(h);
+
 sld=dscr(sl,0.01);
 hd=ss2tf(sld);
 
@@ -48,73 +49,81 @@ hd=ss2tf(sld);
 
 // Continuous time
 clf();bode(h);
-if ~checkbode(h) then pause,end
+assert_checktrue(checkbode(h));
+
 clf();bode(h,"h");
-if ~checkbode(h,"h") then pause,end
+assert_checktrue(checkbode(h,"h"));
 
 clf();bode(h,0.01,100);
-if ~checkbode(h) then pause,end
+assert_checktrue(checkbode(h));
 clf();bode(h,0.01,100,"h");
-if ~checkbode(h,"h") then pause,end
+assert_checktrue(checkbode(h,"h"));
 
 clf();bode(h,0.01,100,0.01);
-if ~checkbode(h) then pause,end
+assert_checktrue(checkbode(h));
 clf();bode(sl,0.01,100);
-if ~checkbode(sl) then pause,end
+assert_checktrue(checkbode(sl));
 clf();bode(sl,0.01,100,0.01);
 
 // Continuous time SIMO
 h=[h;h+1];sl=[sl;sl+1];
 clf();bode(h);
-if ~checkbode(h) then pause,end
+assert_checktrue(checkbode(h));
+clf();bode(zpk(h));
+assert_checktrue(checkbode(zpk(h)));
+
 clf();bode(h,["h";"h+1"]);
-if ~checkbode(h,["h";"h+1"]) then pause,end
+assert_checktrue(checkbode(h,["h";"h+1"]));
+clf();bode(zpk(h),["h";"h+1"]);
+assert_checktrue(checkbode(zpk(h),["h";"h+1"]));
 
 clf();bode(h,0.01,100);
-if ~checkbode(h) then pause,end
+assert_checktrue(checkbode(h));
 clf();bode(h,0.01,100,["h";"h+1"]);
-if ~checkbode(h,["h";"h+1"]) then pause,end
+assert_checktrue(checkbode(h,["h";"h+1"]));
 
 clf();bode(h,0.01,100,0.01);
-if ~checkbode(h) then pause,end
+assert_checktrue(checkbode(h));
 clf();bode(sl,0.01,100);
-if ~checkbode(sl) then pause,end
+assert_checktrue(checkbode(sl));
 clf();bode(sl,0.01,100,0.01);
 
 
 // Discrete case
 clf();bode(hd);
-if ~checkbode(hd) then pause,end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,"h");
-if ~checkbode(hd,"h") then pause,end
+assert_checktrue(checkbode(hd,"h"));
 
 clf();bode(hd,0.01,100);
-if ~checkbode(hd) then pause,end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,0.01,100,"h");
-if ~checkbode(hd,"h") then pause,end
+assert_checktrue(checkbode(hd,"h"));
 
 clf();bode(hd,0.01,100,0.01);
-if ~checkbode(hd) then pause,end
+assert_checktrue(checkbode(hd));
 clf();bode(sld,0.01,100);
-if ~checkbode(sld) then pause,end
+assert_checktrue(checkbode(sld));
 clf();bode(sl,0.01,100,0.01);
 
 // Discrete case SIMO
 hd=[hd;hd+1];sld=[sld;sld+1];
 clf();bode(hd);
-if ~checkbode(hd) then pause,end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,["h";"h+1"]);
-if ~checkbode(hd,["h";"h+1"]) then pause,end
+assert_checktrue(checkbode(hd,["h";"h+1"]));
+clf();bode(zpk(hd),["h";"h+1"]);
+assert_checktrue(checkbode(zpk(hd),["h";"h+1"]));
 
 clf();bode(hd,0.01,100);
-if ~checkbode(hd) then pause,end
+assert_checktrue(checkbode(hd));
 clf();bode(hd,0.01,100,["h";"h+1"]);
-if ~checkbode(hd,["h";"h+1"]) then pause,end
+assert_checktrue(checkbode(hd,["h";"h+1"]));
 
 clf();bode(hd,0.01,100,0.01);
-if ~checkbode(hd) then pause,end
+assert_checktrue(checkbode(hd));
 clf();bode(sld,0.01,100);
-if ~checkbode(sld) then pause,end
+assert_checktrue(checkbode(sld));
 clf();bode(sl,0.01,100,0.01);
 
 // bode given by precomputed frequency response
@@ -142,4 +151,9 @@ sys = syslin("c", G); // A continuous-time linear system in transfer matrix repr
 f_min = .0001; f_max = 1600; // Frequencies in Hz
 
 clf(); bode(sys, f_min, f_max, "rad"); // The optional argument "rad" converts Hz to rad/s
+
 bode_asymp(sys, 10, 1000); // Plots asymptotes in the given range of frequency (in rad/s).
+
+clf(); bode(zpk(sys), f_min, f_max, "rad"); // The optional argument "rad" converts Hz to rad/s
+bode_asymp(zpk(sys), 10, 1000); // Plots asymptotes in the given range of frequency (in rad/s).
+driver(old);
index 670f4cb..efe6769 100644 (file)
@@ -1,86 +1,32 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
-K=0.001;      // Minimum relative prediction error in the nyquist plan 
+K=0.001;      // Minimum relative prediction error in the nyquist plan
 Epss=0.002;   // minimum frequency distance with a singularity
 nptmax=5000;  //maximum number of discretization points
 pas=100/(2*%pi);
 s=%s;
-h=syslin('c',1/%s);n=1;
+h=syslin("c",1/%s);n=1;
 [f,bnds,split]=calfrq(h,0.01,100);
-if split<>1 then bugmes();quit;end
+assert_checktrue(split==1);
 rf=freq(h.num,h.den,2*%pi*%i*f);
 //finite difference derivative estimate
 ddf=diff(f)/pas;
 drf=(freq(h.num,h.den,2*%pi*%i*(f(1:$-1)+ddf))-rf(:,1:$-1));
 //error between computed and extrapolated value
 e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then bugmes();quit;end
-h=syslin('c',[1/(%s+0.5);1/(%s+0.3)]);n=2;
-[f,bnds,split]=calfrq(h,0.01,100);
-if split<>1 then bugmes();quit;end
-rf=freq(h.num,h.den,2*%pi*%i*f);
-//finite difference derivative estimate
-ddf=diff(f)/pas;
-drf=(freq(h.num,h.den,2*%pi*%i*(f(1:$-1)+ddf))-rf(:,1:$-1));
-//error between computed and extrapolated value
-e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then bugmes();quit;end
-h=syslin('c',(%s^2+2*0.9*10*%s+100)/(%s^2+2*0.3*10.1*%s+102.01));
-//h=h*syslin('c',(%s)/(%s^2+81)) ;
-n=1;
-[f,bnds,split]=calfrq(h,0.01,100);
-if size(split,1)<>1 then bugmes();quit;end
-rf=freq(h.num,h.den,2*%pi*%i*f);
-//finite difference derivative estimate
-ddf=diff(f)/100;
-drf=(freq(h.num,h.den,2*%pi*%i*(f(1:$-1)+ddf))-rf(:,1:$-1));
-//error between computed and extrapolated value
-e=rf(:,2:$)-(rf(:,1:$-1)+drf*100);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then bugmes();quit;end
-//case with singularity
-h=syslin('c',(%s)/(%s^2+81)) ;
-sing=9/(2*%pi);
-n=1;
-[f,bnds,split]=calfrq(h,0.01,100);
-if size(split,2)<>2 then bugmes();quit;end
-ks=split(2);
-if abs(f(ks-1)-f(ks))*2*%pi<Epss then bugmes();quit;end
-if f(ks-1)>sing|f(ks)<sing then bugmes();quit;end
-//finite difference derivative estimate
-f1=f(1:ks-15);//remove points near singularity for which pasmin constraint may be active
-rf=freq(h.num,h.den,2*%pi*%i*f1);
-ddf=diff(f1)/pas;
-drf=(freq(h.num,h.den,2*%pi*%i*(f1(1:$-1)+ddf))-rf(:,1:$-1));
-//error between computed and extrapolated value
-e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then bugmes();quit;end
-f1=f(ks+15:$);//remove points near singularity for which pasmin constraint may be active
-rf=freq(h.num,h.den,2*%pi*%i*f1);
-ddf=diff(f1)/pas;
-drf=(freq(h.num,h.den,2*%pi*%i*(f1(1:$-1)+ddf))-rf(:,1:$-1));
-//error between computed and extrapolated value
-e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then bugmes();quit;end
-//state space case
-sl=tf2ss(h);
-n=1;
-[f1,bnds1,split1]=calfrq(sl,0.01,100);
-if norm(f-f1)>1d-13 then bugmes();quit;end
-if or(split<>split1) then bugmes();quit;end
-//discrete case
-h=syslin('c',(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
-hd=ss2tf(dscr(h,0.01));
-[f,bnds,split]=calfrq(hd,0.00001,3);
-if size(split,1)<>1 then bugmes();quit;end
-rf=freq(h.num,h.den,exp(2*%pi*%i*f));
-//finite difference derivative estimate
-ddf=diff(f)/pas;
-drf=(freq(h.num,h.den,exp(2*%pi*%i*(f(1:$-1)+ddf)))-rf(:,1:$-1));
-//error between computed and extrapolated value
-e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then bugmes();quit;end
+assert_checktrue(max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])<=K);
+[f1,bnds1,split1]=calfrq(tf2ss(h),0.01,100);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+[f1,bnds1,split1]=calfrq(zpk(h),0.01,100);
+save /tmp/fii f1 bnds1 split1 f bnds split
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+return
index 00d0107..3e6c1a1 100644 (file)
@@ -1,30 +1,42 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
-K=0.001;      // Minimum relative prediction error in the nyquist plan 
+K=0.001;      // Minimum relative prediction error in the nyquist plan
 Epss=0.002;   // minimum frequency distance with a singularity
 nptmax=5000;  //maximum number of discretization points
 pas=100/(2*%pi);
 s=%s;
 
-h=syslin('c',1/%s);n=1;
+h=syslin("c",1/%s);n=1;
 
 
 [f,bnds,split]=calfrq(h,0.01,100);
-if split<>1 then pause,end
+assert_checktrue(split==1);
 rf=freq(h.num,h.den,2*%pi*%i*f);
 //finite difference derivative estimate
 ddf=diff(f)/pas;
 drf=(freq(h.num,h.den,2*%pi*%i*(f(1:$-1)+ddf))-rf(:,1:$-1));
 //error between computed and extrapolated value
 e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then pause,end
+assert_checktrue(max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])<=K);
+
+[f1,bnds1,split1]=calfrq(tf2ss(h),0.01,100);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
 
-h=syslin('c',[1/(%s+0.5);1/(%s+0.3)]);n=2;
+[f1,bnds1,split1]=calfrq(zpk(h),0.01,100);
+save /tmp/fii f1 bnds1 split1 f bnds split
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+return
+
+h=syslin("c",[1/(%s+0.5);1/(%s+0.3)]);n=2;
 [f,bnds,split]=calfrq(h,0.01,100);
 if split<>1 then pause,end
 rf=freq(h.num,h.den,2*%pi*%i*f);
@@ -33,15 +45,25 @@ ddf=diff(f)/pas;
 drf=(freq(h.num,h.den,2*%pi*%i*(f(1:$-1)+ddf))-rf(:,1:$-1));
 //error between computed and extrapolated value
 e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then pause,end
+assert_checktrue(max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])<=K);
+
+[f1,bnds1,split1]=calfrq(tf2ss(h),0.01,100);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+[f1,bnds1,split1]=calfrq(zpk(h),0.01,100);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
 
 
 
-h=syslin('c',(%s^2+2*0.9*10*%s+100)/(%s^2+2*0.3*10.1*%s+102.01));
+
+h=syslin("c",(%s^2+2*0.9*10*%s+100)/(%s^2+2*0.3*10.1*%s+102.01));
 //h=h*syslin('c',(%s)/(%s^2+81)) ;
 n=1;
 [f,bnds,split]=calfrq(h,0.01,100);
-if size(split,1)<>1 then pause,end
+assert_checktrue(size(split,1)==1);
 
 rf=freq(h.num,h.den,2*%pi*%i*f);
 //finite difference derivative estimate
@@ -49,22 +71,27 @@ ddf=diff(f)/100;
 drf=(freq(h.num,h.den,2*%pi*%i*(f(1:$-1)+ddf))-rf(:,1:$-1));
 //error between computed and extrapolated value
 e=rf(:,2:$)-(rf(:,1:$-1)+drf*100);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then pause,end
-
-
-
+assert_checktrue(max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])<=K);
 
+[f1,bnds1,split1]=calfrq(tf2ss(h),0.01,100);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+[f1,bnds1,split1]=calfrq(zpk(h),0.01,100);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
 
 
 //case with singularity
-h=syslin('c',(%s)/(%s^2+81)) ;
+h=syslin("c",(%s)/(%s^2+81)) ;
 sing=9/(2*%pi);
 n=1;
 [f,bnds,split]=calfrq(h,0.01,100);
-if size(split,2)<>2 then pause,end
+assert_checktrue(size(split,"*")==2);
 ks=split(2);
-if abs(f(ks-1)-f(ks))*2*%pi<Epss then pause,end
-if f(ks-1)>sing|f(ks)<sing then pause,end
+assert_checktrue(abs(f(ks-1)-f(ks))*2*%pi>=Epss);
+assert_checktrue(f(ks-1)<=sing&f(ks)>=sing);
 
 //finite difference derivative estimate
 f1=f(1:ks-15);//remove points near singularity for which pasmin constraint may be active
@@ -73,28 +100,39 @@ ddf=diff(f1)/pas;
 drf=(freq(h.num,h.den,2*%pi*%i*(f1(1:$-1)+ddf))-rf(:,1:$-1));
 //error between computed and extrapolated value
 e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then pause,end
+assert_checktrue(max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])<=K);
+
 f1=f(ks+15:$);//remove points near singularity for which pasmin constraint may be active
 rf=freq(h.num,h.den,2*%pi*%i*f1);
 ddf=diff(f1)/pas;
 drf=(freq(h.num,h.den,2*%pi*%i*(f1(1:$-1)+ddf))-rf(:,1:$-1));
 //error between computed and extrapolated value
 e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then pause,end
+assert_checktrue(max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])<=K);
 
 
 //state space case
 sl=tf2ss(h);
 n=1;
 [f1,bnds1,split1]=calfrq(sl,0.01,100);
-if norm(f-f1)>1d-13 then pause,end
-if or(split<>split1) then pause,end
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+// zpk case
+sl=zpk(h);
+n=1;
+[f1,bnds1,split1]=calfrq(sl,0.01,100);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+
+
 
 //discrete case
-h=syslin('c',(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
+h=syslin("c",(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
 hd=ss2tf(dscr(h,0.01));
 [f,bnds,split]=calfrq(hd,0.00001,3);
-if size(split,1)<>1 then pause,end
+assert_checktrue(size(split,"*")==1);
 
 rf=freq(h.num,h.den,exp(2*%pi*%i*f));
 //finite difference derivative estimate
@@ -102,4 +140,13 @@ ddf=diff(f)/pas;
 drf=(freq(h.num,h.den,exp(2*%pi*%i*(f(1:$-1)+ddf)))-rf(:,1:$-1));
 //error between computed and extrapolated value
 e=rf(:,2:$)-(rf(:,1:$-1)+drf*pas);
-if max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])>K then pause,end
+assert_checktrue(max([abs(real(e))/max(bnds(2)-bnds(1),1); abs(imag(e))/max(bnds(4)- bnds(3),1)])<=K);
+
+[f1,bnds1,split1]=calfrq(tf2ss(hd),0.00001,3);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
+[f1,bnds1,split1]=calfrq(zpk(hd),0.00001,3);
+assert_checkalmostequal(f,f1);
+assert_checkalmostequal(bnds,bnds1);
+assert_checkequal(split,split1);
index 2e598dd..ca9a6a8 100644 (file)
@@ -1,7 +1,7 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
@@ -9,68 +9,80 @@
 // Unit test for csim function
 a=0;b=1;c=2;
 t=0:0.1:1;
-sl=syslin('c',a,b,c);
+sl=syslin("c",a,b,c);
 u=ones(1,11);
 xrefstep = 0:0.1:1;
 yrefstep=0:0.2:2;
 //step
-y=csim('step',t,sl);
+y=csim("step",t,sl);
 assert_checkalmostequal(y, yrefstep);
-y=csim('step',[],sl);
+y=csim("step",t,ss2tf(sl));
+assert_checkalmostequal(y, yrefstep);
+y=csim("step",t,zpk(sl));
+assert_checkalmostequal(y, yrefstep);
+y=csim("step",[],sl);
 assert_checkequal(y, []);
-[y1,x]=csim('step',[],sl);
+[y1,x]=csim("step",[],sl);
 assert_checkequal(y1, []);
 assert_checkequal(x, []);
-[y1,x]=csim('step',t,sl);
+[y1,x]=csim("step",t,sl);
 assert_checkalmostequal(y1, yrefstep);
 assert_checkalmostequal(x, xrefstep);
-y=csim('step',t,sl,0);
+y=csim("step",t,sl,0);
 assert_checkalmostequal(y, yrefstep);
-[y1,x]=csim('step',t,sl,0);
+[y1,x]=csim("step",t,sl,0);
 assert_checkalmostequal(y1, yrefstep);
 assert_checkalmostequal(x, xrefstep);
-y=csim('step',t,sl,1);
+y=csim("step",t,sl,1);
 assert_checkalmostequal(y, yrefstep);
-y=csim('step',t,sl,0,[10*%eps %eps]);
+y=csim("step",t,sl,0,[10*%eps %eps]);
 assert_checkalmostequal(y, yrefstep);
-[y1,x]=csim('step',t,sl,1,[10*%eps %eps]);
+[y1,x]=csim("step",t,sl,1,[10*%eps %eps]);
 assert_checkalmostequal(y, yrefstep);
 assert_checkalmostequal(x, xrefstep);
 //impulse
 yrefimp=2*ones(1,11);
 xrefimp=ones(1,11);
-y=csim('impulse',t,sl);
+y=csim("impulse",t,sl);
+assert_checkalmostequal(y, yrefimp);
+y=csim("impulse",t,ss2tf(sl));
+assert_checkalmostequal(y, yrefimp);
+y=csim("impulse",t,zpk(sl));
 assert_checkalmostequal(y, yrefimp);
-y=csim('impulse',[],sl);
+y=csim("impulse",[],sl);
 assert_checkequal(y, []);
-[y1,x]=csim('impulse',[],sl);
+[y1,x]=csim("impulse",[],sl);
 assert_checkequal(y1, []);
 assert_checkequal(x, []);
 w=ones(t)-eye(t);
-y=csim('impulse',t,sl);
+y=csim("impulse",t,sl);
 assert_checkalmostequal(y, yrefimp);
-[y1,x]=csim('impulse',t,sl);
+[y1,x]=csim("impulse",t,sl);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
-y=csim('impulse',t,sl,0);
+y=csim("impulse",t,sl,0);
 assert_checkalmostequal(y, yrefimp);
-[y1,x]=csim('impulse',t,sl,0);
+[y1,x]=csim("impulse",t,sl,0);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
-y=csim('impulse',t,sl,1);
+y=csim("impulse",t,sl,1);
 assert_checkalmostequal(y, yrefimp);
-[y1,x]=csim('impulse',t,sl,1);
+[y1,x]=csim("impulse",t,sl,1);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
-y=csim('impulse',t,sl,0,[10*%eps %eps]);
+y=csim("impulse",t,sl,0,[10*%eps %eps]);
 assert_checkalmostequal(y, yrefimp);
-[y1,x]=csim('impulse',t,sl,1,[10*%eps %eps]);
+[y1,x]=csim("impulse",t,sl,1,[10*%eps %eps]);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
 //function
 function y=step(t),if t<0 then y=0,else y=1,end,endfunction
 y=csim(step,t,sl);
 assert_checkalmostequal(y, yrefstep);
+y=csim(step,t,ss2tf(sl));
+assert_checkalmostequal(y, yrefstep);
+y=csim(step,t,zpk(sl));
+assert_checkalmostequal(y, yrefstep);
 y=csim(step,[],sl);
 assert_checkequal(y, []);
 [y1,x]=csim(step,[],sl);
index a8a84f8..f89dd58 100644 (file)
@@ -1,7 +1,7 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 a=0;b=1;c=2;
 t=0:0.1:1;
-sl=syslin('c',a,b,c);
+sl=syslin("c",a,b,c);
 u=ones(1,11);
 xrefstep = 0:0.1:1;
 yrefstep=0:0.2:2;
 
 //step
-y=csim('step',t,sl);
+y=csim("step",t,sl);
 assert_checkalmostequal(y, yrefstep);
-y=csim('step',[],sl);
+y=csim("step",t,ss2tf(sl));
+assert_checkalmostequal(y, yrefstep);
+y=csim("step",t,zpk(sl));
+assert_checkalmostequal(y, yrefstep);
+
+
+y=csim("step",[],sl);
 assert_checkequal(y, []);
-[y1,x]=csim('step',[],sl);
+[y1,x]=csim("step",[],sl);
 assert_checkequal(y1, []);
 assert_checkequal(x, []);
 
-[y1,x]=csim('step',t,sl);
+[y1,x]=csim("step",t,sl);
 assert_checkalmostequal(y1, yrefstep);
 assert_checkalmostequal(x, xrefstep);
 
-y=csim('step',t,sl,0);
+y=csim("step",t,sl,0);
 assert_checkalmostequal(y, yrefstep);
 
-[y1,x]=csim('step',t,sl,0);
+[y1,x]=csim("step",t,sl,0);
 assert_checkalmostequal(y1, yrefstep);
 assert_checkalmostequal(x, xrefstep);
 
-y=csim('step',t,sl,1);
+y=csim("step",t,sl,1);
 assert_checkalmostequal(y, yrefstep);
 
-y=csim('step',t,sl,0,[10*%eps %eps]);
+y=csim("step",t,sl,0,[10*%eps %eps]);
 assert_checkalmostequal(y, yrefstep);
 
-[y1,x]=csim('step',t,sl,1,[10*%eps %eps]);
+[y1,x]=csim("step",t,sl,1,[10*%eps %eps]);
 assert_checkalmostequal(y, yrefstep);
 assert_checkalmostequal(x, xrefstep);
 
@@ -52,42 +58,46 @@ assert_checkalmostequal(x, xrefstep);
 yrefimp=2*ones(1,11);
 xrefimp=ones(1,11);
 
-y=csim('impulse',t,sl);
+y=csim("impulse",t,sl);
+assert_checkalmostequal(y, yrefimp);
+y=csim("impulse",t,ss2tf(sl));
+assert_checkalmostequal(y, yrefimp);
+y=csim("impulse",t,zpk(sl));
 assert_checkalmostequal(y, yrefimp);
 
-y=csim('impulse',[],sl);
+y=csim("impulse",[],sl);
 assert_checkequal(y, []);
 
-[y1,x]=csim('impulse',[],sl);
+[y1,x]=csim("impulse",[],sl);
 assert_checkequal(y1, []);
 assert_checkequal(x, []);
 
 w=ones(t)-eye(t);
-y=csim('impulse',t,sl);
+y=csim("impulse",t,sl);
 assert_checkalmostequal(y, yrefimp);
 
-[y1,x]=csim('impulse',t,sl);
+[y1,x]=csim("impulse",t,sl);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
 
-y=csim('impulse',t,sl,0);
+y=csim("impulse",t,sl,0);
 assert_checkalmostequal(y, yrefimp);
 
-[y1,x]=csim('impulse',t,sl,0);
+[y1,x]=csim("impulse",t,sl,0);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
 
-y=csim('impulse',t,sl,1);
+y=csim("impulse",t,sl,1);
 assert_checkalmostequal(y, yrefimp);
 
-[y1,x]=csim('impulse',t,sl,1);
+[y1,x]=csim("impulse",t,sl,1);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
 
-y=csim('impulse',t,sl,0,[10*%eps %eps]);
+y=csim("impulse",t,sl,0,[10*%eps %eps]);
 assert_checkalmostequal(y, yrefimp);
 
-[y1,x]=csim('impulse',t,sl,1,[10*%eps %eps]);
+[y1,x]=csim("impulse",t,sl,1,[10*%eps %eps]);
 assert_checkalmostequal(y1, yrefimp);
 assert_checkalmostequal(x, xrefimp);
 
@@ -96,6 +106,10 @@ function y=step(t),if t<0 then y=0,else y=1,end,endfunction
 
 y=csim(step,t,sl);
 assert_checkalmostequal(y, yrefstep);
+y=csim(step,t,ss2tf(sl));
+assert_checkalmostequal(y, yrefstep);
+y=csim(step,t,zpk(sl));
+assert_checkalmostequal(y, yrefstep);
 
 y=csim(step,[],sl);
 assert_checkequal(y, []);
index 0f3947a..1b02bf4 100644 (file)
@@ -1,3 +1,4 @@
+//<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 // Copyright (C) 2001 - INRIA - Serge Steer
@@ -32,7 +33,7 @@ R=1;
 assert_checkequal (wn,1);
 assert_checkequal (zeta,-1);
 //Polynomial and Polynomial array
-P=real([poly([2 1+%i 1-%i  2-3*%i 2+3*%i],'s'),poly(0,'s'),poly(1,'s')]);
+P=real([poly([2 1+%i 1-%i  2-3*%i 2+3*%i],"s"),poly(0,"s"),poly(1,"s")]);
 [wn,zeta]=damp(P);
 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
@@ -62,10 +63,10 @@ assert_checkalmostequal (wn,wnref, 0, 1D-14);
 assert_checkalmostequal (zeta(2:$),zetaref(2:$));
 assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
 //transfer function
-[wn,zeta]=damp(syslin('c',ones(1,3),P));
+[wn,zeta]=damp(syslin("c",ones(1,3),P));
 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
-assert_checkalmostequal (wn,wnref, 0, 1D-14);
+assert_checkalmostequal (wn,wnref, 1D-14, 1D-14);
 assert_checkalmostequal (zeta(2:$),zetaref(2:$));
 assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
 dt=1;
@@ -77,8 +78,24 @@ zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/ab
 assert_checkalmostequal (wn,wnref,0, 1D-14);
 assert_checkalmostequal (zeta(2:$),zetaref(2:$));
 assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
+//zpk
+[wn,zeta]=damp(zpk(syslin("c",ones(1,3),P)));
+wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
+zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
+assert_checkalmostequal (wn,wnref, 0, 1D-14);
+assert_checkalmostequal (zeta(2:$),zetaref(2:$));
+assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
+dt=1;
+[wn,zeta]=damp(zpk(syslin(dt,ones(1,3),P)));
+t1=log(1+%i)/dt;
+t2=log(2-3*%i)/dt;
+wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
+zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
+assert_checkalmostequal (wn,wnref,0, 1D-14);
+assert_checkalmostequal (zeta(2:$),zetaref(2:$));
+assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
 //state-space
-[wn,zeta]=damp(tf2ss(syslin('c',1,prod(P))));
+[wn,zeta]=damp(tf2ss(syslin("c",1,prod(P))));
 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
 assert_checkalmostequal (wn,wnref);
index 5c29cf4..67419ce 100644 (file)
@@ -40,7 +40,7 @@ assert_checkequal (wn,1);
 assert_checkequal (zeta,-1);
 
 //Polynomial and Polynomial array
-P=real([poly([2 1+%i 1-%i  2-3*%i 2+3*%i],'s'),poly(0,'s'),poly(1,'s')]);
+P=real([poly([2 1+%i 1-%i  2-3*%i 2+3*%i],"s"),poly(0,"s"),poly(1,"s")]);
 [wn,zeta]=damp(P);
 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
@@ -74,10 +74,10 @@ assert_checkalmostequal (zeta(2:$),zetaref(2:$));
 assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
 
 //transfer function
-[wn,zeta]=damp(syslin('c',ones(1,3),P));
+[wn,zeta]=damp(syslin("c",ones(1,3),P));
 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
-assert_checkalmostequal (wn,wnref, 0, 1D-14);
+assert_checkalmostequal (wn,wnref, 1D-14, 1D-14);
 assert_checkalmostequal (zeta(2:$),zetaref(2:$));
 assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
 
@@ -91,8 +91,27 @@ assert_checkalmostequal (wn,wnref,0, 1D-14);
 assert_checkalmostequal (zeta(2:$),zetaref(2:$));
 assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
 
+//zpk
+[wn,zeta]=damp(zpk(syslin("c",ones(1,3),P)));
+wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
+zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
+assert_checkalmostequal (wn,wnref, 0, 1D-14);
+assert_checkalmostequal (zeta(2:$),zetaref(2:$));
+assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
+
+dt=1;
+[wn,zeta]=damp(zpk(syslin(dt,ones(1,3),P)));
+t1=log(1+%i)/dt;
+t2=log(2-3*%i)/dt;
+wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
+zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
+assert_checkalmostequal (wn,wnref,0, 1D-14);
+assert_checkalmostequal (zeta(2:$),zetaref(2:$));
+assert_checktrue(abs(abs(zeta(1))-1)<100*%eps);
+
+
 //state-space
-[wn,zeta]=damp(tf2ss(syslin('c',1,prod(P))));
+[wn,zeta]=damp(tf2ss(syslin("c",1,prod(P))));
 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
 assert_checkalmostequal (wn,wnref);
index 0271dff..3923271 100644 (file)
@@ -29,10 +29,10 @@ D=[1 -1 -2  0  0
    0  0  1  2  1];
 ncon=2
  ncon  = 
-    2.
+   2.
 nmeas=2
  nmeas  = 
-    2.
+   2.
 gam=111.30;
 [AK,BK,CK,DK] = dhinf(A,B,C,D,ncon,nmeas,gam);
 DK_ref=[9.0643622,7.5621326;
index bb7fe96..637288b 100644 (file)
@@ -9,15 +9,13 @@
 a=-1/3;
 b=1;
 c=1;
-sl=syslin('c',a,b,c);
+sl=syslin("c",a,b,c);
 sld=dscr(sl,0.1);
-assert_checkalmostequal ( sld.dt , 0.1 , %eps , 0);
-computed = sld.A;
-expected = exp(sl.A*0.1);
-assert_checkalmostequal ( computed , expected , %eps , %eps);
-computed = sld.B;
-expected = sl.A\(sld.A-eye())*sl.B;
-assert_checkalmostequal ( computed , expected);
+assert_checkequal ( sld.dt , 0.1);
+assert_checkalmostequal (sld.A ,exp(sl.A*0.1));
+assert_checkalmostequal (sld.B , sl.A\(sld.A-eye())*sl.B );
+assert_checktrue(sld==dscr(zpk(sl),0.1));
+assert_checktrue(sld==dscr(ss2tf(sl),0.1));
 // Case #2
 a=[0.9,0,0.6,-1.4,-4.2;
    0.2,0.1,-0.2,0.5,0.6;
@@ -35,10 +33,8 @@ d=[1,0,0
    0,0,0];
 sl=syslin('c',a,b,c,d);
 sld=dscr(sl,0.1);
-assert_checkalmostequal ( sld.dt , 0.1 , %eps , 0 );
-computed = sld.A;
-expected = expm(sl.A*0.1);
-assert_checkalmostequal ( computed , expected , 1.e3 * %eps );
-computed = sld.B;
-expected = sl.A\(sld.A-eye())*sl.B;
-assert_checkalmostequal ( computed , expected , 2.e5 * %eps );
+assert_checkequal ( sld.dt , 0.1);
+assert_checkalmostequal (sld.A ,expm(sl.A*0.1));
+assert_checkalmostequal (sld.B , sl.A\(sld.A-eye())*sl.B);
+S=zpk({[],1},{-1,[-2 -3]},[1 1],"c");
+assert_checktrue(dscr(zpk2ss(S),0.1)==dscr(S,0.1));
index d2f4c35..5b9676c 100644 (file)
@@ -14,39 +14,37 @@ b=1;
 c=1;
 sl=syslin("c",a,b,c);
 sld=dscr(sl,0.1);
-assert_checkalmostequal ( sld.dt , 0.1 , %eps , 0);
-computed = sld.A;
-expected = exp(sl.A*0.1);
-assert_checkalmostequal ( computed , expected , %eps , %eps);
-computed = sld.B;
-expected = sl.A\(sld.A-eye())*sl.B;
-assert_checkalmostequal ( computed , expected);
+assert_checkequal ( sld.dt , 0.1);
+assert_checkalmostequal (sld.A ,exp(sl.A*0.1));
+assert_checkalmostequal (sld.B , sl.A\(sld.A-eye())*sl.B );
+
+assert_checktrue(sld==dscr(zpk(sl),0.1));
+assert_checktrue(sld==dscr(ss2tf(sl),0.1));
 
 // Case #2
 a=[0.9,0,0.6,-1.4,-4.2;
-0.2,0.1,-0.2,0.5,0.6;
--4.3,0,2.2,0,2.4;
--3.7,-0.5,2.4,-0.6,2.7;
-6.4,0.1,-4,-0.5,-4];
+   0.2,0.1,-0.2,0.5,0.6;
+   -4.3,0,2.2,0,2.4;
+   -3.7,-0.5,2.4,-0.6,2.7;
+   6.4,0.1,-4,-0.5,-4];
 
 b=[-0.1,-0.1,0;
-0,0,0.1;
--0.1,0.2,-0.1;
-0.2,0.2,-0.6;
-0.2,-0.1,0.1];
-
+   0,0,0.1;
+   -0.1,0.2,-0.1;
+   0.2,0.2,-0.6;
+   0.2,-0.1,0.1];
 c=[2,7,-2,5,1
-0,-1,3,0,2];
+   0,-1,3,0,2];
 d=[1,0,0
-0,0,0];
+   0,0,0];
 
-sl=syslin("c",a,b,c,d);
+sl=syslin('c',a,b,c,d);
 sld=dscr(sl,0.1);
-assert_checkalmostequal ( sld.dt , 0.1 , %eps , 0 );
-computed = sld.A;
-expected = expm(sl.A*0.1);
-assert_checkalmostequal ( computed , expected , 1.e3 * %eps );
-computed = sld.B;
-expected = sl.A\(sld.A-eye())*sl.B;
-assert_checkalmostequal ( computed , expected , 2.e5 * %eps );
+assert_checkequal ( sld.dt , 0.1);
+assert_checkalmostequal (sld.A ,expm(sl.A*0.1));
+assert_checkalmostequal (sld.B , sl.A\(sld.A-eye())*sl.B);
+
+S=zpk({[],1},{-1,[-2 -3]},[1 1],"c");
+assert_checktrue(dscr(zpk2ss(S),0.1)==dscr(S,0.1));
 
diff --git a/scilab/modules/cacsd/tests/unit_tests/dscr.tst.orig b/scilab/modules/cacsd/tests/unit_tests/dscr.tst.orig
new file mode 100644 (file)
index 0000000..63543ba
--- /dev/null
@@ -0,0 +1,69 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - 2016 - INRIA - Serge Steer
+// Copyright (C) 2011 - DIGITEO - Michael Baudin
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+
+
+// Case #1
+a=-1/3;
+b=1;
+c=1;
+sl=syslin("c",a,b,c);
+sld=dscr(sl,0.1);
+<<<<<<< 9fd20491ce1d155c147a9e99dd2683f4fabdb16f
+assert_checkalmostequal ( sld.dt , 0.1 , %eps , 0);
+computed = sld.A;
+expected = exp(sl.A*0.1);
+assert_checkalmostequal ( computed , expected , %eps , %eps);
+computed = sld.B;
+expected = sl.A\(sld.A-eye())*sl.B;
+assert_checkalmostequal ( computed , expected);
+=======
+assert_checkequal ( sld.dt , 0.1);
+assert_checkalmostequal (sld.A ,exp(sl.A*0.1));
+assert_checkalmostequal (sld.B , sl.A\(sld.A-eye())*sl.B );
+
+assert_checktrue(sld==dscr(zpk(sl),0.1));
+assert_checktrue(sld==dscr(ss2tf(sl),0.1));
+>>>>>>> missing functions for zpk representation added
+
+// Case #2
+a=[0.9,0,0.6,-1.4,-4.2;
+0.2,0.1,-0.2,0.5,0.6;
+-4.3,0,2.2,0,2.4;
+-3.7,-0.5,2.4,-0.6,2.7;
+6.4,0.1,-4,-0.5,-4];
+
+b=[-0.1,-0.1,0;
+0,0,0.1;
+-0.1,0.2,-0.1;
+0.2,0.2,-0.6;
+0.2,-0.1,0.1];
+
+c=[2,7,-2,5,1
+0,-1,3,0,2];
+d=[1,0,0
+0,0,0];
+
+sl=syslin("c",a,b,c,d);
+sld=dscr(sl,0.1);
+<<<<<<< 9fd20491ce1d155c147a9e99dd2683f4fabdb16f
+assert_checkalmostequal ( sld.dt , 0.1 , %eps , 0 );
+computed = sld.A;
+expected = expm(sl.A*0.1);
+assert_checkalmostequal ( computed , expected , 1.e3 * %eps );
+computed = sld.B;
+expected = sl.A\(sld.A-eye())*sl.B;
+assert_checkalmostequal ( computed , expected , 2.e5 * %eps );
+=======
+assert_checkequal ( sld.dt , 0.1);
+assert_checkalmostequal (sld.A ,expm(sl.A*0.1));
+assert_checkalmostequal (sld.B , sl.A\(sld.A-eye())*sl.B);
+>>>>>>> missing functions for zpk representation added
+
+S=zpk({[],1},{-1,[-2 -3]},[1 1],"c");
+assert_checktrue(dscr(zpk2ss(S),0.1)==dscr(S,0.1));
index 9038c42..50ac24f 100644 (file)
@@ -1,23 +1,32 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 a=0.9;b=1;c=1;
-sl=syslin('d',a,b,c);
+sl=syslin("d",a,b,c);
 h=ss2tf(sl);
 y=flts([1 0 0 0 ],sl);
-if norm(y-[0 a.^(0:2)])>1d-15 then bugmes();quit;end
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+y=flts([1 0 0 0 ],zpk(sl));
+assert_checkalmostequal(y,[0 a.^(0:2)]);
 [y,x]=flts([1 0 0 0 ],sl);
-if norm(y-[0 a.^(0:2)])>1d-15 then bugmes();quit;end
-if abs(x-a^3)>1d-15 then bugmes();quit;end
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+assert_checkalmostequal(x,a^3);
 y=flts([1 0 0 0 ],sl,1);
-if norm(y-([0 a.^(0:2)]+a.^(0:3)))>1d-15 then bugmes();quit;end
+assert_checkalmostequal(y,[0 a.^(0:2)]+a.^(0:3));
 [y,x]=flts([1 0 0 0 ],sl,1);
-if norm(y-([0 a.^(0:2)]+a.^(0:3)))>1d-15 then bugmes();quit;end
-if abs(x-(a^4+a^3))>1d-15 then bugmes();quit;end
+assert_checkalmostequal(y,[0 a.^(0:2)]+a.^(0:3));
+assert_checkalmostequal(x,a^3+a^4);
 y=flts([1 0 0 0 ],h);
-if norm(y-[0 a.^(0:2)])>1d-15 then bugmes();quit;end
-if execstr("[y,x]=flts([1 0 0 0 ],h);","errcatch")==0 then bugmes();quit;end
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+y=flts([1 0 0 0 ],zpk(h));
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+y=flts([1 0 0 0 ],[sl;sl+1]);
+assert_checkalmostequal(y,[0 a.^(0:2);1 a.^(0:2)]);
+y=flts([1 0 0 0 ],[h;h+1]);
+assert_checkalmostequal(y,[0 a.^(0:2);1 a.^(0:2)]);
+y=flts([1 0 0 0 ],zpk([h;h+1]));
+assert_checkalmostequal(y,[0 a.^(0:2);1 a.^(0:2)]);
index 2fb9042..88d9758 100644 (file)
@@ -1,27 +1,41 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 a=0.9;b=1;c=1;
-sl=syslin('d',a,b,c);
+sl=syslin("d",a,b,c);
 h=ss2tf(sl);
 y=flts([1 0 0 0 ],sl);
-if norm(y-[0 a.^(0:2)])>1d-15 then pause,end
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+y=flts([1 0 0 0 ],zpk(sl));
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+
 
 [y,x]=flts([1 0 0 0 ],sl);
-if norm(y-[0 a.^(0:2)])>1d-15 then pause,end
-if abs(x-a^3)>1d-15 then pause,end
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+assert_checkalmostequal(x,a^3);
 
 
 y=flts([1 0 0 0 ],sl,1);
-if norm(y-([0 a.^(0:2)]+a.^(0:3)))>1d-15 then pause,end
+assert_checkalmostequal(y,[0 a.^(0:2)]+a.^(0:3));
+
 [y,x]=flts([1 0 0 0 ],sl,1);
-if norm(y-([0 a.^(0:2)]+a.^(0:3)))>1d-15 then pause,end
-if abs(x-(a^4+a^3))>1d-15 then pause,end
+assert_checkalmostequal(y,[0 a.^(0:2)]+a.^(0:3));
+assert_checkalmostequal(x,a^3+a^4);
 
 y=flts([1 0 0 0 ],h);
-if norm(y-[0 a.^(0:2)])>1d-15 then pause,end
-if execstr("[y,x]=flts([1 0 0 0 ],h);","errcatch")==0 then pause,end
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+
+y=flts([1 0 0 0 ],zpk(h));
+assert_checkalmostequal(y,[0 a.^(0:2)]);
+
+y=flts([1 0 0 0 ],[sl;sl+1]);
+assert_checkalmostequal(y,[0 a.^(0:2);1 a.^(0:2)]);
+
+y=flts([1 0 0 0 ],[h;h+1]);
+assert_checkalmostequal(y,[0 a.^(0:2);1 a.^(0:2)]);
+y=flts([1 0 0 0 ],zpk([h;h+1]));
+assert_checkalmostequal(y,[0 a.^(0:2);1 a.^(0:2)]);
index d295bb0..9bcd043 100644 (file)
@@ -1,51 +1,54 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA Serge Steer
+// Copyright (C) ????-2016 - INRIA Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- TEST WITH GRAPHIC -->
-plots=['bode','black','nyquist','gainplot'];
-s=poly(0,'s');
-h=syslin('c',(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
-h1=h*syslin('c',(s^2+2*0.1*15.1*s+228.01)/(s^2+2*0.9*15*s+225));
+plots=["bode","black","nyquist","gainplot","phaseplot"];
+s=poly(0,"s");
+h=syslin("c",(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
+h1=h*syslin("c",(s^2+2*0.1*15.1*s+228.01)/(s^2+2*0.9*15*s+225));
 hd=dscr(h,0.01);
 hd1=dscr(h1,0.01);
 [frq,repf]=repfreq([h;h1],0.01,100);
 [phi,db]=phasemag(repf);
 Args=list(..
-         list(h),..
-         list(h,0.01,100),..
-         list(h,0.01,100,'h'),..
-         list([h;h1]),..
-         list([h;h1],0.01,100),..
-         list([h;h1],0.01,100,['h';'h1']),..
-         list(hd),..
-         list(hd,0.01,100),..
-         list(hd,0.01,100,'hd'),..
-         list([hd;hd1]),..
-         list([hd;hd1],0.01,100),..
-         list([hd;hd1],0.01,100,['hd';'hd1']),..
-         list(frq,repf(1,:)),..
-         list(frq,repf(1,:),'h'),..
-         list(frq,repf),..
-         list(frq,repf,['h';'h1']),..
-         list([frq;frq],repf,['h';'h1']),..
-         list(frq,db(1,:),phi(1,:)),..
-         list(frq,db(1,:),phi(1,:),'h'),..
-         list(frq,db,phi),..
-         list(frq,db,phi,['h';'h1']),..
-         list([frq;frq],db,phi,['h';'h1']));
-warning('off');
+list(h),..
+list(h,0.01,100),..
+list(h,0.01,100,"h"),..
+list([h;h1]),..
+list([h;h1],0.01,100),..
+list([h;h1],0.01,100,["h";"h1"]),..
+list(zpk([h;h1]),0.01,100,["h";"h1"]),..
+list(hd),..
+list(hd,0.01,100),..
+list(hd,0.01,100,"hd"),..
+list([hd;hd1]),..
+list([hd;hd1],0.01,100),..
+list([hd;hd1],0.01,100,["hd";"hd1"]),..
+list(zpk([hd;hd1]),0.01,100,["hd";"hd1"]),..
+list(frq,repf(1,:)),..
+list(frq,repf(1,:),"h"),..
+list(frq,repf),..
+list(frq,repf,["h";"h1"]),..
+list([frq;frq],repf,["h";"h1"]),..
+list(frq,db(1,:),phi(1,:)),..
+list(frq,db(1,:),phi(1,:),"h"),..
+list(frq,db,phi),..
+list(frq,db,phi,["h";"h1"]),..
+list([frq;frq],db,phi,["h";"h1"]));
+warning("off");
 for p=plots
-  mprintf("-------- %s ---------------\n",p)
-  for args=Args
-    clf()   
-    if execstr(p+'(args(:))','errcatch')<>0 then bugmes();quit;end
-  end
+    mprintf("-------- %s ---------------\n",p)
+    for args=Args
+        clf()
+        assert_checktrue(execstr(p+"(args(:))","errcatch")==0);
+    end
 end
 -------- bode ---------------
 -------- black ---------------
 -------- nyquist ---------------
 -------- gainplot ---------------
-warning('on');
+-------- phaseplot ---------------
+warning("on");
index 41fc2bb..68777af 100644 (file)
@@ -1,50 +1,52 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2008 - INRIA Serge Steer
+// Copyright (C) ????-2016 - INRIA Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- TEST WITH GRAPHIC -->
 
-plots=['bode','black','nyquist','gainplot'];
-s=poly(0,'s');
-h=syslin('c',(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
-h1=h*syslin('c',(s^2+2*0.1*15.1*s+228.01)/(s^2+2*0.9*15*s+225));
+plots=["bode","black","nyquist","gainplot","phaseplot"];
+s=poly(0,"s");
+h=syslin("c",(s^2+2*0.9*10*s+100)/(s^2+2*0.3*10.1*s+102.01));
+h1=h*syslin("c",(s^2+2*0.1*15.1*s+228.01)/(s^2+2*0.9*15*s+225));
 hd=dscr(h,0.01);
 hd1=dscr(h1,0.01);
 [frq,repf]=repfreq([h;h1],0.01,100);
 [phi,db]=phasemag(repf);
 
 Args=list(..
-         list(h),..
-         list(h,0.01,100),..
-         list(h,0.01,100,'h'),..
-         list([h;h1]),..
-         list([h;h1],0.01,100),..
-         list([h;h1],0.01,100,['h';'h1']),..
-         list(hd),..
-         list(hd,0.01,100),..
-         list(hd,0.01,100,'hd'),..
-         list([hd;hd1]),..
-         list([hd;hd1],0.01,100),..
-         list([hd;hd1],0.01,100,['hd';'hd1']),..
-         list(frq,repf(1,:)),..
-         list(frq,repf(1,:),'h'),..
-         list(frq,repf),..
-         list(frq,repf,['h';'h1']),..
-         list([frq;frq],repf,['h';'h1']),..
-         list(frq,db(1,:),phi(1,:)),..
-         list(frq,db(1,:),phi(1,:),'h'),..
-         list(frq,db,phi),..
-         list(frq,db,phi,['h';'h1']),..
-         list([frq;frq],db,phi,['h';'h1']));
+list(h),..
+list(h,0.01,100),..
+list(h,0.01,100,"h"),..
+list([h;h1]),..
+list([h;h1],0.01,100),..
+list([h;h1],0.01,100,["h";"h1"]),..
+list(zpk([h;h1]),0.01,100,["h";"h1"]),..
+list(hd),..
+list(hd,0.01,100),..
+list(hd,0.01,100,"hd"),..
+list([hd;hd1]),..
+list([hd;hd1],0.01,100),..
+list([hd;hd1],0.01,100,["hd";"hd1"]),..
+list(zpk([hd;hd1]),0.01,100,["hd";"hd1"]),..
+list(frq,repf(1,:)),..
+list(frq,repf(1,:),"h"),..
+list(frq,repf),..
+list(frq,repf,["h";"h1"]),..
+list([frq;frq],repf,["h";"h1"]),..
+list(frq,db(1,:),phi(1,:)),..
+list(frq,db(1,:),phi(1,:),"h"),..
+list(frq,db,phi),..
+list(frq,db,phi,["h";"h1"]),..
+list([frq;frq],db,phi,["h";"h1"]));
 
-warning('off');          
+warning("off");
 for p=plots
-  mprintf("-------- %s ---------------\n",p)
-  for args=Args
-    clf()   
-    if execstr(p+'(args(:))','errcatch')<>0 then pause,end
-  end
+    mprintf("-------- %s ---------------\n",p)
+    for args=Args
+        clf()
+        assert_checktrue(execstr(p+"(args(:))","errcatch")==0);
+    end
 end
-warning('on');   
\ No newline at end of file
+warning("on");
diff --git a/scilab/modules/cacsd/tests/unit_tests/freson.dia.ref b/scilab/modules/cacsd/tests/unit_tests/freson.dia.ref
new file mode 100644 (file)
index 0000000..5f73ae1
--- /dev/null
@@ -0,0 +1,13 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2010 - 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+h=syslin("c",-1+%s,(3+2*%s+%s^2)*(50+0.1*%s+%s^2));
+fr=freson(h);
+assert_checkalmostequal(fr,[0.26162097704;1.12527981797]);
+hd=dscr(h,0.05);
+fr=freson(hd);
+assert_checkalmostequal(fr,[0.26155702493;1.12527923264]);
diff --git a/scilab/modules/cacsd/tests/unit_tests/freson.tst b/scilab/modules/cacsd/tests/unit_tests/freson.tst
new file mode 100644 (file)
index 0000000..4671821
--- /dev/null
@@ -0,0 +1,15 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2010 - 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+h=syslin("c",-1+%s,(3+2*%s+%s^2)*(50+0.1*%s+%s^2));
+fr=freson(h);
+assert_checkalmostequal(fr,[0.26162097704;1.12527981797]);
+
+
+hd=dscr(h,0.05);
+fr=freson(hd);
+assert_checkalmostequal(fr,[0.26155702493;1.12527923264]);
index 8616a7c..36e299a 100644 (file)
@@ -1,7 +1,7 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2010 - INRIA - Serge Steer
+// Copyright (C) 2010 - 2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
@@ -35,19 +35,27 @@ z=poly(0,"z");
 h = syslin(0.1,((29/625)+(2399/50000)*z)/((1131/1250)+(-181/100)*z+z^2));
 f_ref=atan(sqrt(9003479136639)/4963519)/(0.1*2*%pi);
 g_ref=6.242379356591869534116;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 h=syslin(0.1,((43/500)+(-161/1000)*z+(39/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 f_ref=atan((1/215)*sqrt(1136805-8330*sqrt(5970))/(833/43+(1/215)*sqrt(5970)))/(0.1*2*%pi);
 g_ref=12.3470513198103944037870;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 h=syslin(0.1,((129/500)+(-483/1000)*z+(117/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 f_ref=atan((1/215)*sqrt(1136805-8330*sqrt(5970))/(833/43+(1/215)*sqrt(5970)))/(0.1*2*%pi);
 g_ref=2.8046262254171456578864840;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 h=syslin(1,((21/500)+(-3933/100000)*z+(-15407/100000)*z^2+(9259/50000)*z^3+(6939/(10^12))*z^4)/((-21/500)+(11/125)*z+(57/500)*z^2+(-9/25)*z^3+(1/5)*z^4));
 f_ref=1/2;
 g_ref=6.48227782514616029706190;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 //continuous time case
 s=poly(0,"s");
 //the reference solutions are computed using  the following Maple instructions
@@ -60,19 +68,25 @@ s=poly(0,"s");
 h=syslin("c",(-1+s)/(3+2*s+s^2));
 f_ref=0;
 g_ref=9.5424250943932487459005580;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 h = syslin("c",((1/5)+(4/5)*s+(0/1)*s^2+(3/10)*s^3)/((409/10000)+(1827/10000)*s+(5129/4000)*s^2+(31909/10000)*s^3+(64/25)*s^4 +s^5));
 f_ref=0.0714555258202006740373134;
 g_ref=-4.91687406933815400242335;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 h=syslin("c",485000/(10000*s+200*s^2+s^3));
 f_ref=100/(2*%pi);
 g_ref=12.305765141234350772862319;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
 h = syslin("c",1/(s+2*s^2+s^3));
 f_ref=1/(2*%pi);
 g_ref=6.0205999132796239042747779;
-if ~check_gmargin(h,f_ref,g_ref) then bugmes();quit;end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 //phase margin
 //-----------
 function ok=check_pmargin(h,f_ref,p_ref)
@@ -98,16 +112,20 @@ endfunction
 h = syslin(0.1,((29/625)+(2399/50000)*z)/((1131/1250)+(-181/100)*z+z^2));
 f_ref=0.693016600315284442350578876;
 p_ref=13.57115563612946355428439468;
-if  ~check_pmargin(h,f_ref,p_ref) then bugmes();quit;end
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
 h=syslin(0.1,((43/500)+(-161/1000)*z+(39/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 [p ,f]=p_margin(h);
-if p<>%inf  then bugmes();quit;end
-if f<>[]  then bugmes();quit;end
+assert_checktrue(p==%inf);
+assert_checktrue(f==[]);
 h=syslin(0.1,3*(0.086-0.161*%z+0.078*%z^2),-0.67+2.286*%z-2.61*%z^2+%z^3);
 h=syslin(0.1,((129/500)+(-483/1000)*z+(117/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 f_ref=0.212336488950669705771059018;
 p_ref=52.94967415965772478856630911;
-if  ~check_pmargin(h,f_ref,p_ref) then bugmes();quit;end
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
 //continuous case
 //the reference solutions are computed using  the following Maple instructions
 //z:=I*w:
@@ -117,8 +135,12 @@ if  ~check_pmargin(h,f_ref,p_ref) then bugmes();quit;end
 h=syslin("c",((11/10)+(12/5)*s+(7/10)*s^2)/(3+2*s+s^2));
 f_ref=(1/51)*sqrt(15861-204*sqrt(3562))/(2*%pi);
 p_ref=-148.547076202317410601324666;
-if  ~check_pmargin(h,f_ref,p_ref) then bugmes();quit;end
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
 h = syslin("c",((1/5)+(4/5)*s+(3/10)*s^3)/((409/10000)+(1827/10000)*s+(5129/4000)*s^2+(31909/10000)*s^3+(64/25)*s^4+s^5));
 f_ref=0.09144216563554157543991;
 p_ref=-13.1128497150069802772313;
-if  ~check_pmargin(h,f_ref,p_ref) then bugmes();quit;end
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
index 5b59864..72fff10 100644 (file)
@@ -1,7 +1,7 @@
 //<-- CLI SHELL MODE -->
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2010 - INRIA - Serge Steer
+// Copyright (C) 2010 - 2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
@@ -39,25 +39,34 @@ z=poly(0,"z");
 h = syslin(0.1,((29/625)+(2399/50000)*z)/((1131/1250)+(-181/100)*z+z^2));
 f_ref=atan(sqrt(9003479136639)/4963519)/(0.1*2*%pi);
 g_ref=6.242379356591869534116;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
-
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 
 
 h=syslin(0.1,((43/500)+(-161/1000)*z+(39/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 f_ref=atan((1/215)*sqrt(1136805-8330*sqrt(5970))/(833/43+(1/215)*sqrt(5970)))/(0.1*2*%pi);
 g_ref=12.3470513198103944037870;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
+
 
 h=syslin(0.1,((129/500)+(-483/1000)*z+(117/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 f_ref=atan((1/215)*sqrt(1136805-8330*sqrt(5970))/(833/43+(1/215)*sqrt(5970)))/(0.1*2*%pi);
 g_ref=2.8046262254171456578864840;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
+
 
 
 h=syslin(1,((21/500)+(-3933/100000)*z+(-15407/100000)*z^2+(9259/50000)*z^3+(6939/(10^12))*z^4)/((-21/500)+(11/125)*z+(57/500)*z^2+(-9/25)*z^3+(1/5)*z^4));
 f_ref=1/2;
 g_ref=6.48227782514616029706190;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 
 //continuous time case
 s=poly(0,"s");
@@ -72,25 +81,31 @@ s=poly(0,"s");
 h=syslin("c",(-1+s)/(3+2*s+s^2));
 f_ref=0;
 g_ref=9.5424250943932487459005580;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 
 
 h = syslin("c",((1/5)+(4/5)*s+(0/1)*s^2+(3/10)*s^3)/((409/10000)+(1827/10000)*s+(5129/4000)*s^2+(31909/10000)*s^3+(64/25)*s^4 +s^5));
 f_ref=0.0714555258202006740373134;
 g_ref=-4.91687406933815400242335;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 
 
 h=syslin("c",485000/(10000*s+200*s^2+s^3));
 f_ref=100/(2*%pi);
 g_ref=12.305765141234350772862319;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
 
 
 h = syslin("c",1/(s+2*s^2+s^3));
 f_ref=1/(2*%pi);
 g_ref=6.0205999132796239042747779;
-if ~check_gmargin(h,f_ref,g_ref) then pause,end
+assert_checktrue(check_gmargin(h,f_ref,g_ref));
+assert_checktrue(check_gmargin(tf2ss(h),f_ref,g_ref));
+assert_checktrue(check_gmargin(zpk(h),f_ref,g_ref));
 
 //phase margin
 //-----------
@@ -119,19 +134,23 @@ endfunction
 h = syslin(0.1,((29/625)+(2399/50000)*z)/((1131/1250)+(-181/100)*z+z^2));
 f_ref=0.693016600315284442350578876;
 p_ref=13.57115563612946355428439468;
-if  ~check_pmargin(h,f_ref,p_ref) then pause,end
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
 
 
 h=syslin(0.1,((43/500)+(-161/1000)*z+(39/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 [p ,f]=p_margin(h);
-if p<>%inf  then pause,end
-if f<>[]  then pause,end
+assert_checktrue(p==%inf);
+assert_checktrue(f==[]);
 
 h=syslin(0.1,3*(0.086-0.161*%z+0.078*%z^2),-0.67+2.286*%z-2.61*%z^2+%z^3);
 h=syslin(0.1,((129/500)+(-483/1000)*z+(117/500)*z^2)/((-67/100)+(1143/500)*z+(-261/100)*z^2+z^3));
 f_ref=0.212336488950669705771059018;
 p_ref=52.94967415965772478856630911;
-if  ~check_pmargin(h,f_ref,p_ref) then pause,end
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
 
 //continuous case
 //the reference solutions are computed using  the following Maple instructions
@@ -143,10 +162,13 @@ if  ~check_pmargin(h,f_ref,p_ref) then pause,end
 h=syslin("c",((11/10)+(12/5)*s+(7/10)*s^2)/(3+2*s+s^2));
 f_ref=(1/51)*sqrt(15861-204*sqrt(3562))/(2*%pi);
 p_ref=-148.547076202317410601324666;
-if  ~check_pmargin(h,f_ref,p_ref) then pause,end
-
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
 
 h = syslin("c",((1/5)+(4/5)*s+(3/10)*s^3)/((409/10000)+(1827/10000)*s+(5129/4000)*s^2+(31909/10000)*s^3+(64/25)*s^4+s^5));
 f_ref=0.09144216563554157543991;
 p_ref=-13.1128497150069802772313;
-if  ~check_pmargin(h,f_ref,p_ref) then pause,end
+assert_checktrue(check_pmargin(h,f_ref,p_ref));
+assert_checktrue(check_pmargin(tf2ss(h),f_ref,p_ref));
+assert_checktrue(check_pmargin(zpk(h),f_ref,p_ref));
index 2e6e1b5..b9f9c78 100644 (file)
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2010 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 // <-- TEST WITH GRAPHIC -->
 // <-- ENGLISH IMPOSED -->
+old=driver("null");
 function r=checknyquist(Args,leg)
-  if size(Args)==1 then Args($+1)=1d-3; Args($+1)=1d+3;end
-  [frq,rf,splitf]=repfreq(Args(:));repi=imag(rf);repf=real(rf);
-  [mn,n]=size(rf);
-  splitf($+1)=n+1;
-  ksplit=1;sel=splitf(ksplit):splitf(ksplit+1)-1;
-  R=[repf(:,sel)];  I=[repi(:,sel)];
-  for ksplit=2:size(splitf,'*')-1
-    sel=splitf(ksplit):splitf(ksplit+1)-1
-    R=[R %nan(ones(mn,1)) repf(:,sel)];
-    I=[I %nan(ones(mn,1)) repi(:,sel)];
-  end
-  //use symetry
-  R=[R R(:,$:-1:1)];
-  I=[I -I(:,$:-1:1)];
-  l=find(~isnan(R(1,:)))
-  fig=gcf();
-  r=0
-  a=fig.children;
-  if a.log_flags<>'nnn' then r=1;return,end
-  if or(a.axes_visible<>["on","on","on"]) then r=2;return,end
-  n=size(Args(1),1)
-  n1=size(a.children,'*')
-  if (argn(2)==1&(n<>n1))|(argn(2)==2&(n+1<>n1)) then r=3;return,end
-  for k=1:n;
-    if a.children($+1-k).type<>'Compound' then r=4;return,end
-    if size(a.children($+1-k).children,'*')<>2  then r=5;return,end
-    if a.children($+1-k).children(1).type<>'Compound'  then r=6;return, end
-    if a.children($+1-k).children(2).type<>'Polyline'  then r=7;return, end
-    if %f then //temporarily removed for 5.0
-      if a.children($+1-k).children(1).children(1).type<>'Segs' then r=8;return, end
-      ns=size(a.children($+1-k).children(1).children(1).data,1);
-      if size(a.children($+1-k).children(1).children,'*')-2<>(ns/2) then r=9;return, end
-      if or(a.children($+1-k).children(1).children(2:$).type<>'Text') then r=10;return, end
+    if size(Args)==1 then Args($+1)=1d-3; Args($+1)=1d+3;end
+    [frq,rf,splitf]=repfreq(Args(:));repi=imag(rf);repf=real(rf);
+    [mn,n]=size(rf);
+    splitf($+1)=n+1;
+    ksplit=1;sel=splitf(ksplit):splitf(ksplit+1)-1;
+    R=[repf(:,sel)];  I=[repi(:,sel)];
+    for ksplit=2:size(splitf,"*")-1
+        sel=splitf(ksplit):splitf(ksplit+1)-1
+        R=[R %nan(ones(mn,1)) repf(:,sel)];
+        I=[I %nan(ones(mn,1)) repi(:,sel)];
+    end
+    //use symetry
+    R=[R R(:,$:-1:1)];
+    I=[I -I(:,$:-1:1)];
+    l=find(~isnan(R(1,:)))
+    fig=gcf();
+    r=0
+    a=fig.children;
+    if a.log_flags<>"nnn" then r=1;return,end
+    if or(a.axes_visible<>["on","on","on"]) then r=2;return,end
+    n=size(Args(1),1)
+    n1=size(a.children,"*")
+    if (argn(2)==1&(n<>n1))|(argn(2)==2&(n+1<>n1)) then r=3;return,end
+    for k=1:n;
+        if a.children($+1-k).type<>"Compound" then r=4;return,end
+        if size(a.children($+1-k).children,"*")<>2  then r=5;return,end
+        if a.children($+1-k).children(1).type<>"Compound"  then r=6;return, end
+        if a.children($+1-k).children(2).type<>"Polyline"  then r=7;return, end
+        if %f then //temporarily removed for 5.0
+            if a.children($+1-k).children(1).children(1).type<>"Segs" then r=8;return, end
+            ns=size(a.children($+1-k).children(1).children(1).data,1);
+            if size(a.children($+1-k).children(1).children,"*")-2<>(ns/2) then r=9;return, end
+            if or(a.children($+1-k).children(1).children(2:$).type<>"Text") then r=10;return, end
+        end
+        if or(l<>find(~isnan(a.children($+1-k).children(2).data(:,1)))) then r=11;return, end
+        if norm(a.children($+1-k).children(2).data(l,:)-[R(k,l)' I(k,l)'])> 1d-14 then r=12;return, end
+        s= a.children($+1-k).children(1).children(1);
+    end
+    if argn(2)==2 then //test the legend
+        if size(a.children,"*")<=n then r=13;return,end
+        if a.children(1).type<>"Legend" then r=14;return,end
+        if size(a.children(1).links,"*")<>n then r=15;return,end
+        if or(a.children(1).text<>leg(:)) then r=16;return,end
     end
-    if or(l<>find(~isnan(a.children($+1-k).children(2).data(:,1)))) then r=11;return, end
-    if norm(a.children($+1-k).children(2).data(l,:)-[R(k,l)' I(k,l)'])> 1d-14 then r=12;return, end
-    s= a.children($+1-k).children(1).children(1);
-  end
-  if argn(2)==2 then //test the legend
-    if size(a.children,'*')<=n then r=13;return,end
-    if a.children(1).type<>'Legend' then r=14;return,end
-    if size(a.children(1).links,'*')<>n then r=15;return,end
-    if or(a.children(1).text<>leg(:)) then r=16;return,end
-  end
 endfunction
-s=poly(0,'s');
+s=poly(0,"s");
 n=1+s;d=1+2*s;
-h=syslin('c',n,d);
+h=syslin("c",n,d);
 sl=tf2ss(h);
 sld=dscr(sl,0.01);
 hd=ss2tf(sld);
 [w,rf]=repfreq(h,0.01,100);
 //continuous time
 clf();nyquist(h);
-if checknyquist(list(h)) then bugmes();quit;end
-clf();nyquist(h,'h');
-if checknyquist(list(h),'h') then bugmes();quit;end
+assert_checktrue(checknyquist(list(h))==0);
+clf();nyquist(h,"h");
+assert_checktrue(checknyquist(list(h),"h")==0);
 clf();nyquist(h,0.01,100);
-if checknyquist(list(h,0.01,100)) then bugmes();quit;end
-clf();nyquist(h,0.01,100,'h');
-if checknyquist(list(h,0.01,100),'h') then bugmes();quit;end
+assert_checktrue(checknyquist(list(h,0.01,100))==0);
+clf();nyquist(h,0.01,100,"h");
+assert_checktrue(checknyquist(list(h,0.01,100),"h")==0);
 clf();nyquist(h,0.01,100,0.01)
-if checknyquist(list(h,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(h,0.01,100,0.01))==0);
 clf();nyquist(sl,0.01,100);
-if checknyquist(list(sl,0.01,100)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sl,0.01,100))==0);
 clf();nyquist(sl,0.01,100,0.01)
-if checknyquist(list(sl,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sl,0.01,100,0.01))==0);
 //continuous time SIMO
 h=[h;h+1];sl=[sl;sl+1];
 clf();nyquist(h);
-if checknyquist(list(h)) then bugmes();quit;end
-clf();nyquist(h,['h';'h+1']);
-if checknyquist(list(h),['h';'h+1']) then bugmes();quit;end
+assert_checktrue(checknyquist(list(h))==0);
+clf();nyquist(h,["h";"h+1"]);
+assert_checktrue(checknyquist(list(h),["h";"h+1"])==0);
+clf();nyquist(zpk(h),["h";"h+1"]);
+assert_checktrue(checknyquist(list(zpk(h)),["h";"h+1"])==0);
 clf();nyquist(h,0.01,100);
-if checknyquist(list(h,0.01,100)) then bugmes();quit;end
-clf();nyquist(h,0.01,100,['h';'h+1']);
-if checknyquist(list(h,0.01,100),['h';'h+1']) then bugmes();quit;end
+assert_checktrue(checknyquist(list(h,0.01,100))==0);
+clf();nyquist(zpk(h),0.01,100);
+assert_checktrue(checknyquist(list(zpk(h),0.01,100))==0);
+clf();nyquist(h,0.01,100,["h";"h+1"]);
+assert_checktrue(checknyquist(list(h,0.01,100),["h";"h+1"])==0);
 clf();nyquist(h,0.01,100,0.01)
-if checknyquist(list(h,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(h,0.01,100,0.01))==0);
 clf();nyquist(sl,0.01,100);
-if checknyquist(list(sl,0.01,100)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sl,0.01,100))==0);
 clf();nyquist(sl,0.01,100,0.01)
-if checknyquist(list(sl,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sl,0.01,100,0.01))==0);
 //discrete case
 clf();nyquist(hd);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd))==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-clf();nyquist(hd,'h');
+clf();nyquist(hd,"h");
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd),'h') then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd),"h")==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
 clf();nyquist(hd,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd,0.01,100)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd,0.01,100))==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-clf();nyquist(hd,0.01,100,'h');
+clf();nyquist(hd,0.01,100,"h");
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd,0.01,100),'h') then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd,0.01,100),"h")==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
 clf();nyquist(hd,0.01,100,0.01)
-if checknyquist(list(hd,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd,0.01,100,0.01))==0);
 clf();nyquist(sld,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(sld,0.01,100)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sld,0.01,100))==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
 clf();nyquist(sld,0.01,100,0.01)
-if checknyquist(list(sld,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sld,0.01,100,0.01))==0);
 //discrete case SIMO
 hd=[hd;hd+1];sld=[sld;sld+1];
 clf();nyquist(hd);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd))==0);
+WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
+clf();nyquist(zpk(hd));
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-clf();nyquist(hd,['h';'h+1']);
+assert_checktrue(checknyquist(list(zpk(hd)))==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd),['h';'h+1']) then bugmes();quit;end
+clf();nyquist(hd,["h";"h+1"]);
+WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
+assert_checktrue(checknyquist(list(hd),["h";"h+1"])==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
 clf();nyquist(hd,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd,0.01,100)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd,0.01,100))==0);
+WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
+clf();nyquist(hd,0.01,100,["h";"h+1"]);
+WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
+assert_checktrue(checknyquist(list(hd,0.01,100),["h";"h+1"])==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-clf();nyquist(hd,0.01,100,['h';'h+1']);
+clf();nyquist(zpk(hd),0.01,100,["h";"h+1"]);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(hd,0.01,100),['h';'h+1']) then bugmes();quit;end
+assert_checktrue(checknyquist(list(zpk(hd),0.01,100),["h";"h+1"])==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
 clf();nyquist(hd,0.01,100,0.01)
-if checknyquist(list(hd,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(hd,0.01,100,0.01))==0);
 clf();nyquist(sld,0.01,100);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
-if checknyquist(list(sld,0.01,100)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sld,0.01,100))==0);
 WARNING: calfrq: Frequencies beyond Nyquist frequency are ignored.
 clf();nyquist(sld,0.01,100,0.01)
-if checknyquist(list(sld,0.01,100,0.01)) then bugmes();quit;end
+assert_checktrue(checknyquist(list(sld,0.01,100,0.01))==0);
 //nyquist given by precmputed freqency response
 clf(); nyquist(w,rf)
 clf(); nyquist(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)))
 // check legend color
 clf();
-F1=syslin('c',(2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
-F2=syslin('c',(0.88*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
-F3=syslin('c',(100*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
+F1=syslin("c",(2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
+F2=syslin("c",(0.88*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
+F3=syslin("c",(100*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
 nyquist ([F1;F2;F3],0.0 ,1000,["F1(Kr=1)";"F2(Kr=0,88)";"F3(Kr=10)"],%f)
 a=gca();
 assert_checkequal(a.children(1).links.foreground, [3, 2, 1]); // [green blue black]
+driver(old);
index 5da9571..1f17823 100644 (file)
@@ -1,68 +1,68 @@
 // =============================================================================
 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) ????-2010 - INRIA - Serge Steer
+// Copyright (C) ????-2016 - INRIA - Serge Steer
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
 
 // <-- TEST WITH GRAPHIC -->
 // <-- ENGLISH IMPOSED -->
-
+old=driver("null");
 function r=checknyquist(Args,leg)
-  if size(Args)==1 then Args($+1)=1d-3; Args($+1)=1d+3;end
-  [frq,rf,splitf]=repfreq(Args(:));repi=imag(rf);repf=real(rf);
-  [mn,n]=size(rf);
-  splitf($+1)=n+1;
-
-  ksplit=1;sel=splitf(ksplit):splitf(ksplit+1)-1;
-  R=[repf(:,sel)];  I=[repi(:,sel)];
-  for ksplit=2:size(splitf,'*')-1
-    sel=splitf(ksplit):splitf(ksplit+1)-1
-    R=[R %nan(ones(mn,1)) repf(:,sel)];
-    I=[I %nan(ones(mn,1)) repi(:,sel)];
-  end
-  //use symetry
-  R=[R R(:,$:-1:1)];
-  I=[I -I(:,$:-1:1)];
-
-  l=find(~isnan(R(1,:)))
-  fig=gcf();
-  r=0
-  a=fig.children;
-
-  if a.log_flags<>'nnn' then r=1;return,end
-  if or(a.axes_visible<>["on","on","on"]) then r=2;return,end
-
-  n=size(Args(1),1)
-  n1=size(a.children,'*')
-  if (argn(2)==1&(n<>n1))|(argn(2)==2&(n+1<>n1)) then r=3;return,end
-  for k=1:n;
-    if a.children($+1-k).type<>'Compound' then r=4;return,end
-    if size(a.children($+1-k).children,'*')<>2  then r=5;return,end
-    if a.children($+1-k).children(1).type<>'Compound'  then r=6;return, end
-    if a.children($+1-k).children(2).type<>'Polyline'  then r=7;return, end
-    if %f then //temporarily removed for 5.0
-      if a.children($+1-k).children(1).children(1).type<>'Segs' then r=8;return, end
-      ns=size(a.children($+1-k).children(1).children(1).data,1);
-      if size(a.children($+1-k).children(1).children,'*')-2<>(ns/2) then r=9;return, end
-      if or(a.children($+1-k).children(1).children(2:$).type<>'Text') then r=10;return, end
+    if size(Args)==1 then Args($+1)=1d-3; Args($+1)=1d+3;end
+    [frq,rf,splitf]=repfreq(Args(:));repi=imag(rf);repf=real(rf);
+    [mn,n]=size(rf);
+    splitf($+1)=n+1;
+
+    ksplit=1;sel=splitf(ksplit):splitf(ksplit+1)-1;
+    R=[repf(:,sel)];  I=[repi(:,sel)];
+    for ksplit=2:size(splitf,"*")-1
+        sel=splitf(ksplit):splitf(ksplit+1)-1
+        R=[R %nan(ones(mn,1)) repf(:,sel)];
+        I=[I %nan(ones(mn,1)) repi(:,sel)];
+    end
+    //use symetry
+    R=[R R(:,$:-1:1)];
+    I=[I -I(:,$:-1:1)];
+
+    l=find(~isnan(R(1,:)))
+    fig=gcf();
+    r=0
+    a=fig.children;
+
+    if a.log_flags<>"nnn" then r=1;return,end
+    if or(a.axes_visible<>["on","on","on"]) then r=2;return,end
+
+    n=size(Args(1),1)
+    n1=size(a.children,"*")
+    if (argn(2)==1&(n<>n1))|(argn(2)==2&(n+1<>n1)) then r=3;return,end
+    for k=1:n;
+        if a.children($+1-k).type<>"Compound" then r=4;return,end
+        if size(a.children($+1-k).children,"*")<>2  then r=5;return,end
+        if a.children($+1-k).children(1).type<>"Compound"  then r=6;return, end
+        if a.children($+1-k).children(2).type<>"Polyline"  then r=7;return, end
+        if %f then //temporarily removed for 5.0
+            if a.children($+1-k).children(1).children(1).type<>"Segs" then r=8;return, end
+            ns=size(a.children($+1-k).children(1).children(1).data,1);
+            if size(a.children($+1-k).children(1).children,"*")-2<>(ns/2) then r=9;return, end
+            if or(a.children($+1-k).children(1).children(2:$).type<>"Text") then r=10;return, end
+        end
+        if or(l<>find(~isnan(a.children($+1-k).children(2).data(:,1)))) then r=11;return, end
+        if norm(a.children($+1-k).children(2).data(l,:)-[R(k,l)' I(k,l)'])> 1d-14 then r=12;return, end
+        s= a.children($+1-k).children(1).children(1);
+    end
+    if argn(2)==2 then //test the legend
+        if size(a.children,"*")<=n then r=13;return,end
+        if a.children(1).type<>"Legend" then r=14;return,end
+        if size(a.children(1).links,"*")<>n then r=15;return,end
+        if or(a.children(1).text<>leg(:)) then r=16;return,end
     end
-    if or(l<>find(~isnan(a.children($+1-k).children(2).data(:,1)))) then r=11;return, end
-    if norm(a.children($+1-k).children(2).data(l,:)-[R(k,l)' I(k,l)'])> 1d-14 then r=12;return, end
-    s= a.children($+1-k).children(1).children(1);
-  end
-  if argn(2)==2 then //test the legend
-    if size(a.children,'*')<=n then r=13;return,end
-    if a.children(1).type<>'Legend' then r=14;return,end
-    if size(a.children(1).links,'*')<>n then r=15;return,end
-    if or(a.children(1).text<>leg(:)) then r=16;return,end
-  end
 endfunction
 
 
-s=poly(0,'s');
+s=poly(0,"s");
 n=1+s;d=1+2*s;
-h=syslin('c',n,d);
+h=syslin("c",n,d);
 sl=tf2ss(h);
 sld=dscr(sl,0.01);
 hd=ss2tf(sld);
@@ -71,77 +71,87 @@ hd=ss2tf(sld);
 
 //continuous time
 clf();nyquist(h);
-if checknyquist(list(h)) then pause,end
-clf();nyquist(h,'h');
-if checknyquist(list(h),'h') then pause,end
+assert_checktrue(checknyquist(list(h))==0);
+clf();nyquist(h,"h");
+assert_checktrue(checknyquist(list(h),"h")==0);
 
 clf();nyquist(h,0.01,100);
-if checknyquist(list(h,0.01,100)) then pause,end
-clf();nyquist(h,0.01,100,'h');
-if checknyquist(list(h,0.01,100),'h') then pause,end
+assert_checktrue(checknyquist(list(h,0.01,100))==0);
+clf();nyquist(h,0.01,100,"h");
+assert_checktrue(checknyquist(list(h,0.01,100),"h")==0);
 
 clf();nyquist(h,0.01,100,0.01)
-if checknyquist(list(h,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(h,0.01,100,0.01))==0);
 clf();nyquist(sl,0.01,100);
-if checknyquist(list(sl,0.01,100)) then pause,end
+assert_checktrue(checknyquist(list(sl,0.01,100))==0);
 clf();nyquist(sl,0.01,100,0.01)
-if checknyquist(list(sl,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(sl,0.01,100,0.01))==0);
 
 //continuous time SIMO
 h=[h;h+1];sl=[sl;sl+1];
 clf();nyquist(h);
-if checknyquist(list(h)) then pause,end
-clf();nyquist(h,['h';'h+1']);
-if checknyquist(list(h),['h';'h+1']) then pause,end
+assert_checktrue(checknyquist(list(h))==0);
+clf();nyquist(h,["h";"h+1"]);
+assert_checktrue(checknyquist(list(h),["h";"h+1"])==0);
+clf();nyquist(zpk(h),["h";"h+1"]);
+assert_checktrue(checknyquist(list(zpk(h)),["h";"h+1"])==0);
+
 
 clf();nyquist(h,0.01,100);
-if checknyquist(list(h,0.01,100)) then pause,end
-clf();nyquist(h,0.01,100,['h';'h+1']);
-if checknyquist(list(h,0.01,100),['h';'h+1']) then pause,end
+assert_checktrue(checknyquist(list(h,0.01,100))==0);
+clf();nyquist(zpk(h),0.01,100);
+assert_checktrue(checknyquist(list(zpk(h),0.01,100))==0);
+
+clf();nyquist(h,0.01,100,["h";"h+1"]);
+assert_checktrue(checknyquist(list(h,0.01,100),["h";"h+1"])==0);
 
 clf();nyquist(h,0.01,100,0.01)
-if checknyquist(list(h,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(h,0.01,100,0.01))==0);
 clf();nyquist(sl,0.01,100);
-if checknyquist(list(sl,0.01,100)) then pause,end
+assert_checktrue(checknyquist(list(sl,0.01,100))==0);
 clf();nyquist(sl,0.01,100,0.01)
-if checknyquist(list(sl,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(sl,0.01,100,0.01))==0);
 
 //discrete case
 clf();nyquist(hd);
-if checknyquist(list(hd)) then pause,end
-clf();nyquist(hd,'h');
-if checknyquist(list(hd),'h') then pause,end
+assert_checktrue(checknyquist(list(hd))==0);
+clf();nyquist(hd,"h");
+assert_checktrue(checknyquist(list(hd),"h")==0);
 
 clf();nyquist(hd,0.01,100);
-if checknyquist(list(hd,0.01,100)) then pause,end
-clf();nyquist(hd,0.01,100,'h');
-if checknyquist(list(hd,0.01,100),'h') then pause,end
+assert_checktrue(checknyquist(list(hd,0.01,100))==0);
+clf();nyquist(hd,0.01,100,"h");
+assert_checktrue(checknyquist(list(hd,0.01,100),"h")==0);
 
 clf();nyquist(hd,0.01,100,0.01)
-if checknyquist(list(hd,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(hd,0.01,100,0.01))==0);
 clf();nyquist(sld,0.01,100);
-if checknyquist(list(sld,0.01,100)) then pause,end
+assert_checktrue(checknyquist(list(sld,0.01,100))==0);
 clf();nyquist(sld,0.01,100,0.01)
-if checknyquist(list(sld,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(sld,0.01,100,0.01))==0);
 
 //discrete case SIMO
 hd=[hd;hd+1];sld=[sld;sld+1];
 clf();nyquist(hd);
-if checknyquist(list(hd)) then pause,end
-clf();nyquist(hd,['h';'h+1']);
-if checknyquist(list(hd),['h';'h+1']) then pause,end
+assert_checktrue(checknyquist(list(hd))==0);
+clf();nyquist(zpk(hd));
+assert_checktrue(checknyquist(list(zpk(hd)))==0);
+clf();nyquist(hd,["h";"h+1"]);
+assert_checktrue(checknyquist(list(hd),["h";"h+1"])==0);
 
 clf();nyquist(hd,0.01,100);
-if checknyquist(list(hd,0.01,100)) then pause,end
-clf();nyquist(hd,0.01,100,['h';'h+1']);
-if checknyquist(list(hd,0.01,100),['h';'h+1']) then pause,end
+assert_checktrue(checknyquist(list(hd,0.01,100))==0);
+clf();nyquist(hd,0.01,100,["h";"h+1"]);
+assert_checktrue(checknyquist(list(hd,0.01,100),["h";"h+1"])==0);
+clf();nyquist(zpk(hd),0.01,100,["h";"h+1"]);
+assert_checktrue(checknyquist(list(zpk(hd),0.01,100),["h";"h+1"])==0);
 
 clf();nyquist(hd,0.01,100,0.01)
-if checknyquist(list(hd,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(hd,0.01,100,0.01))==0);
 clf();nyquist(sld,0.01,100);
-if checknyquist(list(sld,0.01,100)) then pause,end
+assert_checktrue(checknyquist(list(sld,0.01,100))==0);
 clf();nyquist(sld,0.01,100,0.01)
-if checknyquist(list(sld,0.01,100,0.01)) then pause,end
+assert_checktrue(checknyquist(list(sld,0.01,100,0.01))==0);
 
 //nyquist given by precmputed freqency response
 
@@ -150,9 +160,10 @@ clf(); nyquist(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)))
 
 // check legend color
 clf();
-F1=syslin('c',(2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
-F2=syslin('c',(0.88*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
-F3=syslin('c',(100*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
+F1=syslin("c",(2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
+F2=syslin("c",(0.88*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
+F3=syslin("c",(100*2.5*0.8)/((0.25*%s+1)*(0.8*%s+1)));
 nyquist ([F1;F2;F3],0.0 ,1000,["F1(Kr=1)";"F2(Kr=0,88)";"F3(Kr=10)"],%f)
 a=gca();
 assert_checkequal(a.children(1).links.foreground, [3, 2, 1]); // [green blue black]
+driver(old);
diff --git a/scilab/modules/cacsd/tests/unit_tests/ss2zp.dia.ref b/scilab/modules/cacsd/tests/unit_tests/ss2zp.dia.ref
new file mode 100644 (file)
index 0000000..e8ce9e5
--- /dev/null
@@ -0,0 +1,62 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+    eps=1e-10;
+    y=gsort(real(x(abs(imag(x))<eps)),"g","i");
+    y=[y;gsort(x(imag(x)<-eps),"g","i")];
+    y=[y;gsort(x(imag(x)>eps),"g","i")];
+endfunction
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^2);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,2.5); //faux
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^3);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,2.5);
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+h=syslin("c",3*%s+7,2*%s^2+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkalmostequal(z,-7/3);
+h=syslin("c",3,2*%s^2+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkequal(z,[]);
+h=syslin("c",3,-2*%s^4+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,-1.5);
+assert_checkalmostequal(gsort(p),gsort(roots(h.den)));
+assert_checkequal(z,[]);
+h=syslin("c",%s^3+3*%s+7,2*%s^2+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,1/2);
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,2*%s^2+3*%s+1)];
+S=tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(z(:,1),[-0.5;-1; %inf]);
+assert_checkalmostequal(csort(z(:,2)),csort([-1.4;-0.5+%i*0.5;-0.5-%i*0.5]));
+assert_checkalmostequal(csort(p),csort(spec(S.A)));
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,(%s+4)*(2*%s^2+3*%s+1))];
+S=tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(csort(z(:,1)),csort([-4;-1;-0.5]));
+assert_checkalmostequal(csort(z(:,2)),csort([-0.5+%i*0.5;-0.5-%i*0.5;-1.4]));
+assert_checkalmostequal(csort(p),csort(spec(S.A)));
diff --git a/scilab/modules/cacsd/tests/unit_tests/ss2zp.tst b/scilab/modules/cacsd/tests/unit_tests/ss2zp.tst
new file mode 100644 (file)
index 0000000..e1f9a64
--- /dev/null
@@ -0,0 +1,73 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+    eps=1e-10;
+    y=gsort(real(x(abs(imag(x))<eps)),"g","i");
+    y=[y;gsort(x(imag(x)<-eps),"g","i")];
+    y=[y;gsort(x(imag(x)>eps),"g","i")];
+endfunction
+
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^2);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,2.5); //faux
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^3);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,2.5);
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+
+h=syslin("c",3*%s+7,2*%s^2+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkalmostequal(z,-7/3);
+
+h=syslin("c",3,2*%s^2+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkequal(z,[]);
+
+h=syslin("c",3,-2*%s^4+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,-1.5);
+assert_checkalmostequal(gsort(p),gsort(roots(h.den)));
+assert_checkequal(z,[]);
+
+h=syslin("c",%s^3+3*%s+7,2*%s^2+3*%s+1);
+S =  tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,1/2);
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+
+
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,2*%s^2+3*%s+1)];
+S=tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(z(:,1),[-0.5;-1; %inf]);
+assert_checkalmostequal(csort(z(:,2)),csort([-1.4;-0.5+%i*0.5;-0.5-%i*0.5]));
+assert_checkalmostequal(csort(p),csort(spec(S.A)));
+
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,(%s+4)*(2*%s^2+3*%s+1))];
+S=tf2ss(h);
+[z,p,k]=ss2zp(S);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(csort(z(:,1)),csort([-4;-1;-0.5]));
+assert_checkalmostequal(csort(z(:,2)),csort([-0.5+%i*0.5;-0.5-%i*0.5;-1.4]));
+assert_checkalmostequal(csort(p),csort(spec(S.A)));
+
+
diff --git a/scilab/modules/cacsd/tests/unit_tests/tf2zp.dia.ref b/scilab/modules/cacsd/tests/unit_tests/tf2zp.dia.ref
new file mode 100644 (file)
index 0000000..b3bf443
--- /dev/null
@@ -0,0 +1,54 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+  eps=1e-10
+  y=gsort(real(x(abs(imag(x))<eps)),"g","i")
+  y=[y;gsort(x(imag(x)<-eps),"g","i")]
+  y=[y;gsort(x(imag(x)>eps),"g","i")] 
+endfunction
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^2);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,2.5); //faux
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^3);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,2.5);
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+h=syslin("c",3*%s+7,2*%s^2+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkalmostequal(z,-7/3);
+h=syslin("c",3,2*%s^2+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkequal(z,[]);
+h=syslin("c",3,-2*%s^4+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,-1.5);
+assert_checkalmostequal(gsort(p),gsort(roots(h.den)));
+assert_checkequal(z,[]);
+h=syslin("c",%s^3+3*%s+7,2*%s^2+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,1/2);
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,2*%s^2+3*%s+1)];
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(csort(z(:,1)),csort([-0.5;-1; %inf]));
+assert_checkalmostequal(csort(z(:,2)),csort([-1.4;-0.5+%i*0.5;-0.5-%i*0.5]));
+assert_checkalmostequal(csort(p),csort(roots(lcm(h.den))));
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,(%s+4)*(2*%s^2+3*%s+1))];
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(csort(z(:,1)),csort([-0.5;-1;-4]));
+assert_checkalmostequal(csort(z(:,2)),csort([-0.5+%i*0.5;-0.5-%i*0.5;-1.4]));
+assert_checkalmostequal(csort(p),csort(roots(lcm(h.den))));
diff --git a/scilab/modules/cacsd/tests/unit_tests/tf2zp.tst b/scilab/modules/cacsd/tests/unit_tests/tf2zp.tst
new file mode 100644 (file)
index 0000000..ad8340b
--- /dev/null
@@ -0,0 +1,64 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+  eps=1e-10
+  y=gsort(real(x(abs(imag(x))<eps)),"g","i")
+  y=[y;gsort(x(imag(x)<-eps),"g","i")]
+  y=[y;gsort(x(imag(x)>eps),"g","i")] 
+endfunction
+
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^2);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,2.5); //faux
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+
+h=syslin("c",3.5+1.5*%s+2.5*%s^2,0.5+1.5*%s+%s^3);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,2.5);
+assert_checkalmostequal(csort(p),csort(roots(h.den)));
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+
+h=syslin("c",3*%s+7,2*%s^2+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkalmostequal(z,-7/3);
+
+h=syslin("c",3,2*%s^2+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,1.5);
+assert_checkalmostequal(gsort(p),[-1;-0.5]);
+assert_checkequal(z,[]);
+
+h=syslin("c",3,-2*%s^4+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,-1.5);
+assert_checkalmostequal(gsort(p),gsort(roots(h.den)));
+assert_checkequal(z,[]);
+
+h=syslin("c",%s^3+3*%s+7,2*%s^2+3*%s+1);
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,1/2);
+assert_checkalmostequal(csort(z),csort(roots(h.num)));
+
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,2*%s^2+3*%s+1)];
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(csort(z(:,1)),csort([-0.5;-1; %inf]));
+assert_checkalmostequal(csort(z(:,2)),csort([-1.4;-0.5+%i*0.5;-0.5-%i*0.5]));
+assert_checkalmostequal(csort(p),csort(roots(lcm(h.den))));
+
+h=[syslin("c",3,2*%s^2+2*%s+1);syslin("c",5*%s+7,(%s+4)*(2*%s^2+3*%s+1))];
+[z,p,k]=tf2zp(h);
+assert_checkalmostequal(k,[3/2;5/2]);
+assert_checkalmostequal(csort(z(:,1)),csort([-0.5;-1;-4]));
+assert_checkalmostequal(csort(z(:,2)),csort([-0.5+%i*0.5;-0.5-%i*0.5;-1.4]));
+assert_checkalmostequal(csort(p),csort(roots(lcm(h.den))));
+
+
diff --git a/scilab/modules/cacsd/tests/unit_tests/zp2ss.dia.ref b/scilab/modules/cacsd/tests/unit_tests/zp2ss.dia.ref
new file mode 100644 (file)
index 0000000..ce88cba
--- /dev/null
@@ -0,0 +1,50 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+  eps=1e-10
+  y=gsort(real(x(abs(imag(x))<eps)),"g","i")
+  y=[y;gsort(x(imag(x)<-eps),"g","i")]
+  y=[y;gsort(x(imag(x)>eps),"g","i")] 
+endfunction
+Z=[2;1;0.5-%i;0.5+%i];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[0.5;0.6];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[0.5];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2;1;0.5-%i;0.5+%i];P=[5-%i;5+%i;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2;1;0.5-%i;0.5+%i;8];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2,1-%i;1,1+%i;0.5-%i,2;0.5+%i,%inf;8,%inf] ;
+P=[5-%i;5+%i;7;3-%i;3+%i];K=[1;3];
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z(:,1)),csort(z(:,1)));
+assert_checkalmostequal(csort(Z(:,2)),csort(z(:,2)));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
diff --git a/scilab/modules/cacsd/tests/unit_tests/zp2ss.tst b/scilab/modules/cacsd/tests/unit_tests/zp2ss.tst
new file mode 100644 (file)
index 0000000..4f0e4af
--- /dev/null
@@ -0,0 +1,60 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+  eps=1e-10
+  y=gsort(real(x(abs(imag(x))<eps)),"g","i")
+  y=[y;gsort(x(imag(x)<-eps),"g","i")]
+  y=[y;gsort(x(imag(x)>eps),"g","i")] 
+endfunction
+
+
+Z=[2;1;0.5-%i;0.5+%i];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[0.5;0.6];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[0.5];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+
+Z=[2;1;0.5-%i;0.5+%i];P=[5-%i;5+%i;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[2;1;0.5-%i;0.5+%i;8];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[2];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+
+Z=[2,1-%i;1,1+%i;0.5-%i,2;0.5+%i,%inf;8,%inf] ;
+P=[5-%i;5+%i;7;3-%i;3+%i];K=[1;3];
+[z,p,k]=ss2zp(zp2ss(Z,P,K));
+assert_checkalmostequal(csort(Z(:,1)),csort(z(:,1)));
+assert_checkalmostequal(csort(Z(:,2)),csort(z(:,2)));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
diff --git a/scilab/modules/cacsd/tests/unit_tests/zp2tf.dia.ref b/scilab/modules/cacsd/tests/unit_tests/zp2tf.dia.ref
new file mode 100644 (file)
index 0000000..5b2951a
--- /dev/null
@@ -0,0 +1,50 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+  eps=1e-10
+  y=gsort(real(x(abs(imag(x))<eps)),"g","i")
+  y=[y;gsort(x(imag(x)<-eps),"g","i")]
+  y=[y;gsort(x(imag(x)>eps),"g","i")] 
+endfunction
+Z=[2;1;0.5-%i;0.5+%i];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[0.5;0.6];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[0.5];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2;1;0.5-%i;0.5+%i];P=[5-%i;5+%i;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2;1;0.5-%i;0.5+%i;8];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+Z=[2,1-%i;1,1+%i;0.5-%i,2;0.5+%i,%inf;8,%inf] ;
+P=[5-%i;5+%i;7;3-%i;3+%i];K=[1;3];
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z(:,1)),csort(z(:,1)));
+assert_checkalmostequal(csort(Z(:,2)),csort(z(:,2)));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
diff --git a/scilab/modules/cacsd/tests/unit_tests/zp2tf.tst b/scilab/modules/cacsd/tests/unit_tests/zp2tf.tst
new file mode 100644 (file)
index 0000000..bed9cb6
--- /dev/null
@@ -0,0 +1,59 @@
+//<-- CLI SHELL MODE -->
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+function y=csort(x)
+  eps=1e-10
+  y=gsort(real(x(abs(imag(x))<eps)),"g","i")
+  y=[y;gsort(x(imag(x)<-eps),"g","i")]
+  y=[y;gsort(x(imag(x)>eps),"g","i")] 
+endfunction
+
+Z=[2;1;0.5-%i;0.5+%i];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[0.5;0.6];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[0.5];P=[4;5;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+
+Z=[2;1;0.5-%i;0.5+%i];P=[5-%i;5+%i;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[2;1;0.5-%i;0.5+%i;8];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+Z=[2];P=[5-%i;5+%i;7;3-%i;3+%i];K=1;
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z),csort(z));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
+
+
+Z=[2,1-%i;1,1+%i;0.5-%i,2;0.5+%i,%inf;8,%inf] ;
+P=[5-%i;5+%i;7;3-%i;3+%i];K=[1;3];
+[z,p,k]=tf2zp(zp2tf(Z,P,K));
+assert_checkalmostequal(csort(Z(:,1)),csort(z(:,1)));
+assert_checkalmostequal(csort(Z(:,2)),csort(z(:,2)));
+assert_checkalmostequal(csort(P),csort(p));
+assert_checkalmostequal(K,k);
diff --git a/scilab/modules/cacsd/tests/unit_tests/zpk.dia.ref b/scilab/modules/cacsd/tests/unit_tests/zpk.dia.ref
new file mode 100644 (file)
index 0000000..056e453
--- /dev/null
@@ -0,0 +1,330 @@
+//<-- CLI SHELL MODE -->
+// This file is part of the zpk module
+// Copyright (C) 2016 - Serge Steer - INRIA
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+// Tests of zpk function
+//----------------------------------------------------------------
+z11=[1 -0.5];p11=[-2 -3+2*%i -3-2*%i  ];k11=1;
+S11=zpk(z11,p11,k11,"c");
+assert_checkequal(S11.Z{1},z11.');
+assert_checkequal(S11.P{1},p11.');
+assert_checkequal(S11.K,k11);
+z21=0.3;p21=[-3+2*%i -3-2*%i];k21=1.5;
+S21=zpk(z21,p21,k21,"c");
+S12=zpk([],0,1,"c");
+S22=zpk(1,-3,1,"c");
+S=zpk({z11 [];z21 1},{p11,0;p21 -3},[k11 1;k21 1],"c");
+assert_checkequal(S.Z{1,1},z11.');
+assert_checkequal(S.P{1,1},p11.');
+assert_checkequal(S.K(1,1),k11);
+assert_checkequal(S.Z{1,2},[]);
+assert_checkequal(S.P{1,2},0);
+assert_checkequal(S.K(1,2),1);
+assert_checkequal(S.Z{2,1},z21.');
+assert_checkequal(S.P{2,1},p21.');
+assert_checkequal(S.K(2,1),k21);
+assert_checkequal(S.Z{2,2},1);
+assert_checkequal(S.P{2,2},-3);
+assert_checkequal(S.K(2,2),1);
+h1=syslin("c",5*(%s-1)*(%s-3)/(%s^2-4));
+Sh1=zpk(h1);
+assert_checkalmostequal(Sh1.Z{1},[3;1]);
+assert_checkalmostequal(Sh1.P{1},[2;-2]);
+assert_checkalmostequal(Sh1.K,5);
+Ss1=zpk(tf2ss(h1));
+assert_checkalmostequal(Ss1.Z{1},[3;1]);
+assert_checkalmostequal(Ss1.P{1},[2;-2]);
+assert_checkalmostequal(Ss1.K,5);
+h2=syslin("c",1/(%s^2+1));
+Sh=zpk([h1 h2]);
+assert_checkalmostequal(Sh.Z{1,1},[3;1]);
+assert_checkalmostequal(Sh.P{1,1},[2;-2]);
+assert_checkalmostequal(Sh.K(1,1),5);
+assert_checkalmostequal(Sh.Z{1,2},[]);
+assert_checkalmostequal(Sh.P{1,2},[%i;-%i]);
+assert_checkalmostequal(Sh.K(1,2),1);
+Ss=zpk(tf2ss([h1 h2]));
+assert_checkalmostequal(Ss.Z{1,1},[3;1]);
+assert_checkalmostequal(Ss.P{1,1},[2;-2]);
+assert_checkalmostequal(Ss.K(1,1),5);
+assert_checkalmostequal(Ss.Z{1,2},[]);
+assert_checkalmostequal(Ss.P{1,2},[%i;-%i]);
+assert_checkalmostequal(Ss.K(1,2),1);
+// test of function size
+//----------------------------------------------------------------
+assert_checkequal(size(S11),[1 1]);
+assert_checkequal(size(S11,1),1);
+assert_checkequal(size(S,2),2);
+assert_checkequal(size(S,"*"),4);
+assert_checkequal(size(S,"r"),2);
+// Tests of comparisons
+//----------------------------------------------------------------
+assert_checkequal(S11==S11,%t);
+assert_checkequal(S==S,[%t %t;%t %t]);
+assert_checkequal(S==S11,[%t %f;%f %f]);
+assert_checkequal(S<>S11,[%f %t;%t %t]);
+assert_checkequal(S11<>S11,%f);
+//test of references and catenation
+//----------------------------------------------------------------
+assert_checktrue(S(1)==S11);
+assert_checktrue(S(1,1)==S11);
+assert_checktrue(S(:,1)==[S11;S21]);
+assert_checktrue(S(1,:)==[S11, S12]);
+assert_checktrue([S11 []]==S11);
+assert_checktrue([[] S11]==S11);
+assert_checktrue([S11;[]]==S11);
+assert_checktrue([[];S11]==S11);
+tmp=[S11 1];
+assert_checktrue(tmp(1,1)==S11);
+assert_checktrue(tmp(1,2)==zpk([],[],1,"c"));
+tmp=[1 S11];
+assert_checktrue(tmp(1,2)==S11);
+assert_checktrue(tmp(1,1)==zpk([],[],1,"c"));
+tmp=[S11;1];
+assert_checktrue(tmp(1,1)==S11);
+assert_checktrue(tmp(2,1)==zpk([],[],1,"c"));
+tmp=[1;S11];
+assert_checktrue(tmp(2,1)==S11);
+assert_checktrue(tmp(1,1)==zpk([],[],1,"c"));
+tmp=[S [5;7]];
+assert_checktrue(tmp(:,1:2)==S);
+assert_checktrue(tmp(:,$)==zpk({[];[]},{[];[]},[5;7],"c"));
+tmp=[[5;7] S];
+assert_checktrue(tmp(:,2:$)==S);
+assert_checktrue(tmp(:,1)==zpk({[];[]},{[];[]},[5;7],"c"));
+assert_checktrue([S11 h1]==[S11 zpk(h1)]);
+assert_checktrue([h1;S11]==[zpk(h1);S11]);
+assert_checktrue([S;Sh]==[S;zpk(Sh)]);
+assert_checktrue([Sh;S]==[zpk(Sh);S]);
+// Tests of assignments
+//----------------------------------------------------------------
+tmp=S;
+tmp(1,1)=S12;
+assert_checktrue(tmp==[S12 S12;S21 S22]);
+tmp(:,1)=[S12;S12];
+assert_checktrue(tmp==[S12 S12;S12 S22]);
+// Tests of transpose
+//----------------------------------------------------------------
+assert_checktrue([S11 S12]'==[S11;S12]);
+assert_checktrue(S'==[S11 S21;S12 S22]);
+// Test of sum, + and -
+//----------------------------------------------------------------
+z11=[1 -0.5];p11=[-2 -3+2*%i -3-2*%i  ];k11=1;
+S11=zpk(z11,p11,k11,"c");
+z21=0.3;p21=[-3+2*%i -3-2*%i];k21=1.5;
+S21=zpk(z21,p21,k21,"c");
+S12=zpk([],0,1,"c");
+S22=zpk(1,-3,1,"c");
+S=zpk({z11 [];z21 1},{p11,0;p21 -3},[k11 1;k21 1],"c");
+h1=syslin("c",1/(1-%s));
+Sh1=tf2ss(h1);
+s=S11+S12;
+Z=[-1.1452362725849+%i*2.7559801007529;
+-1.1452362725849-%i*2.7559801007529;
+-1.4595274548302];
+P=[0;-2;-3+%i*2;-3-%i*2];
+K=2;
+assert_checkalmostequal(s.Z{1},Z);
+assert_checktrue(s.P{1}==P);
+assert_checktrue(s.K==K);
+s=S+S;
+assert_checktrue(s.Z{1}==S.Z{1});
+assert_checktrue(s.P{1}==S.P{1});
+assert_checktrue(s.K==2*S.K);
+s=-S;
+assert_checktrue(s.Z{1}==S.Z{1});
+assert_checktrue(s.P{1}==S.P{1});
+assert_checktrue(s.K==-S.K);
+assert_checktrue(S11-S12==S11+(-S12));
+assert_checktrue(S-S==zpk(cell(2,2),cell(2,2),zeros(2,2),"c"));
+s=S22+S12;
+Z=[%i;-%i]*sqrt(3);
+P=[0;-3];
+K=1;
+assert_checkalmostequal(s.Z{1},Z);
+assert_checktrue(s.P{1}==P);
+assert_checktrue(s.K==K);
+s=S22-S12;
+Z=[3;-1];
+P=[0;-3];
+K=1;
+assert_checkalmostequal(s.Z{1},Z);
+assert_checktrue(s.P{1}==P);
+assert_checktrue(s.K==K);
+assert_checktrue(S12+1==zpk(-1,0,1,"c"));
+assert_checktrue(1+S12==zpk(-1,0,1,"c"));
+assert_checktrue(h1+S12==zpk([],[0 1],-1,"c"));
+assert_checktrue(S12+h1==zpk([],[0 1],-1,"c"));
+assert_checktrue(h1-S12==zpk(0.5,[0 1],-2,"c"));
+assert_checktrue(S12-h1==zpk(0.5,[0 1],2,"c"));
+s=S12-Sh1;
+assert_checktrue(s.A==[0 0;0 1]);
+assert_checktrue(s.B==[1;-1]);
+assert_checktrue(s.C==[1 -1]);
+assert_checktrue(s.D==0);
+s=Sh1-S12;
+assert_checktrue(s.A==[1 0;0 0]);
+assert_checktrue(s.B==[1;-1]);
+assert_checktrue(s.C==[-1 1]);
+assert_checktrue(s.D==0);
+// Test of *
+//----------------------------------------------------------------
+z11=[1 -0.5];p11=[-2 -3+2*%i -3-2*%i  ];k11=1;
+S11=zpk(z11,p11,k11,"c");
+z21=0.3;p21=[-3+2*%i -3-2*%i];k21=1.5;
+S21=zpk(z21,p21,k21,"c");
+S12=zpk([],0,1,"c");
+S22=zpk(1,-3,1,"c");
+S=zpk({z11 [];z21 1},{p11,0;p21 -3},[k11 1;k21 1],"c");
+// "scalar"*"scalar"
+assert_checktrue(S12*S12==zpk([],[0 0],1,"c"));
+assert_checktrue(S11*S11==zpk([z11 z11],[p11 p11],k11^2,"c"));
+// "scalar"*matrix and matrix*"scalar"
+S2=S*S12;
+assert_checktrue(S2(1,1)==S(1,1)*S12);
+assert_checktrue(S2(2,1)==S(2,1)*S12);
+assert_checktrue(S2(1,2)==S(1,2)*S12);
+assert_checktrue(S2(2,2)==S(2,2)*S12);
+S2=S12*S;
+assert_checktrue(S2(1,1)==S(1,1)*S12);
+assert_checktrue(S2(2,1)==S(2,1)*S12);
+assert_checktrue(S2(1,2)==S(1,2)*S12);
+assert_checktrue(S2(2,2)==S(2,2)*S12);
+//matrix*matrix
+S2=S(1,:)*S(:,1);
+Z=[0.2992047956058;
+-1.4216535670946+%i*0.5022286865922;
+-1.4216535670946-%i*0.5022286865922;
+-1.4379488307083+%i*3.4195209906928;
+-1.4379488307083-%i*3.4195209906928];
+P=[0;-2;-2;-3+%i*2;-3+%i*2;-3-%i*2;-3-%i*2];
+K=2.5;
+assert_checkalmostequal(S2.Z{1},Z);
+assert_checktrue(S2.P{1}==P);
+assert_checkalmostequal(S2.K,K);
+assert_checktrue((S*S)(1,1)==S2);
+S2=S(2,:)*S(:,1);
+Z=[1;0.3;-1.7226779397091;
+-3.6386610301454+%i*1.6503526090746;
+-3.6386610301454-%i*1.6503526090746];
+P=[-2;-3+%i*2;-3+%i*2;-3;-3-%i*2;-3-%i*2];
+K=1.5;
+assert_checkalmostequal(S2.Z{1},Z);
+assert_checktrue(S2.P{1}==P);
+assert_checkalmostequal(S2.K,K);
+assert_checktrue((S*S)(2,1)==S2);
+//mixed type products
+h1=syslin("c",5*(%s-1)*(%s-3)/(%s^2-4));
+h2=syslin("c",1/(%s^2+1));
+S2=S11*2;
+assert_checktrue(S2.Z==S11.Z&S2.P==S11.P&S2.K==2*S11.K);
+S2=3*S11;
+assert_checktrue(S2.Z==S11.Z&S2.P==S11.P&S2.K==3*S11.K);
+S2=eye(2,2)*S;
+for i=1:2,
+    for j=1:2
+        assert_checkalmostequal(S2.Z{i,j},S.Z{i,j});
+    end;
+end
+assert_checktrue(S2.P==S.P);
+assert_checkalmostequal(S2.K,S.K);
+S2=S*eye(2,2);
+for i=1:2,
+    for j=1:2
+        assert_checkalmostequal(S2.Z{i,j},S.Z{i,j});
+    end;
+end
+assert_checktrue(S2.P==S.P);
+assert_checkalmostequal(S2.K,S.K);
+assert_checktrue(S11*h1==S11*zpk(h1));
+assert_checktrue(h1*S11==zpk(h1)*S11);
+assert_checktrue(S(1,:)*[h1;h2]==S(1,:)*zpk([h1;h2]));
+assert_checktrue([h1;h2]*S(1,:)==zpk([h1;h2])*S(1,:));
+s1=tf2ss(h1);
+s2=tf2ss(h2);
+assert_checktrue(S(2,:)*[s1;s2]==zpk2ss(S(2,:))*[s1;s2]);
+assert_checktrue([s1 s2]*S(:,2)==[s1 s2]*zpk2ss(S(:,2)));
+// Test of .*
+//----------------------------------------------------------------
+z11=[1 -0.5];p11=[-2 -3+2*%i -3-2*%i  ];k11=1;
+S11=zpk(z11,p11,k11,"c");
+z21=0.3;p21=[-3+2*%i -3-2*%i];k21=1.5;
+S21=zpk(z21,p21,k21,"c");
+S12=zpk([],0,1,"c");
+S22=zpk(1,-3,1,"c");
+S=zpk({z11 [];z21 1},{p11,0;p21 -3},[k11 1;k21 1],"c");
+h1=syslin("c",5*(%s-1)*(%s-3)/(%s^2-4));
+h2=syslin("c",1/(%s^2+1));
+assert_checktrue(S11.*S21==zpk([z11 z21],[p11 p21],k11*k21,"c"));
+assert_checktrue(S.*S11==S*S11);
+assert_checktrue(S11.*S==S*S11);
+Z=cell(2,2);P=cell(2,2);
+for i=1:2
+    for j=1:2
+        Z{i,j}=[S.Z{i,j};S.Z{i,j}];
+        P{i,j}=[S.P{i,j};S.P{i,j}];
+    end
+end
+assert_checktrue(S.*S==zpk(Z,P,S.K.*S.K,"c"));
+A=[1 2;3 4];
+assert_checktrue(S.*A==zpk(S.Z,S.P,S.K.*A,"c"));
+assert_checktrue(A.*S==zpk(S.Z,S.P,S.K.*A,"c"));
+A=5;
+assert_checktrue(S.*A==zpk(S.Z,S.P,S.K.*A,"c"));
+assert_checktrue(A.*S==zpk(S.Z,S.P,S.K.*A,"c"));
+assert_checktrue(S.*h1==S.*zpk(h1));
+assert_checktrue(h1.*S==S.*zpk(h1));
+assert_checktrue([h1 h2].*S(1,:)==zpk([h1 h2]).*S(1,:));
+if %f then
+    //skip because %lss_x_lss not implemented
+    s1=tf2ss(h1);s2=tf2ss(h2);
+    assert_checktrue(S.*s1==S.*zpk(s1));
+    assert_checktrue(s1.*S==S.*zpk(s1));
+    assert_checktrue([s1 s2].*S(1,:)==zpk([s1 s2]).*S(1,:));
+end
+//test of / and \
+z11=[1 -0.5];p11=[-2 -3+2*%i -3-2*%i  ];k11=1;
+S11=zpk(z11,p11,k11,"c");
+z21=0.3;p21=[-3+2*%i -3-2*%i];k21=1.5;
+S21=zpk(z21,p21,k21,"c");
+S12=zpk([],0,1,"c");
+S22=zpk(1,-3,1,"c");
+S=zpk({z11 [];z21 1},{p11,0;p21 -3},[k11 1;k21 1],"c");
+h1=syslin("c",1/(1-%s));
+Sh1=tf2ss(h1);
+assert_checktrue(S11/S12==zpk([0 1 -0.5],p11,1,"c"));
+assert_checktrue(S12\S11==zpk([0 1 -0.5],p11,1,"c"));
+assert_checktrue(S/S12==S*zpk(0,[],1,"c"));
+assert_checktrue(S12\S==S*zpk(0,[],1,"c"));
+s1=S;s1.K=s1.K/2;
+assert_checktrue(S/2==s1);
+assert_checktrue(2\S==s1);
+assert_checktrue(S/h1==S*zpk(1,[],-1,"c"));
+assert_checktrue(h1\S==S*zpk(1,[],-1,"c"));
+assert_checktrue(S/Sh1==S*zpk(1,[],-1,"c"));
+assert_checktrue(Sh1\S==S*zpk(1,[],-1,"c"));
+s1=minss(S/S);
+assert_checktrue(s1.A==[]&s1.B==[]&s1.C==[]);
+assert_checkalmostequal(s1.D,eye(2,2),1e-10,1e-10);
+s1=minss(S\S);
+assert_checktrue(s1.A==[]&s1.B==[]&s1.C==[]);
+assert_checkalmostequal(s1.D,eye(2,2),1e-10,1e-10);
+//test of ./ and .\
+assert_checktrue(S11./S12==zpk([0 1 -0.5],p11,1,"c"));
+assert_checktrue(S12.\S11==zpk([0 1 -0.5],p11,1,"c"));
+assert_checktrue(S./S12==S*zpk(0,[],1,"c"));
+assert_checktrue(S12.\S==S*zpk(0,[],1,"c"));
+s1=S;s1.K=s1.K/2;
+assert_checktrue(S./2==s1);
+assert_checktrue(2 .\S==s1);
+assert_checktrue(S./h1==S*zpk(1,[],-1,"c"));
+assert_checktrue(h1.\S==S*zpk(1,[],-1,"c"));
+assert_checktrue(S./Sh1==S*zpk(1,[],-1,"c"));
+assert_checktrue(Sh1.\S==S*zpk(1,[],-1,"c"));
+assert_checktrue(S./S==zpk({[],[];[],[]},{[],[];[],[]},ones(2,2),"c"));
+assert_checktrue(S.\S==zpk({[],[];[],[]},{[],[];[],[]},ones(2,2),"c"));
+s1=S./[1 2;4 1];
+assert_checktrue(s1.Z==S.Z&s1.P==S.P&s1.K==S.K./[1 2;4 1]);
diff --git a/scilab/modules/cacsd/tests/unit_tests/zpk.tst b/scilab/modules/cacsd/tests/unit_tests/zpk.tst
new file mode 100644 (file)
index 0000000..8e5febd
--- /dev/null
@@ -0,0 +1,389 @@
+//<-- CLI SHELL MODE -->
+// This file is part of the zpk module
+// Copyright (C) 2016 - Serge Steer - INRIA
+// This file is hereby licensed under the terms of the GNU GPL v2.0,
+// pursuant to article 5.3.4 of the CeCILL v.2.1.
+// For more information, see the COPYING file which you should have received
+// along with this program.
+
+// Tests of zpk function
+//----------------------------------------------------------------
+z11=[1 -0.5];p11=[-2 -3+2*%i -3-2*%i  ];k11=1;
+S11=zpk(z11,p11,k11,"c");
+
+
+assert_checkequal(S11.Z{1},z11.');
+assert_checkequal(S11.P{1},p11.');
+assert_checkequal(S11.K,k11);
+
+z21=0.3;p21=[-3+2*%i -3-2*%i];k21=1.5;
+S21=zpk(z21,p21,k21,"c");
+S12=zpk([],0,1,"c");
+S22=zpk(1,-3,1,"c");
+S=zpk({z11 [];z21 1},{p11,0;p21 -3},[k11 1;k21 1],"c");
+assert_checkequal(S.Z{1,1},z11.');
+assert_checkequal(S.P{1,1},p11.');
+assert_checkequal(S.K(1,1),k11);
+assert_checkequal(S.Z{1,2},[]);
+assert_checkequal(S.P{1,2},0);
+assert_checkequal(S.K(1,2),1);
+assert_checkequal(S.Z{2,1},z21.');
+assert_checkequal(S.P{2,1},p21.');
+assert_checkequal(S.K(2,1),k21);
+assert_checkequal(S.Z{2,2},1);
+assert_checkequal(S.P{2,2},-3);
+assert_checkequal(S.K(2,2),1);
+
+h1=syslin("c",5*(%s-1)*(%s-3)/(%s^2-4));
+Sh1=zpk(h1);
+assert_checkalmostequal(Sh1.Z{1},[3;1]);
+assert_checkalmostequal(Sh1.P{1},[2;-2]);
+assert_checkalmostequal(Sh1.K,5);
+Ss1=zpk(tf2ss(h1));
+assert_checkalmostequal(Ss1.Z{1},[3;1]);
+assert_checkalmostequal(Ss1.P{1},[2;-2]);
+assert_checkalmostequal(Ss1.K,5);
+
+
+h2=syslin("c",1/(%s^2+1));
+Sh=zpk([h1 h2]);
+assert_checkalmostequal(Sh.Z{1,1},[3;1]);
+assert_checkalmostequal(Sh.P{1,1},[2;-2]);
+assert_checkalmostequal(Sh.K(1,1),5);
+assert_checkalmostequal(Sh.Z{1,2},[]);
+assert_checkalmostequal(Sh.P{1,2},[%i;-%i]);
+assert_checkalmostequal(Sh.K(1,2),1);
+Ss=zpk(tf2ss([h1 h2]));
+assert_checkalmostequal(Ss.Z{1,1},[3;1]);
+assert_checkalmostequal(Ss.P{1,1},[2;-2]);
+assert_checkalmostequal(Ss.K(1,1),5);
+assert_checkalmostequal(Ss.Z{1,2},[]);
+assert_checkalmostequal(Ss.P{1,2},[%i;-%i]);
+assert_checkalmostequal(Ss.K(1,2),1);
+// test of function size
+//----------------------------------------------------------------
+assert_checkequal(size(S11),[1 1]);
+assert_checkequal(size(S11,1),1);
+assert_checkequal(size(S,2),2);
+assert_checkequal(size(S,"*"),4);
+assert_checkequal(size(S,"r"),2);
+
+// Tests of comparisons
+//----------