6411a9e0568d875d4985a9f191eabb5242b5288b
[scilab.git] / scilab / modules / cacsd / tests / unit_tests / dscr.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2008 - INRIA - Serge Steer
4 // Copyright (C) 2011 - DIGITEO - Michael Baudin
5 //
6 //  This file is distributed under the same license as the Scilab package.
7 // =============================================================================
8
9
10
11 // Case #1
12 a=-1/3;
13 b=1;
14 c=1;
15 sl=syslin('c',a,b,c);
16 sld=dscr(sl,0.1);
17 assert_checkalmostequal ( sld.dt , 0.1 , %eps );
18 computed = sld.A;
19 expected = exp(sl.A*0.1);
20 assert_checkalmostequal ( computed , expected , %eps );
21 computed = sld.B;
22 expected = sl.A\(sld.A-eye())*sl.B;
23 assert_checkalmostequal ( computed , expected , %eps );
24
25 // Case #2
26 a=[0.9,0,0.6,-1.4,-4.2;
27    0.2,0.1,-0.2,0.5,0.6;
28    -4.3,0,2.2,0,2.4;
29    -3.7,-0.5,2.4,-0.6,2.7;
30    6.4,0.1,-4,-0.5,-4];
31
32 b=[-0.1,-0.1,0;
33    0,0,0.1;
34    -0.1,0.2,-0.1;
35    0.2,0.2,-0.6;
36    0.2,-0.1,0.1];
37  
38 c=[2,7,-2,5,1
39    0,-1,3,0,2];
40 d=[1,0,0
41    0,0,0];
42
43 sl=syslin('c',a,b,c,d);
44 sld=dscr(sl,0.1);
45 assert_checkalmostequal ( sld.dt , 0.1 , %eps );
46 computed = sld.A;
47 expected = expm(sl.A*0.1);
48 assert_checkalmostequal ( computed , expected , %eps );
49 computed = sld.B;
50 expected = sl.A\(sld.A-eye())*sl.B;
51 assert_checkalmostequal ( computed , expected , 2.e5 * %eps );
52