Mercurial > hg > ltpda
view m-toolbox/test/test_ao_add.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line source
mc %% Some AOs c1 = ao(1); c1.setName; c2 = ao(2); c2.setName; c3 = ao(3); c3.setName; c4 = ao(randn(3,3)); c4.setName; c5 = ao(randn(3,3)); c5.setName; c6 = ao(randn(3,1)); c6.setName; c7 = ao(randn(1,3)); c7.setName; t1 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 10)); t1.setName; t2 = ao(plist('tsfcn', 'sqrt(t)', 'fs', 10, 'nsecs', 10)); t2.setName; t3 = ao(plist('tsfcn', 't.^2', 'fs', 10, 'nsecs', 10)); t3.setName; f1 = ao(plist('fsfcn', 'f', 'f', 'logspace(-4,1,100)')); f1.setName; f2 = ao(plist('fsfcn', '1./f', 'f', 'logspace(-4,1,100)')); f2.setName; f3 = ao(plist('fsfcn', 'sqrt(f)', 'f', 'logspace(-4,1,100)')); f3.setName; x1 = ao(plist('xyfcn', 'x', 'x', '1:100')); x1.setName; x2 = ao(plist('xyfcn', '1./x', 'x', '1:100')); x2.setName; x3 = ao(plist('xyfcn', 'sqrt(x)', 'x', '1:100')); x3.setName; %% Rule 1 %---------- CDATA % cdata + cdata r1 = plus(c1,c3); % cdata + tsdata r2 = plus(c1,t1); % cdata + fsdata r3 = plus(c1,f1); % cdata + xydata r4 = plus(c1,x1); %---------- TSDATA % tsdata + tsdata r5 = plus(t1, t2); % tsdata + fsdata try r6 = plus(t1, f2); error('Data types should be incompatible: booo!'); catch lasterr warning('Data types not compatible: fsdata+tsdata: hoorah!'); end % tsdata + xydata r7 = plus(t1, x2); % tsdata + cdata r8 = plus(t1, c2); %---------- FSDATA % fsdata + tsdata try r9 = plus(f1, t2); error('Data types should be incompatible: booo!'); catch lasterr warning('Data types not compatible: fsdata+tsdata: hoorah!'); end % fsdata + fsdata r10 = plus(f1, f2); % fsdata + xydata r11 = plus(f1, x2); % fsdata + cdata r12 = plus(f1, c2); %---------- XYDATA % xydata + tsdata r13 = plus(x1, t2); % xydata + fsdata r14 = plus(x1, f2); % xydata + xydata r15 = plus(x1, x2); % xydata + cdata r16 = plus(x1, c2); %% Rule 2: vector + single v = [t1 t2]; s = c2; % one output r1 = plus(v,s) r2 = plus(s,v) % multiple outputs [r1 r2] = plus(v,s) %% Rule 2: vector + number v = [t1 t2]; % one output r1 = plus(v,2) r2 = plus(2,v) %% Rule 3: V_N + V_M v1 = [t1 t2]; v2 = [c1 c2 c3]; try r = plus(v1,v2); error('Rule 3 should fail: booo!'); catch lasterr warning('Rule 3 fails: hoorah!'); end %% Rule 4: V_N + U_N v1 = [t1 t2 t3]; v2 = [x1 x2 x3]; r = plus(v1,v2); [r1 r2 r3] = plus(v1,v2); %% Rule 5: matrix + single m = [t1 t2 t3; x1 x2 x3]; s = c2; r1 = plus(m,s); r2 = plus(s,m); %% Rule 6: matrix + column vector m = [t1 t2 t3; x1 x2 x3]; v = [c1; c2]; r1 = plus(m,v) r2 = plus(v,m) %% Rule 7: matrix + row vector m = [t1 t2 t3; x1 x2 x3]; v = [c1 c2 c3]; r1 = plus(m,v) r2 = plus(v,m) %% Rule 8: M_NP + V_1Q (or V_Q1) m = [t1 t2 t3; x1 x2 x3]; v = [c1 c2]; try r = plus(m,v) error('Rule 8 should fail: booo!'); catch lasterr warning('Rule 8 fails: hoorah!'); end try r = plus(v,m) error('Rule 8 should fail: booo!'); catch lasterr warning('Rule 8 fails: hoorah!'); end m = [t1 t2 t3; x1 x2 x3]; v = [c1; c2; c3]; try r = plus(m,v) error('Rule 8 should fail: booo!'); catch lasterr warning('Rule 8 fails: hoorah!'); end try r = plus(v,m) error('Rule 8 should fail: booo!'); catch lasterr warning('Rule 8 fails: hoorah!'); end %% Rule 9: M_NP + H_PQ m = [t1 t2; x1 x2]; h = [c1 c2 c3; c1 c2 c3]; try r = plus(m,h) error('Rule 9 should fail: booo!'); catch lasterr warning('Rule 9 fails: hoorah!'); end %% Rule 10: matrix + matrix m = [t1 t2 t3; x1 x2 x3]; h = [c1 c2 c3; c1 c2 c3]; r = plus(m,h) %% Rule 11: more than two inputs m = [t1 t2 t3; x1 x2 x3]; v = [c1; c2]; r = plus(m,v, c3, v, m) %% Check units % empty + m = m t1.setYunits('m'); t2.setYunits(''); r = plus(t1,t2) % V + m = error t2.setYunits('V'); try r = plus(t1,t2) error('This unit check should fail: booo!'); catch lasterr warning('The unit check failed: hoorah!'); end