Add unitary tests for cacsd 97/9897/4
Sylvestre Ledru [Mon, 3 Dec 2012 15:23:50 +0000 (16:23 +0100)]
Change-Id: I78f93d1e1b1f2baf2c9b11939db53fc16a60f4ab

scilab/modules/cacsd/tests/unit_tests/dhinf.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/dhinf.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/rankqr.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/rankqr.tst [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/ricc.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/ricc.tst [new file with mode: 0644]

diff --git a/scilab/modules/cacsd/tests/unit_tests/dhinf.dia.ref b/scilab/modules/cacsd/tests/unit_tests/dhinf.dia.ref
new file mode 100644 (file)
index 0000000..53dc7ff
--- /dev/null
@@ -0,0 +1,58 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - SE - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+A=[-0.7  0    0.3  0   -0.5 -0.1
+   -0.6  0.2 -0.4 -0.3  0    0
+   -0.5  0.7 -0.1  0    0   -0.8
+   -0.7  0    0   -0.5 -1    0
+    0    0.3  0.6 -0.9  0.1 -0.4
+    0.5 -0.8  0    0    0.2 -0.9];
+B=[-1 -2 -2  1  0
+    1  0  1 -2  1
+   -3 -4  0  2 -2
+    1 -2  1  0 -1
+    0  1 -2  0  3
+    1  0  3 -1 -2];
+C=[ 1 -1  2 -2  0 -3
+   -3  0  1 -1  1  0
+    0  2  0 -4  0 -2
+    1 -3  0  0  3  1
+    0  1 -2  1  0 -2];
+D=[1 -1 -2  0  0
+   0  1  0  1  0
+   2 -1 -3  0  1
+   0  1  0  1 -1
+   0  0  1  2  1];
+ncon=2
+ ncon  =
+    2.  
+nmeas=2
+ nmeas  =
+    2.  
+gam=111.30;
+[AK,BK,CK,DK] = dhinf(A,B,C,D,ncon,nmeas,gam);
+DK_ref=[9.0643622,7.5621326;
+-3.4130376,-2.8323139];
+CK_ref=[-9.2274286,27.617295,13.786069,-0.3641854,-21.675515,9.6380172;
+3.661606,-10.657654,-5.2960847,0.2432695,8.1401006,-3.6427294];
+BK_ref=[17.040893,14.216801;
+-18.990171,-15.73011;
+25.296356,21.361546;
+20.185869,16.893822;
+1.4151937,1.2079724;
+5.3371104,4.5307879];
+AK_ref=[-18.066348,52.229142,26.177583,-0.4276594,-41.049028,18.153152;
+18.890371,-57.836295,-29.19831,0.5876879,45.493269,-19.939051;
+-26.692988,78.252232,39.17635,-1.4029006,-60.329721,26.790618;
+-21.491455,62.399041,30.862738,-0.9208084,-48.796168,21.915137;
+-0.8960266,4.2934499,2.3358869,-0.2424272,-3.0488883,1.2220794;
+-5.347976,16.254159,8.5113556,-0.2490600,-12.279774,5.1796586];
+assert_checkalmostequal(AK,AK_ref, 1.e-6 );
+assert_checkalmostequal(BK,BK_ref, 1.e-6 );
+assert_checkalmostequal(CK,CK_ref, 1.e-6 );
+assert_checkalmostequal(DK,DK_ref, 1.e-6 );
diff --git a/scilab/modules/cacsd/tests/unit_tests/dhinf.tst b/scilab/modules/cacsd/tests/unit_tests/dhinf.tst
new file mode 100644 (file)
index 0000000..c7991ca
--- /dev/null
@@ -0,0 +1,59 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - SE - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+A=[-0.7  0    0.3  0   -0.5 -0.1
+   -0.6  0.2 -0.4 -0.3  0    0
+   -0.5  0.7 -0.1  0    0   -0.8
+   -0.7  0    0   -0.5 -1    0
+    0    0.3  0.6 -0.9  0.1 -0.4
+    0.5 -0.8  0    0    0.2 -0.9];
+B=[-1 -2 -2  1  0
+    1  0  1 -2  1
+   -3 -4  0  2 -2
+    1 -2  1  0 -1
+    0  1 -2  0  3
+    1  0  3 -1 -2];
+C=[ 1 -1  2 -2  0 -3
+   -3  0  1 -1  1  0
+    0  2  0 -4  0 -2
+    1 -3  0  0  3  1
+    0  1 -2  1  0 -2];
+D=[1 -1 -2  0  0
+   0  1  0  1  0
+   2 -1 -3  0  1
+   0  1  0  1 -1
+   0  0  1  2  1];
+
+ncon=2
+nmeas=2
+gam=111.30;
+[AK,BK,CK,DK] = dhinf(A,B,C,D,ncon,nmeas,gam);
+
+DK_ref=[9.0643622,7.5621326;
+-3.4130376,-2.8323139];
+
+CK_ref=[-9.2274286,27.617295,13.786069,-0.3641854,-21.675515,9.6380172;
+3.661606,-10.657654,-5.2960847,0.2432695,8.1401006,-3.6427294];
+
+BK_ref=[17.040893,14.216801;
+-18.990171,-15.73011;
+25.296356,21.361546;
+20.185869,16.893822;
+1.4151937,1.2079724;
+5.3371104,4.5307879];
+
+AK_ref=[-18.066348,52.229142,26.177583,-0.4276594,-41.049028,18.153152;
+18.890371,-57.836295,-29.19831,0.5876879,45.493269,-19.939051;
+-26.692988,78.252232,39.17635,-1.4029006,-60.329721,26.790618;
+-21.491455,62.399041,30.862738,-0.9208084,-48.796168,21.915137;
+-0.8960266,4.2934499,2.3358869,-0.2424272,-3.0488883,1.2220794;
+-5.347976,16.254159,8.5113556,-0.2490600,-12.279774,5.1796586];
+
+assert_checkalmostequal(AK,AK_ref, 1.e-6 );
+assert_checkalmostequal(BK,BK_ref, 1.e-6 );
+assert_checkalmostequal(CK,CK_ref, 1.e-6 );
+assert_checkalmostequal(DK,DK_ref, 1.e-6 );
diff --git a/scilab/modules/cacsd/tests/unit_tests/rankqr.dia.ref b/scilab/modules/cacsd/tests/unit_tests/rankqr.dia.ref
new file mode 100644 (file)
index 0000000..05798b2
--- /dev/null
@@ -0,0 +1,23 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - SE - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+A=testmatrix("magi",5);
+[Q,R,JPVT,RANK,SVAL]=rankqr(A,%eps);
+assert_checkequal(RANK, 5);
+assert_checkequal(JPVT, [3,1,4,2,5]);
+assert_checkalmostequal(SVAL, [64.612618,13.836178,13.836178], 1e-6);
+R_ref=[-34.71311,-20.021254,-23.478161,-23.478161,-20.021254;
+0,-25.576344,-11.727155,-15.441525,-17.170139;
+0,0,-20.4022,3.0540446,-9.4882354;
+0,0,0,17.493086,3.6461334;
+0,0,0,0,16.000463];
+assert_checkalmostequal(R, R_ref, 1e-6);
+Q_ref=[-0.0288076,-0.6421260,0.0101293,0.7647199,0.0441038;
+-0.2016529,-0.7414138,-0.0279815,-0.6343960,0.0800023;
+-0.3744983,0.1367641,-0.6279383,0.0707175,0.6646346;
+-0.5473436,0.0374763,-0.4209775,0.0579516,-0.7200208;
+-0.720189,0.1336816,0.6539005,0.0662258,0.1774410];
+assert_checkalmostequal(Q, Q_ref, 1e-5);
diff --git a/scilab/modules/cacsd/tests/unit_tests/rankqr.tst b/scilab/modules/cacsd/tests/unit_tests/rankqr.tst
new file mode 100644 (file)
index 0000000..8297f1f
--- /dev/null
@@ -0,0 +1,25 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - SE - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+A=testmatrix("magi",5);
+[Q,R,JPVT,RANK,SVAL]=rankqr(A,%eps);
+assert_checkequal(RANK, 5);
+assert_checkequal(JPVT, [3,1,4,2,5]);
+assert_checkalmostequal(SVAL, [64.612618,13.836178,13.836178], 1e-6);
+
+R_ref=[-34.71311,-20.021254,-23.478161,-23.478161,-20.021254;
+0,-25.576344,-11.727155,-15.441525,-17.170139;
+0,0,-20.4022,3.0540446,-9.4882354;
+0,0,0,17.493086,3.6461334;
+0,0,0,0,16.000463];
+assert_checkalmostequal(R, R_ref, 1e-6);
+
+Q_ref=[-0.0288076,-0.6421260,0.0101293,0.7647199,0.0441038;
+-0.2016529,-0.7414138,-0.0279815,-0.6343960,0.0800023;
+-0.3744983,0.1367641,-0.6279383,0.0707175,0.6646346;
+-0.5473436,0.0374763,-0.4209775,0.0579516,-0.7200208;
+-0.720189,0.1336816,0.6539005,0.0662258,0.1774410];
+assert_checkalmostequal(Q, Q_ref, 1e-5);
diff --git a/scilab/modules/cacsd/tests/unit_tests/ricc.dia.ref b/scilab/modules/cacsd/tests/unit_tests/ricc.dia.ref
new file mode 100644 (file)
index 0000000..2d30361
--- /dev/null
@@ -0,0 +1,16 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - SE - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+A = [8,8,9;1,8,6;2,5,9];
+B = [0,6;7,8;4,0];
+C = [8,5,5;9,8,1;5,0,7];
+C=C*C';
+R=[2,9; 5,7];
+R=R*R'+eye();
+B=B*inv(R)*B';
+X=ricc(A,B,C,'cont');
+X_ref=[44.84688,2.304207,66.647924;2.304207,27.392655,10.625534;66.647924,10.625534,118.86653];
+assert_checkalmostequal(X, X_ref, 1e-6);
diff --git a/scilab/modules/cacsd/tests/unit_tests/ricc.tst b/scilab/modules/cacsd/tests/unit_tests/ricc.tst
new file mode 100644 (file)
index 0000000..95e2983
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - SE - Sylvestre Ledru
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+A = [8,8,9;1,8,6;2,5,9];
+B = [0,6;7,8;4,0];
+C = [8,5,5;9,8,1;5,0,7];
+
+C=C*C';
+R=[2,9; 5,7];
+
+R=R*R'+eye();
+B=B*inv(R)*B';
+X=ricc(A,B,C,'cont');
+X_ref=[44.84688,2.304207,66.647924;2.304207,27.392655,10.625534;66.647924,10.625534,118.86653];
+assert_checkalmostequal(X, X_ref, 1e-6);