You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lbeckman314 fe068574c6 cs344: updated matrix 2 years ago
example_matrices updated README 2 years ago
helper_scripts organized files 2 years ago
.gitignore updated gitignore 2 years ago
LICENSE Create LICENSE 2 years ago
README.md updated README 2 years ago
date added test file 2 years ago
m1 initial commit to matrix repo 2 years ago
m2 organized files 2 years ago
matrix cs344: updated matrix 2 years ago
matrix.man organized files 2 years ago
matrix.png updated README 2 years ago
p1grading_result cs344: updated matrix 2 years ago
p1gradingscript organized files 2 years ago

README.md

matrix

This program adds, multiplies, transposes, and averages matrices! in action here.



Installation

For an example of installation, see here.

0. Prerequisites

bash :: for running the script.

git :: for a quick git clone.

If you have a propensity against git, check out the alternative installation. In which case wget or curl can be helpful for downloading the necessary files. gpg and sha256sum can be used to verify the integrity of the files.

If you are running Windows, the above utilities will be packaged in any of the following: babun, cmder, or Linux Subsystem for Windows. Take your pick! : )

The above utilities should be installed (or readily available) if you are running a Unix derivative (such as Linux, macOS, or any of the BSD’s).

1. Quickstart

# clone the git repo
git clone https://git.liambeckman.com/cgit/matrix

# enter directory
cd matrix

# allow the script to execute
chmod u+x matrix

# run the script
./matrix add m1 m1


Uninstallation

0. Delete the directory/folder.

rm -rfI matrix



Documentation

(Run man -l matrix.man while in the directory for a basic man page for matrix.)

matrix takes four arguments: add, average, multiply, and transpose. Matrix input (either with files or standard input) must be integers, either positive or negative, separated by white space. Non-numeric characters (including blank elements) will throw an error. Output will be tab-delimited elements.



add

takes two matrices of dimensions `row × col` and `row × col` and produces a sum matrix of dimesions `row × col`. To add two matrices, run `./matrix add m1 m2` where `m1` and `m2` are matrix files.
$ cat mI1
1   2   3   4
5   6   7   8

$ ./matrix add m1 m1
2	4	6	8
10	12	14	16



mean

takes one matrix of dimension `row × col` and averages each of it's columns. Produces an average matrix of dimensions `1 × col`. To add two matrices, run `./matrix transpose m1 ` where `m1` is a matrix file.
$ cat m1
1   2   3   4
5   6   7   8

$ ./matrix mean m1
3	4	5	6



multiply

takes two matrices of dimensions `row₁ × col₁` and `row₂ × col₂` and produces a sum matrix of dimesions `row₁ × col₂`. col₁ must be eqaul to row₂. To add two matrices, run `./matrix multiply m1 m2` where `m1` and `m2` are matrix files.
$ cat m1
1   2   3   4
5   6   7   8

$ cat m2
1	5
2	6
3	7
4	8

$ ./matrix multiply m1 m2
30	70
70	174



transpose

takes one matrix and moves element at position `row × col` to position `col × row`. To add two matrices, run `./matrix transpose m1` where `m1` is a matrix file.
$ cat m1
1   2   3   4
5   6   7   8

$ ./matrix transpose m1
1	5
2	6
3	7
4	8




Examples of valid and invalid matrices:

m4 is a valid matrix

$ cat m4

1   2   3
4   5   6
7   8   9
10  11  12


m5 is an invalid matrix: non-numeric character at position (1, 3).

$ cat m5

1   2   A
4   5   6
7   8   9
10  11  12




m6 is a valid matrix

$ cat m6

1   2
2   3
3   4
4   5


m7 is an invalid matrix: blank character at position (2, 1)

$ cat m7

1   2
    3
3   4
4   5




m8 is a valid matrix

$ cat -A m8

1   2   3$


m9 is an invalid matrix: trailing tab in first row

$ cat m9

1   2   3    $




Alternative Installation

0. Download

Click the tar.gz or zip buttons at the top of the page to download a tar.gz or .zip compressed directory.

Or copy and paste the following command into the terminal to have it download it for you!

wget http://www.liambeckman.com/pkgs/matrix/matrix.tar.gz

# or if you prefer curl:
# curl http://www.liambeckman.com/pkgs/matrix/matrix.tar.gz -o matrix.tar.gz

Optional (but recommended): verify file integrity

#-------------------------------#
# RECIEVE GPG KEYS
#-------------------------------#

gpg --keyserver pgp.mit.edu --recv-keys AC1CC079

#-------------------------------#
# RECIEVE SHA256SUMS
#-------------------------------#

wget http://www.liambeckman.com/pkgs/matrix/sha256sums.txt{,.asc}
# or if you prefer curl:
# curl http://www.liambeckman.com/pkgs/matrix/sha256sums.txt{,.asc} -o sha256sums.txt -o sha256sums.txt.asc

#-------------------------------#
# VERIFY SHA256SUMS
#-------------------------------#

gpg --verify sha256sums.txt.asc

# gpg: Signature made Tue Oct 31 11:11:11 2017 PDT using RSA key ID AC1CC079
# gpg: Good signature from "liam beckman ("I only want to live in peace, plant potatoes, and dream!" -Tove Jansson) <lbeckman314@gmail.com>" [unknown]

#-------------------------------#
# VERIFY FILE INTEGRITY
#-------------------------------#

sha256sum -c sha256sums.txt

# matrix.tar.gz: OK
# matrix.zip: OK

#-------------------------------#
# OPTIONALLY REMOVE PUBLIC KEY
#-------------------------------#

# to remove my public key from your public key ring, simply
gpg --delete-key AC1CC079

1. Extract

tar -zxvf matrix.tar.gz
# or if you downloaded the zip file
# unzip matrix.zip

2. Compile and run

cd matrix

chmod u+x matrix
./matrix add m1 m1


Uninstallation

0. Delete the directory/folder.

rm -rfI matrix