damp function added in CACSD module
[scilab.git] / scilab / modules / cacsd / tests / unit_tests / damp.dia.ref
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 R=[2 1+%i  2-3*%i];
9 [wn,zeta]=damp(R);
10 assert_checkequal (wn,abs(R));
11 assert_checkequal (zeta,-real(R)./wn);
12 dt=1;
13 [wn,zeta]=damp(R,dt);
14 Rd=log(R)/dt;
15 assert_checkequal (wn,abs(Rd));
16 assert_checkequal (zeta,-real(Rd)./wn);
17 R=0;
18 [wn,zeta]=damp(R);
19 assert_checkequal (wn,0);
20 assert_checkequal (zeta,-1);
21 R=0;dt=1;
22 [wn,zeta]=damp(R,dt);
23 assert_checkequal (wn,%inf);
24 assert_checkequal (zeta,%nan);
25 R=1;dt=1;
26 [wn,zeta]=damp(R,dt);
27 assert_checkequal (wn,0);
28 assert_checkequal (zeta,-1);
29 R=1;
30 [wn,zeta]=damp(R);
31 assert_checkequal (wn,1);
32 assert_checkequal (zeta,-1);
33 //Polynomial and Polynomial array
34 P=real([poly([2 1+%i 1-%i  2-3*%i 2+3*%i],'s'),poly(0,'s'),poly(1,'s')]);
35 [wn,zeta]=damp(P);
36 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
37 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
38 assert_checkalmostequal (wn,wnref);
39 assert_checkalmostequal (zeta,zetaref);
40 [wn,zeta]=damp(prod(P));
41 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
42 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
43 assert_checkalmostequal (wn,wnref);
44 assert_checkalmostequal (zeta,zetaref);
45 dt=1;
46 [wn,zeta]=damp(P,dt);
47 t1=log(1+%i)/dt;
48 t2=log(2-3*%i)/dt;
49 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
50 zetaref=[-1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
51 assert_checkalmostequal (wn,wnref);
52 assert_checkalmostequal (zeta,zetaref);
53 dt=1;
54 [wn,zeta]=damp(prod(P),dt);
55 t1=log(1+%i)/dt;
56 t2=log(2-3*%i)/dt;
57 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
58 zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
59 assert_checkalmostequal (wn,wnref);
60 assert_checkalmostequal (zeta,zetaref);
61 //transfer function
62 [wn,zeta]=damp(syslin('c',ones(1,3),P));
63 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
64 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
65 assert_checkalmostequal (wn,wnref);
66 assert_checkalmostequal (zeta,zetaref);
67 dt=1;
68 [wn,zeta]=damp(syslin(dt,ones(1,3),P));
69 t1=log(1+%i)/dt;
70 t2=log(2-3*%i)/dt;
71 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
72 zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
73 assert_checkalmostequal (wn,wnref);
74 assert_checkalmostequal (zeta,zetaref);
75 //state-space
76 [wn,zeta]=damp(tf2ss(syslin('c',1,prod(P))));
77 wnref=[0;1;sqrt(2);sqrt(2);2;sqrt(13);sqrt(13)];
78 zetaref=[-1;-1;-sqrt(2)/2;-sqrt(2)/2;-1;-2/sqrt(13);-2/sqrt(13)];
79 assert_checkalmostequal (wn,wnref);
80 assert_checkalmostequal (zeta,zetaref);
81 dt=1;
82 [wn,zeta]=damp(tf2ss(syslin(dt,1,prod(P))));
83 t1=log(1+%i)/dt;
84 t2=log(2-3*%i)/dt;
85 wnref=[0;log(2);abs(t1);abs(t1);abs(t2);abs(t2);%inf];
86 zetaref=[1;-1;-real(t1)/abs(t1);-real(t1)/abs(t1);-real(t2)/abs(t2);-real(t2)/abs(t2);%nan];
87 assert_checkalmostequal (wn,wnref) ;
88 assert_checkalmostequal (zeta,zetaref) ;
89 //invalid calls
90 assert_checkfalse(execstr("[wn,zeta]=damp()","errcatch")==0);
91 assert_checkfalse(execstr("[wn,zeta]=damp(%t)","errcatch")==0);
92 assert_checkfalse(execstr("[wn,zeta]=damp(P,1:3)","errcatch")==0);
93 assert_checkfalse(execstr("[wn,zeta]=damp(P,%t)","errcatch")==0);