Eigen is a simple CLI that performs matrix and vector operations, modular arithmetic, and basic arithmetic. Eigen is currently a work in progress, so feel free to report any bugs or let me know if you have any suggestions for the program!
- Install Go
$ git clone https://github.com/tbliu/Eigen
$ cd Eigen
$ go run Main.go
- Use
+,-,/,*
to perform basic arithmetic in Eigen as you would normally.
- Eigen supports arithmetic for floating point digits as well as integers
- Use
=
to assign a variable to a value. - Valid value types are:
int, float64, *Matrix
- Variable names follow traditional rules:
- The first character cannot be a number
- All other characters can be either numbers or letters
- Variables are case sensitive
exit, clear, clean
are all reserved key words and cannot be used as variables
- To declare a matrix:
- Use
[
to denote the beginning of the matrix. - Elements within a row are separated by a
,
- Rows are separated by
;
- Use
]
to denote the end of the end of the matrix.
- Use
- Example:
- You can also assign matrices to variables:
x = [1, 2, 1; 4, 3, 1; 0, 2, 1]
creates the same matrix as above, and assigns it to the variablex
.
Vectors do not have a special definition in Eigen. They are simply defined as ℝNx1 matrices. Any references to the word "Vector" or the parameter "*Vector" should just be understood as a matrix with one column.
Command | Description | Return type |
---|---|---|
col(A *Matrix) |
Returns a matrix B whose columns span the column space of A | Matrix |
det(A *Matrix) |
Returns the determinant of a square matrix A | float64 |
id(N int) |
Returns the NxN identity matrix | Matrix |
inv(A *Matrix) |
Returns the inverse of a square matrix A | Matrix |
Lnull(A *Matrix) |
Returns a matrix B whose columns span the left null space of A | Matrix |
null(A *Matrix) |
Returns a matrix B whose columns span the null space of A | Matrix |
nullity(A *Matrix) |
Returns the dimension of the null space of A | int |
rank(A *Matrix) |
Returns the dimension of the column space of A | int |
row(A *Matrix) |
Returns a matrix B whose columns span the row space of A | Matrix |
rref(A *Matrix) |
Returns the reduced row echelon form of a matrix A | Matrix |
solve(A *Matrix, b *Matrix) |
Returns the vector x that solves the system of equations Ax=b | Vector |
transpose(A *Matrix) |
Returns the transpose of a matrix A | Matrix |
zeros(N int) |
Returns the NxN zero matrix | Matrix |
zeros(N int, M int) |
Returns the NxM zero matrix | Matrix |
dot(v *Vector, w *Vector) |
Returns the dot products of vector v and vector w | float64 |
orth(v *Vector, w *Vector) |
Returns 1 if v and w are orthogonal. 0 otherwise | int |
llse(A *Matrix, b *Vector) |
Returns the linear least squares estimate of x in Ax=b |
Vector |
proj(v *Vector, w *Vector) |
Returns the projection of the vector w onto the vector v | Vector |
gs(A *Matrix) |
Orthonormalizes the columns of A | Matrix |
qr(A *Matrix, tag string) |
Performs QR decomposition on A. If tag == 'q', Q. If tag == 'r', return R. Quotes are not necessary. | Matrix |
norm(v *Vector) |
Returns a vector w, which is the normalized version of v | Vector |
roll(v *Vector, N int) |
Returns a vector w, whose values are the same as v's, shifted by N places | Vector |
xcorr(v *Vector, w *Vector) |
Returns the cross-correlation of w with respect to v | Vector |
autocorr(v *Vector) |
Returns the auto-correlation of v | Vector |
Command | Description | Return type |
---|---|---|
mod(x int, m int) |
Returns x modulo m | int |
modexp(x int, y int, m int) |
Returns x to the power of y modulo m. Uses repeated squaring, so this function works well with large ints. | int |
modinv(x int, m int) |
Returns the inverse of x modulo m. | int |
Command | Description | Return type |
---|---|---|
gcd(x int, y int) |
Returns the greatest common divisor of x and y | int |
sqrt(x float64) |
Returns the square root of a number up to 3 decimal points | float64 |
exit |
Exits the program | None |
clear |
Clears the terminal window | None |
clean |
Removes all variable assignments | None |
- Incomplete arithmetic queries (ex:
3*
) cause Eigen to panic (Index out of range error) - There are some bugs with matrix operations when not using variables (ex: [3,2] * [3,1;1,2] returns an ERROR message. But assigning A=[3,2] and B = [3,1;1,2] and doing A*B works).
- Changing color to white after a red error message might make text invisible to people with white terminal backgrounds. Fix so it gets default terminal color
- When subtracting with negative numbers, Eigen sometimes processes a negative number as a variable (ex: -3-4 returns "ERROR: Invalid variable '-3'")