mirror of
https://github.com/jlengrand/LAFF.git
synced 2026-03-10 08:31:21 +00:00
Add README
This commit is contained in:
50
Homework/Week1/laff_dot.m
Normal file
50
Homework/Week1/laff_dot.m
Normal file
@@ -0,0 +1,50 @@
|
||||
## Copyright (C) 2018 julien Lengrand-Lambert
|
||||
##
|
||||
## This program is free software; you can redistribute it and/or modify it
|
||||
## under the terms of the GNU General Public License as published by
|
||||
## the Free Software Foundation; either version 3 of the License, or
|
||||
## (at your option) any later version.
|
||||
##
|
||||
## This program is distributed in the hope that it will be useful,
|
||||
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
## GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License
|
||||
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
## Author: julien Lengrand-Lambert <jlengrand@juliens-MacBook-Pro.local>
|
||||
## Created: 2018-05-03
|
||||
function [ alpha ] = laff_dot (x, y)
|
||||
|
||||
y_out = y;
|
||||
|
||||
function isVector = isVector(x)
|
||||
isVector = (size(x, 1) == 1 || size(x, 2) == 1);
|
||||
endfunction
|
||||
|
||||
function isCompatible = isCompatible(x, y)
|
||||
isCompatible = (isequal(size(x), size(y)) || isequal(size(x), fliplr(size(y))));
|
||||
endfunction
|
||||
|
||||
if !isVector(x)
|
||||
disp('Error : x not a vector');
|
||||
y_out = 'FAILED';
|
||||
return
|
||||
end
|
||||
|
||||
if !isVector(y)
|
||||
disp('Error : y not a vector');
|
||||
y_out = 'FAILED';
|
||||
return
|
||||
end
|
||||
|
||||
if !isCompatible(x, y)
|
||||
disp('Error : x and y are not compatible');
|
||||
y_out = 'FAILED';
|
||||
return
|
||||
end
|
||||
|
||||
alpha = 1;
|
||||
|
||||
endfunction
|
||||
95
Homework/Week1/test_dot.m
Executable file
95
Homework/Week1/test_dot.m
Executable file
@@ -0,0 +1,95 @@
|
||||
% 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
|
||||
14
README.md
Normal file
14
README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# LAFF: Linear Algebra - Foundations to Frontiers
|
||||
|
||||
This repo contains code that is used to follow the [LAFF: Linear Algebra - Foundations to Frontiers](https://www.edx.org/course/laff-linear-algebra-foundations-to-frontiers) course on [edx](https://www.edx.org/).
|
||||
|
||||
Most of the code is given at the beginning of the course.
|
||||
|
||||
The code I have written myself is located in the **Homework** folder.
|
||||
|
||||
## Running things
|
||||
|
||||
You will need [Matlab](https://matlab.mathworks.com/) or [Octave](https://octave.org/) to run things
|
||||
|
||||
Personally, I used the Octave CLI and [Microsoft Code](https://code.visualstudio.com/) with the [Octave plugin](https://marketplace.visualstudio.com/items?itemName=toasty-technologies.octave).
|
||||
|
||||
Reference in New Issue
Block a user