Files
LAFF/Homework/Week1/test_dot.m
Julien Lengrand-Lambert 47ba265501 Add README
2018-05-03 08:22:48 +02:00

95 lines
1.9 KiB
Matlab
Executable File

% Create some vectors
x = [
1
2
3
]
y = [
0
-1
-2
]
z = [
4
3
2
1
]
% test dot product of column vector with column vector
disp( 'dot product of column vector with column vector' )
if ( isequal( laff_dot( x, y ), x' * y ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end
disp( ' ' )
% test dot product of column vector with row vector
disp( 'dot product of column vector with row vector' )
if ( isequal( laff_dot( x, y' ), x' * y ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end
disp( ' ' )
% test dot product of row vector with column vector
disp( 'dot product of row vector with column vector' )
if ( isequal( laff_dot( x', y ), x' * y ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end
disp( ' ' )
% test dot product of row vector with row vector
disp( 'dot product of row vector with row vector' )
if ( isequal( laff_dot( x', y' ), x' * y ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end
disp( ' ' )
% test dot product of column vector with column vector (wrong size)
disp( 'dot product of column vector with column vector (wrong size)' )
if ( isequal( laff_dot( x, z ), 'FAILED' ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end
disp( ' ' )
% test dot product of column vector with row vector (wrong size)
disp( 'dot product of column vector with row vector (wrong size)' )
if ( isequal( laff_dot( x, z' ), 'FAILED' ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end
disp( ' ' )
% test dot product of row vector with column vector (wrong size)
disp( 'dot product of row vector with column vector (wrong size)' )
if ( isequal( laff_dot( x', z ), 'FAILED' ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end
disp( ' ' )
% test dot product of row vector with row vector (wrong size)
disp( 'dot product of row vector with row vector (wrong size)' )
if ( isequal( laff_dot( x', z' ), 'FAILED' ) )
disp( 'TEST PASSED' )
else
disp( 'TEST FAILED' )
end