Safety First

Be careful — this code might be very evil! Only compile and run this program if you trust me and the code herein.

Signed checksums and gpg signatures are included in every package for security. Here is an example of using the GNU Privacy Guard to verify the integrity of a program.

matriz

Add, average, multiply, and transpose matrices like it's going out of style!

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

Give it a Spin




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://github.com/lbeckman314/matriz

# enter directory
cd matriz

# allow the script to execute
chmod u+x matriz

# run the script
./matriz add m1 m1


Uninstallation

0. Delete the directory/folder.

rm -rfI matriz



Documentation

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

matriz takes four arguments: add, average, multiply, and transpose. matriz 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.


The two matrices used in the examples below can be found in the files m1 and m2:

$ cat m1
1   2   3   4
5   6   7   8

$ cat m2
1   5
2   6
3   7
4   8



add takes two matrices of dimensions row × col and row × col and produces a sum matriz of dimesions row × col.

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



mean takes one matriz of dimension row × col and averages each of it’s columns. Produces an average matriz of dimensions 1 × col.

$ ./matriz mean m1
3   4   5   6



multiply takes two matrices of dimensions row₁ × col₁ and row₂ × col₂ and produces a sum matriz of dimesions row₁ × col₂. col₁ must be eqaul to row₂.

$ ./matriz multiply m1 m2
30  70
70  174



transpose takes one matriz and moves element at position row × col to position col × row.

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




Examples of valid and invalid matrices:

m4 is a valid matriz

$ cat m4

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


m5 is an invalid matriz: 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 matriz

$ cat m6

1   2
2   3
3   4
4   5


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

$ cat m7

1   2
    3
3   4
4   5




m8 is a valid matriz

$ cat -A m8

1   2   3$


m9 is an invalid matriz: trailing tab in first row

$ cat -A 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/matriz/matriz.tar.gz

# or if you prefer curl:
# curl http://www.liambeckman.com/pkgs/matriz/matriz.tar.gz -o matriz.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/matriz/sha256sums.txt{,.asc}
# or if you prefer curl:
# curl http://www.liambeckman.com/pkgs/matriz/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 2>/dev/null | grep matriz.tar.gz

# matriz.tar.gz: OK

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

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

1. Extract

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

2. Compile and run

cd matriz

chmod u+x matriz
./matriz add m1 m1


Uninstallation

0. Delete the directory/folder.

rm -rfI matriz