damp function added in CACSD module
[scilab.git] / scilab / modules / cacsd / tests / unit_tests / damp.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2001 - INRIA - Serge Steer
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7 //Vector of complex numbers
8
9 R=[2 1+%i  2-3*%i];
10 [wn,zeta]=damp(R);
11 assert_checkequal (wn,abs(R));
12 assert_checkequal (zeta,-real(R)./wn);
13
14 dt=1;
15 [wn,zeta]=damp(R,dt);
16 Rd=log(R)/dt;
17 assert_checkequal (wn,abs(Rd));
18 assert_checkequal (zeta,-real(Rd)./wn);
19
20 R=0;
21 [wn,zeta]=damp(R);
22 assert_checkequal (wn,0);
23 assert_checkequal (zeta,-1);
24
25 R=0;dt=1;
26 [wn,zeta]=damp(R,dt);
27 assert_checkequal (wn,%inf);
28 assert_checkequal (zeta,%nan);
29
30 R=1;dt=1;
31 [wn,zeta]=damp(R,dt);
32 assert_checkequal (wn,0);
33 assert_checkequal (zeta,-1);
34
35 R=1;
36 [wn,zeta]=damp(R);
37 assert_checkequal (wn,1);
38 assert_checkequal (zeta,-1);
39
40 //Polynomial and Polynomial array
41 P=real([poly([2 1+%i 1-%i  2-3*%i 2+3*%i],'s'),poly(0,'s'),poly(1,'s')]);
42 [wn,zeta]=damp(P);
43 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
44 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
45 assert_checkalmostequal (wn,wnref);
46 assert_checkalmostequal (zeta,zetaref);
47
48 [wn,zeta]=damp(prod(P));
49 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
50 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
51 assert_checkalmostequal (wn,wnref);
52 assert_checkalmostequal (zeta,zetaref);
53
54 dt=1;
55 [wn,zeta]=damp(P,dt);
56 t1=log(1+%i)/dt;
57 t2=log(2-3*%i)/dt;
58 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
59 zetaref=[-1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
60 assert_checkalmostequal (wn,wnref);
61 assert_checkalmostequal (zeta,zetaref);
62
63 dt=1;
64 [wn,zeta]=damp(prod(P),dt);
65 t1=log(1+%i)/dt;
66 t2=log(2-3*%i)/dt;
67 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
68 zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
69 assert_checkalmostequal (wn,wnref);
70 assert_checkalmostequal (zeta,zetaref);
71
72 //transfer function
73 [wn,zeta]=damp(syslin('c',ones(1,3),P));
74 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
75 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
76 assert_checkalmostequal (wn,wnref);
77 assert_checkalmostequal (zeta,zetaref);
78
79 dt=1;
80 [wn,zeta]=damp(syslin(dt,ones(1,3),P));
81 t1=log(1+%i)/dt;
82 t2=log(2-3*%i)/dt;
83 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
84 zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
85 assert_checkalmostequal (wn,wnref);
86 assert_checkalmostequal (zeta,zetaref);
87
88 //state-space
89 [wn,zeta]=damp(tf2ss(syslin('c',1,prod(P))));
90 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
91 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
92 assert_checkalmostequal (wn,wnref);
93 assert_checkalmostequal (zeta,zetaref);
94
95 dt=1;
96 [wn,zeta]=damp(tf2ss(syslin(dt,1,prod(P))));
97 t1=log(1+%i)/dt;
98 t2=log(2-3*%i)/dt;
99 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
100 zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
101 assert_checkalmostequal (wn,wnref) ;
102 assert_checkalmostequal (zeta,zetaref) ;
103
104 //invalid calls
105 assert_checkfalse(execstr("[wn,zeta]=damp()","errcatch")==0);
106 assert_checkfalse(execstr("[wn,zeta]=damp(%t)","errcatch")==0);
107 assert_checkfalse(execstr("[wn,zeta]=damp(P,1:3)","errcatch")==0);
108 assert_checkfalse(execstr("[wn,zeta]=damp(P,%t)","errcatch")==0);