fix proposal for bug 13831: ss2ss does not transform initial state 29/18129/5
serge.steer [Thu, 28 Apr 2016 09:35:19 +0000 (11:35 +0200)]
Change-Id: If3fd1e630aff5c86377edb1be6ca8201fc067f55

scilab/CHANGES
scilab/modules/cacsd/macros/ss2ss.sci
scilab/modules/cacsd/tests/nonreg_tests/bug_13831.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/nonreg_tests/bug_13831.tst [new file with mode: 0644]

index 173c6f2..cac5d0e 100644 (file)
@@ -382,6 +382,8 @@ In 6.0.0:
 
 * Bug #13816 fixed - show_margins caused a scilab crash
 
+* Bug #13831 fixed - ss2ss does not transform initial state
+
 * Bug #13839 fixed - sign() could not be used with sparse matrices
 
 * Bug #13869 fixed - bench_run with option nb_run=10 did not override the NB RUN tags
index a77b880..b2ec5ca 100644 (file)
@@ -31,23 +31,24 @@ function [Sl1,right,left]=ss2ss(Sl,T,F,G,flag)
     [LHS,RHS]=argn(0);
     select RHS
     case 2 then
-        Sl1=syslin(Sl(7),inv(T)*A*T,inv(T)*B,C*T,D);
+        Ti=inv(T)
+        Sl1=syslin(Sl.dt,Ti*A*T,Ti*B,C*T,D,Ti*Sl.X0);
         right=eye(A);left=right;
     case 3 then
         A1=A+B*F;C1=C+D*F;
         A1=inv(T)*A1*T;B1=inv(T)*B;C1=C1*T;D1=D
-        Sl1=syslin(Sl(7),A1,B1,C1,D1);
-        right=syslin(Sl(7),A+B*F,B,F,eye(F*B));
+        Sl1=syslin(Sl.dt,A1,B1,C1,D1,Sl.X0);
+        right=syslin(Sl.dt,A+B*F,B,F,eye(F*B));
         left=eye(size(C,1),size(C,1));
     case 4 then
         A1=A+B*F+G*C+G*D*F;C1=C+D*F;B1=B+G*D
         A1=inv(T)*A1*T;B1=inv(T)*B1;C1=C1*T;D1=D
-        Sl1=syslin(Sl(7),A1,B1,C1,D1);
-        right=syslin(Sl(7),A+B*F,B,F,eye(F*B));
+        Sl1=syslin(Sl.dt,A1,B1,C1,D1,Sl.X0);
+        right=syslin(Sl.dt,A+B*F,B,F,eye(F*B));
         // Warning left is computed as [ At + G*Ct,G;Ct,I]
         // where [At Bt; Ct Dt] is Sl1*right
         At=A+B*F; Ct=C+D*F
-        left=syslin(Sl(7),At+G*Ct,G,Ct,eye(Ct*G));
+        left=syslin(Sl.dt,At+G*Ct,G,Ct,eye(Ct*G));
     case 5 then
         if flag==1 then
             // x in R^n , y in R^p, u in R^m
@@ -68,11 +69,11 @@ function [Sl1,right,left]=ss2ss(Sl,T,F,G,flag)
             A1=A+G*C+[B+G*D,-G]*F;B1=[B+G*D,-G];C1=C+[D,zeros(p,p)]*F;
             D1=[D,zeros(p,p)];
             A1=inv(T)*A1*T;B1=inv(T)*B1;C1=C1*T;D1=D1
-            Sl1=syslin(Sl(7),A1,B1,C1,D1);
-            left=syslin(Sl(7),A+G*C,[G,-G],C,[eye(p,p),zeros(p,p)]);
+            Sl1=syslin(Sl.dt,A1,B1,C1,D1,Sl.X0);
+            left=syslin(Sl.dt,A+G*C,[G,-G],C,[eye(p,p),zeros(p,p)]);
             // Now we compute the right associated to left*Sl1
             A1=A+G*C;B1=[B+G*D,-G];C1=C;D1=[D,zeros(p,p)];
-            right=syslin(Sl(7),A1+B1*F,B1,F,eye(F*B1));
+            right=syslin(Sl.dt,A1+B1*F,B1,F,eye(F*B1));
             return
         end
         if flag==2 then
@@ -93,13 +94,13 @@ function [Sl1,right,left]=ss2ss(Sl,T,F,G,flag)
             C1=C+ D*F;
             D1=[D,zeros(p,p)];
             A1=inv(T)*A1*T;B1=inv(T)*B1;C1=C1*T;D1=D1
-            Sl1=syslin(Sl(7),A1,B1,C1,D1);
-            right=syslin(Sl(7),A+B*F,B,F,eye(F*B));
+            Sl1=syslin(Sl.dt,A1,B1,C1,D1,Sl.X0);
+            right=syslin(Sl.dt,A+B*F,B,F,eye(F*B));
             // Warning left is computed as [ At + G*Ct,(G,-G);
             //                             [    Ct    ,(I, 0)]
             // where [At Bt; Ct Dt] is Sl1*right
             At=A+B*F; Ct=C+D*F
-            left=syslin(Sl(7),At+G*Ct,[G,-G],Ct,[eye(Ct*G),zeros(Ct*G)]);
+            left=syslin(Sl.dt,At+G*Ct,[G,-G],Ct,[eye(Ct*G),zeros(Ct*G)]);
         end
     end
 endfunction
diff --git a/scilab/modules/cacsd/tests/nonreg_tests/bug_13831.dia.ref b/scilab/modules/cacsd/tests/nonreg_tests/bug_13831.dia.ref
new file mode 100644 (file)
index 0000000..7f3a27b
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Scilab Enterprises - Clement DAVID
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 13831 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=13831
+//
+// <-- Short Description -->
+// ss2ss does not transform initial state
+before = syslin('c',-1,1,1,0,1);
+after = ss2ss(before, 2);
+assert_checkequal(after.x0, before.x0 / 2);
diff --git a/scilab/modules/cacsd/tests/nonreg_tests/bug_13831.tst b/scilab/modules/cacsd/tests/nonreg_tests/bug_13831.tst
new file mode 100644 (file)
index 0000000..b044861
--- /dev/null
@@ -0,0 +1,20 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2016 - Scilab Enterprises - Clement DAVID
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- CLI SHELL MODE -->
+//
+// <-- Non-regression test for bug 13831 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=13831
+//
+// <-- Short Description -->
+// ss2ss does not transform initial state
+
+before = syslin("c",-1,1,1,0,1);
+after = ss2ss(before, 2);
+assert_checkequal(after.x0, before.x0 / 2);