comparison m-toolbox/test/test_ao_mtimes.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
4 %% Some AOs
5
6 c1 = ao(1); c1.setName;
7 c2 = ao(2); c2.setName;
8 c3 = ao(3); c3.setName;
9 c4 = ao(randn(3,3)); c4.setName;
10 c5 = ao(randn(3,3)); c5.setName;
11 c6 = ao(randn(3,1)); c6.setName;
12 c7 = ao(randn(1,3)); c7.setName;
13
14
15 t1 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 10)); t1.'; t1.setName;
16 t2 = ao(plist('tsfcn', 'sqrt(t)', 'fs', 10, 'nsecs', 10)); t2.setName;
17 t3 = ao(plist('tsfcn', 't.^2', 'fs', 10, 'nsecs', 10)); t3.setName;
18 t4 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 10)); t4.'; t4.setName;
19 t5 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 10)); t5.'; t5.setName;
20
21 f1 = ao(plist('fsfcn', 'f', 'f', 'logspace(-4,1,100)')); f1.setName;
22 f2 = ao(plist('fsfcn', '1./f', 'f', 'logspace(-4,1,100)')); f2.'; f2.setName;
23 f3 = ao(plist('fsfcn', 'sqrt(f)', 'f', 'logspace(-4,1,100)')); f3.setName;
24
25 x1 = ao(plist('xyfcn', 'x', 'x', '1:100')); x1.setName;
26 x2 = ao(plist('xyfcn', '1./x', 'x', '1:100')); x2.'; x2.setName;
27 x3 = ao(plist('xyfcn', 'sqrt(x)', 'x', '1:100')); x3.setName;
28
29 %% Rule 1: [1x1] * [1x1]
30
31 %---------- CDATA
32 % cdata * cdata
33 r1 = mtimes(c1,c3)
34 % cdata * tsdata
35 r2 = mtimes(c2,t1)
36 % cdata * fsdata
37 r3 = mtimes(c1,f1)
38 % cdata * xydata
39 r4 = mtimes(c1,x1)
40
41 %---------- TSDATA
42 % tsdata * tsdata
43 r5 = mtimes(t1, t2)
44 % tsdata * fsdata
45 try
46 r6 = mtimes(t1, f2)
47 error('Data types should be incompatible: booo!');
48 catch
49 lasterr
50 warning('Data types not compatible: fsdata*tsdata: hoorah!');
51 end
52 % xydata * tsdata
53 r7 = mtimes(x1, t2)
54 % tsdata * cdata
55 r8 = mtimes(t1, c2)
56
57 %---------- FSDATA
58 % fsdata * tsdata
59 try
60 r9 = mtimes(f1, t2)
61 error('Data types should be incompatible: booo!');
62 catch
63 lasterr
64 warning('Data types not compatible: fsdata+tsdata: hoorah!');
65 end
66 % fsdata * fsdata
67 r10 = mtimes(f1, f2)
68 % fsdata * xydata
69 r11 = mtimes(f1, x2)
70 % fsdata * cdata
71 r12 = mtimes(f1, c2)
72
73 %---------- XYDATA
74 % xydata * tsdata
75 r13 = mtimes(x1, t2)
76 % xydata * fsdata
77 r14 = mtimes(x1, f2)
78 % xydata * xydata
79 r15 = mtimes(x1, x2)
80 % xydata * cdata
81 r16 = mtimes(x1, c2)
82
83 %% Rule 2: [1xN] * a or [Nx1] * a
84
85 v1 = [t1 t3];
86 v2 = [t1; t3];
87
88 r1 = mtimes(v1,c1)
89 r2 = mtimes(v2,c1)
90
91 %% Rule 3: [1xN] * [Nx1]
92
93 v1 = [t1 t1];
94 v2 = [t3; t2];
95
96 r1 = mtimes(v1,v2)
97
98 %% Rule 4: [1xN] * [1xN]
99
100 v1 = [t1 t1];
101
102 try
103 r1 = mtimes(v1,v1)
104 error('Sizes should be incompatible: booo!');
105 catch
106 lasterr
107 warning('Sizes not compatible: hoorah!');
108 end
109
110 %% Rule 5: [Nx1] * [1xM]
111
112 v1 = [t1;t4;t5];
113 v2 = [t2 t3];
114
115 r = mtimes(v1,v2)
116
117 %% Rule 6: [Nx1] * [Nx1]
118
119 v1 = [t1;t4;t5];
120
121 try
122 r1 = mtimes(v1,v1)
123 error('Sizes should be incompatible: booo!');
124 catch
125 lasterr
126 warning('Sizes not compatible: hoorah!');
127 end
128
129 %% Rule 7: [NxP] * [Nx1]
130
131 m = [t1 t1;t4 t4;t5 t5];
132 v = [t1;t2;t3]
133
134 try
135 r1 = mtimes(m,v)
136 error('Sizes should be incompatible: booo!');
137 catch
138 lasterr
139 warning('Sizes not compatible: hoorah!');
140 end
141
142 %% but [2x2] * [2 1] should work
143 m = [t1 t1; t4 t4];
144 v = [t2;t3];
145
146 r1 = mtimes(m,v);
147
148
149 %% Rule 8: [NxP] * [1xP]
150
151 m = [t1 t1;t4 t4;t5 t5];
152 v = [t2 t2]
153
154
155 try
156 r1 = mtimes(m,v)
157 error('Sizes should be incompatible: booo!');
158 catch
159 lasterr
160 warning('Sizes not compatible: hoorah!');
161 end
162
163 %% Rule 9: [NxP] * [NxP]
164
165 m = [t1 t1;t4 t4;t5 t5];
166
167
168 try
169 r1 = mtimes(m,m)
170 error('Sizes should be incompatible: booo!');
171 catch
172 lasterr
173 warning('Sizes not compatible: hoorah!');
174 end
175
176 %% Rule 10: [NxP] * [P*Q]
177
178 m1 = [t1 t1;t4 t4;t5 t5];
179 m2 = [t2 t2 t3; t3 t2 t3];
180
181 r1 = mtimes(m1,m2)
182
183
184
185
186
187
188
189
190
191