Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_rdivide.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 mc | |
2 | |
3 %% Some AOs | |
4 | |
5 c1 = ao(1); c1.setName; | |
6 c2 = ao(2); c2.setName; | |
7 c3 = ao(3); c3.setName; | |
8 c4 = ao(randn(3,3)); c4.setName; | |
9 c5 = ao(randn(3,3)); c5.setName; | |
10 c6 = ao(randn(3,1)); c6.setName; | |
11 c7 = ao(randn(1,3)); c7.setName; | |
12 | |
13 | |
14 t1 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 10)); t1.setName; | |
15 t2 = ao(plist('tsfcn', 'sqrt(t)', 'fs', 10, 'nsecs', 10)); t2.setName; | |
16 t3 = ao(plist('tsfcn', 't.^2', 'fs', 10, 'nsecs', 10)); t3.setName; | |
17 | |
18 f1 = ao(plist('fsfcn', 'f', 'f', 'logspace(-4,1,100)')); f1.setName; | |
19 f2 = ao(plist('fsfcn', '1./f', 'f', 'logspace(-4,1,100)')); f2.setName; | |
20 f3 = ao(plist('fsfcn', 'sqrt(f)', 'f', 'logspace(-4,1,100)')); f3.setName; | |
21 | |
22 x1 = ao(plist('xyfcn', 'x', 'x', '1:100')); x1.setName; | |
23 x2 = ao(plist('xyfcn', '1./x', 'x', '1:100')); x2.setName; | |
24 x3 = ao(plist('xyfcn', 'sqrt(x)', 'x', '1:100')); x3.setName; | |
25 | |
26 | |
27 %% Rule 1 | |
28 | |
29 %---------- CDATA | |
30 % cdata .* cdata | |
31 r1 = rdivide(c1,c3); | |
32 % cdata .* tsdata | |
33 r2 = rdivide(c1,t1); | |
34 % cdata .* fsdata | |
35 r3 = rdivide(c1,f1); | |
36 % cdata .* xydata | |
37 r4 = rdivide(c1,x1); | |
38 | |
39 %---------- TSDATA | |
40 % tsdata .* tsdata | |
41 r5 = rdivide(t1, t2); | |
42 % tsdata .* fsdata | |
43 try | |
44 r6 = rdivide(t1, f2); | |
45 error('Data types should be incompatible: booo!'); | |
46 catch | |
47 lasterr | |
48 warning('Data types not compatible: fsdata.*tsdata: hoorah!'); | |
49 end | |
50 % tsdata .* xydata | |
51 r7 = rdivide(t1, x2); | |
52 % tsdata .* cdata | |
53 r8 = rdivide(t1, c2); | |
54 | |
55 %---------- FSDATA | |
56 % fsdata .* tsdata | |
57 try | |
58 r9 = rdivide(f1, t2); | |
59 error('Data types should be incompatible: booo!'); | |
60 catch | |
61 lasterr | |
62 warning('Data types not compatible: fsdata.*tsdata: hoorah!'); | |
63 end | |
64 % fsdata .* fsdata | |
65 r10 = rdivide(f1, f2); | |
66 % fsdata .* xydata | |
67 r11 = rdivide(f1, x2); | |
68 % fsdata .* cdata | |
69 r12 = rdivide(f1, c2); | |
70 | |
71 %---------- XYDATA | |
72 % xydata .* tsdata | |
73 r13 = rdivide(x1, t2); | |
74 % xydata .* fsdata | |
75 r14 = rdivide(x1, f2); | |
76 % xydata .* xydata | |
77 r15 = rdivide(x1, x2); | |
78 % xydata .* cdata | |
79 r16 = rdivide(x1, c2); | |
80 | |
81 | |
82 | |
83 | |
84 %% Rule 2: vector .* single | |
85 | |
86 v = [t1 t2]; | |
87 s = c2; | |
88 | |
89 % one output | |
90 r1 = rdivide(v,s) | |
91 r2 = rdivide(s,v) | |
92 | |
93 % multiple outputs | |
94 [r1 r2] = rdivide(v,s) | |
95 | |
96 | |
97 %% Rule 3: V_N .* V_M | |
98 | |
99 v1 = [t1 t2]; | |
100 v2 = [c1 c2 c3]; | |
101 | |
102 try | |
103 r = rdivide(v1,v2); | |
104 error('Rule 3 should fail: booo!'); | |
105 catch | |
106 lasterr | |
107 warning('Rule 3 fails: hoorah!'); | |
108 end | |
109 | |
110 %% Rule 4: V_N .* U_N | |
111 | |
112 v1 = [t1 t2 t3]; | |
113 v2 = [x1 x2 x3]; | |
114 | |
115 r = rdivide(v1,v2); | |
116 [r1 r2 r3] = rdivide(v1,v2); | |
117 | |
118 %% Rule 5: matrix .* single | |
119 | |
120 m = [t1 t2 t3; x1 x2 x3]; | |
121 s = c2; | |
122 | |
123 r1 = rdivide(m,s); | |
124 r2 = rdivide(s,m); | |
125 | |
126 %% Rule 6: matrix .* column vector | |
127 | |
128 m = [t1 t2 t3; x1 x2 x3]; | |
129 v = [c1; c2]; | |
130 | |
131 r1 = rdivide(m,v) | |
132 r2 = rdivide(v,m) | |
133 | |
134 %% Rule 7: matrix .* row vector | |
135 | |
136 m = [t1 t2 t3; x1 x2 x3]; | |
137 v = [c1 c2 c3]; | |
138 | |
139 r1 = rdivide(m,v) | |
140 r2 = rdivide(v,m) | |
141 | |
142 %% Rule 8: M_NP .* V_1Q (or V_Q1) | |
143 | |
144 | |
145 m = [t1 t2 t3; x1 x2 x3]; | |
146 v = [c1 c2]; | |
147 try | |
148 r = rdivide(m,v) | |
149 error('Rule 8 should fail: booo!'); | |
150 catch | |
151 lasterr | |
152 warning('Rule 8 fails: hoorah!'); | |
153 end | |
154 try | |
155 r = rdivide(v,m) | |
156 error('Rule 8 should fail: booo!'); | |
157 catch | |
158 lasterr | |
159 warning('Rule 8 fails: hoorah!'); | |
160 end | |
161 | |
162 m = [t1 t2 t3; x1 x2 x3]; | |
163 v = [c1; c2; c3]; | |
164 try | |
165 r = rdivide(m,v) | |
166 error('Rule 8 should fail: booo!'); | |
167 catch | |
168 lasterr | |
169 warning('Rule 8 fails: hoorah!'); | |
170 end | |
171 try | |
172 r = rdivide(v,m) | |
173 error('Rule 8 should fail: booo!'); | |
174 catch | |
175 lasterr | |
176 warning('Rule 8 fails: hoorah!'); | |
177 end | |
178 | |
179 %% Rule 9: M_NP .* H_PQ | |
180 | |
181 m = [t1 t2; x1 x2]; | |
182 h = [c1 c2 c3; c1 c2 c3]; | |
183 | |
184 try | |
185 r = rdivide(m,h) | |
186 error('Rule 9 should fail: booo!'); | |
187 catch | |
188 lasterr | |
189 warning('Rule 9 fails: hoorah!'); | |
190 end | |
191 | |
192 %% Rule 10: matrix .* matrix | |
193 | |
194 m = [t1 t2 t3; x1 x2 x3]; | |
195 h = [c1 c2 c3; c1 c2 c3]; | |
196 | |
197 r = rdivide(m,h) | |
198 | |
199 %% Rule 11: more than two inputs | |
200 | |
201 m = [t1 t2 t3; x1 x2 x3]; | |
202 v = [c1; c2]; | |
203 | |
204 r = rdivide(m,v, c3, v, m) | |
205 | |
206 %% Check units | |
207 | |
208 | |
209 % empty .* m = m | |
210 t1.setYunits('m'); | |
211 t2.setYunits(''); | |
212 r = rdivide(t1,t2) | |
213 | |
214 % V .* m = mV | |
215 t2.setYunits('V'); | |
216 r = rdivide(t1,t2) | |
217 |