Fixed numerical precision problem in unit test cacsd/dscr : difference between releas...
[scilab.git] / scilab / modules / cacsd / tests / unit_tests / dscr.dia.ref
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) ????-2008 - INRIA - Serge Steer
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7 //
8 // assert_close --
9 //   Returns 1 if the two real matrices computed and expected are close,
10 //   i.e. if the relative distance between computed and expected is lesser than epsilon.
11 // Arguments
12 //   computed, expected : the two matrices to compare
13 //   epsilon : a small number
14 //
15 function flag = assert_close ( computed, expected, epsilon )
16   if expected==0.0 then
17     shift = norm(computed-expected);
18   else
19     shift = norm(computed-expected)/norm(expected);
20   end
21   if shift < epsilon then
22     flag = 1;
23   else
24     flag = 0;
25   end
26   if flag <> 1 then bugmes();quit;end
27 endfunction
28 // Case #1
29 a=-1/3;
30 b=1;
31 c=1;
32 sl=syslin('c',a,b,c);
33 sld=dscr(sl,0.1);
34 assert_close ( sld.dt , 0.1 , %eps );
35 computed = sld.A;
36 expected = exp(sl.A*0.1);
37 assert_close ( computed , expected , %eps );
38 computed = sld.B;
39 expected = sl.A\(sld.A-eye())*sl.B;
40 assert_close ( computed , expected , %eps );
41 // Case #2
42 a=[0.9,0,0.6,-1.4,-4.2;
43    0.2,0.1,-0.2,0.5,0.6;
44    -4.3,0,2.2,0,2.4;
45    -3.7,-0.5,2.4,-0.6,2.7;
46    6.4,0.1,-4,-0.5,-4];
47 b=[-0.1,-0.1,0;
48    0,0,0.1;
49    -0.1,0.2,-0.1;
50    0.2,0.2,-0.6;
51    0.2,-0.1,0.1];
52 c=[2,7,-2,5,1
53    0,-1,3,0,2];
54 d=[1,0,0
55    0,0,0];
56 sl=syslin('c',a,b,c,d);
57 sld=dscr(sl,0.1);
58 assert_close ( sld.dt , 0.1 , %eps );
59 computed = sld.A;
60 expected = expm(sl.A*0.1);
61 assert_close ( computed , expected , %eps );
62 computed = sld.B;
63 expected = sl.A\(sld.A-eye())*sl.B;
64 assert_close ( computed , expected , 1.e3 * %eps );