This program adds, multiplies, transposes, and averages matrices! in action here.
For an example of installation, see here.
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).
# clone the git repo
git clone https://git.liambeckman.com/cgit/matriz
# enter directory
cd matriz
# allow the script to execute
chmod u+x matriz.sh
# run the script
./matriz.sh add m1 m1
rm -rfI matriz
(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.
add
takes two matrices of dimensions row × col
and row × col
and produces a sum matriz of dimesions row × col
. To add two matrices, run ./matriz.sh add m1 m2
where m1
and m2
are matriz files.
$ cat mI1
1 2 3 4
5 6 7 8
$ ./matriz.sh 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
. To add two matrices, run ./matriz.sh transpose m1
where m1
is a matriz file.
$ cat m1
1 2 3 4
5 6 7 8
$ ./matriz.sh 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₂. To add two matrices, run ./matriz.sh multiply m1 m2
where m1
and m2
are matriz files.
$ cat m1
1 2 3 4
5 6 7 8
$ cat m2
1 5
2 6
3 7
4 8
$ ./matriz.sh multiply m1 m2
30 70
70 174
transpose
takes one matriz and moves element at position row × col
to position col × row
. To add two matrices, run ./matriz.sh transpose m1
where m1
is a matriz file.
$ cat m1
1 2 3 4
5 6 7 8
$ ./matriz.sh transpose m1
1 5
2 6
3 7
4 8
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 $
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
#-------------------------------#
# 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
# matriz.tar.gz: OK
# matriz.zip: OK
#-------------------------------#
# OPTIONALLY REMOVE PUBLIC KEY
#-------------------------------#
# to remove my public key from your public key ring, simply
gpg --delete-key AC1CC079
tar -zxvf matriz.tar.gz
# or if you downloaded the zip file
# unzip matriz.zip
cd matriz
chmod u+x matriz
./matriz add m1 m1
rm -rfI matriz