exalgebra v0.0.4 ExAlgebra.Matrix

Functions that perform computations on matrices.

Summary

Functions

Computes the addition of two matrices. This is a new matrix with entries equal to the sum of the pair of matrices’s corresponding entries. The input matrices should have the same rank.

Examples
iex> ExAlgebra.Matrix.add([[1, 3, 1], [1, 0, 0]], [[0, 0, 5], [7, 5, 0]])
[[1, 3, 6], [8, 5, 0]]

Computes the (i, j) cofactor of a matrix. This is equal to the (i, j) minor of a matrix multiplied by -1 raised to the power of i + j.

Examples
iex> ExAlgebra.Matrix.cofactor( [[2, 3, 4], [1, 0, 0], [3, 4, 5]], 1, 2)
-5.0

Computes the determinant of a matrix. This is computed by summing the cofactors of the matrix multiplied by corresponding elements of the first row.

Examples
iex> ExAlgebra.Matrix.det([[6, 1, 1], [4, -2, 5], [2, 8, 7]])
-306.0

Computes the (i, j) minor of a matrix. This is the determinant of a matrix whose ith row and jth column have been removed.

Examples
iex> ExAlgebra.Matrix.minor( [[2, 3, 4], [1, 0, 0], [3, 4, 5]], 1, 2)
5.0

Computes the multiplication of two matrices. If the rank of matrix A is n x m, then the rank of matrix B must be m x n.

Examples
iex> ExAlgebra.Matrix.multiply([[2, 3, 4], [1, 0, 0]], [[0, 1000], [1, 100], [0, 10]])
[[3, 2340], [0, 1000]]

Computes the rank of a matrix. Both the row rank and the column rank are returned as a map.

Examples
iex> ExAlgebra.Matrix.rank([[1, 2], [3, 4], [4, 3]])
%{rows: 3, columns: 2}

Removes the jth column of a matrix.

Examples
iex> ExAlgebra.Matrix.remove_column([[2, 3, 4], [1, 0, 0], [3, 4, 5]], 2)
[[2, 4], [1, 0], [3, 5]]

Removes the ith row of a matrix.

Examples
iex> ExAlgebra.Matrix.remove_row([[2, 3, 4], [1, 0, 0], [3, 4, 5]], 2)
[[2, 3, 4], [3, 4, 5]]

Computes the multiple of a matrix by a scalar value.

Examples
iex> ExAlgebra.Matrix.scalar_multiply([[1, 3, 1], [1, 0, 0]] , 2.5)
[[2.5, 7.5, 2.5], [2.5, 0.0, 0.0]]

Returns the (i, j) submatrix of a matrix. This is the matrix with the ith row and jth column removed.

Examples
iex> ExAlgebra.Matrix.submatrix([[2, 3, 4], [1, 0, 0], [3, 4, 5]], 2, 3)
[[2, 3], [3, 4]]

Computes the subtraction of two matrices. This is a new matrix with entries equal to the difference of the pair of matrices’s corresponding entries. The input matrices should have the same rank.

Examples
iex> ExAlgebra.Matrix.subtract([[1, 3, 1], [1, 0, 0]], [[0, 0, 5], [7, 5, 0]])
[[1, 3, -4], [-6, -5, 0]]

Computes the the trace of a matrix. This is the sum of the elements down the diagonal of a matrix.

Examples
iex> ExAlgebra.Matrix.trace([[6, 1, 1], [4, -2, 5], [2, 8, 7]])
11

Computes the transpose of a matrix. This is the matrix At built from the matrix A where the entries Aij have been mapped to Aji.

Examples
iex> ExAlgebra.Matrix.transpose([[1, 3, 1], [1, 0, 0]])
[[1, 1], [3, 0], [1, 0]]

Functions

add(list1, list2)

Specs

add([[number]], [[number]]) :: [[number]]

Computes the addition of two matrices. This is a new matrix with entries equal to the sum of the pair of matrices’s corresponding entries. The input matrices should have the same rank.

Examples
iex> ExAlgebra.Matrix.add([[1, 3, 1], [1, 0, 0]], [[0, 0, 5], [7, 5, 0]])
[[1, 3, 6], [8, 5, 0]]
cofactor(matrix, i, j)

Specs

cofactor([[number]], number, number) :: number

Computes the (i, j) cofactor of a matrix. This is equal to the (i, j) minor of a matrix multiplied by -1 raised to the power of i + j.

Examples
iex> ExAlgebra.Matrix.cofactor( [[2, 3, 4], [1, 0, 0], [3, 4, 5]], 1, 2)
-5.0
det(matrix)

Specs

det([[number]]) :: number

Computes the determinant of a matrix. This is computed by summing the cofactors of the matrix multiplied by corresponding elements of the first row.

Examples
iex> ExAlgebra.Matrix.det([[6, 1, 1], [4, -2, 5], [2, 8, 7]])
-306.0
minor(matrix, i, j)

Specs

minor([[number]], number, number) :: number

Computes the (i, j) minor of a matrix. This is the determinant of a matrix whose ith row and jth column have been removed.

Examples
iex> ExAlgebra.Matrix.minor( [[2, 3, 4], [1, 0, 0], [3, 4, 5]], 1, 2)
5.0
multiply(a, b)

Specs

multiply([[number]], [[number]]) :: [[number]]

Computes the multiplication of two matrices. If the rank of matrix A is n x m, then the rank of matrix B must be m x n.

Examples
iex> ExAlgebra.Matrix.multiply([[2, 3, 4], [1, 0, 0]], [[0, 1000], [1, 100], [0, 10]])
[[3, 2340], [0, 1000]]
rank(matrix)

Specs

rank([[number]]) :: map

Computes the rank of a matrix. Both the row rank and the column rank are returned as a map.

Examples
iex> ExAlgebra.Matrix.rank([[1, 2], [3, 4], [4, 3]])
%{rows: 3, columns: 2}
remove_column(matrix, j)

Specs

remove_column([[number]], number) :: [[number]]

Removes the jth column of a matrix.

Examples
iex> ExAlgebra.Matrix.remove_column([[2, 3, 4], [1, 0, 0], [3, 4, 5]], 2)
[[2, 4], [1, 0], [3, 5]]
remove_row(matrix, i)

Specs

remove_row([[number]], number) :: [[number]]

Removes the ith row of a matrix.

Examples
iex> ExAlgebra.Matrix.remove_row([[2, 3, 4], [1, 0, 0], [3, 4, 5]], 2)
[[2, 3, 4], [3, 4, 5]]
scalar_multiply(matrix, scalar)

Specs

scalar_multiply([[number]], number) :: [[number]]

Computes the multiple of a matrix by a scalar value.

Examples
iex> ExAlgebra.Matrix.scalar_multiply([[1, 3, 1], [1, 0, 0]] , 2.5)
[[2.5, 7.5, 2.5], [2.5, 0.0, 0.0]]
submatrix(matrix, i, j)

Specs

submatrix([[number]], number, number) :: [[number]]

Returns the (i, j) submatrix of a matrix. This is the matrix with the ith row and jth column removed.

Examples
iex> ExAlgebra.Matrix.submatrix([[2, 3, 4], [1, 0, 0], [3, 4, 5]], 2, 3)
[[2, 3], [3, 4]]
subtract(list1, list2)

Specs

subtract([[number]], [[number]]) :: [[number]]

Computes the subtraction of two matrices. This is a new matrix with entries equal to the difference of the pair of matrices’s corresponding entries. The input matrices should have the same rank.

Examples
iex> ExAlgebra.Matrix.subtract([[1, 3, 1], [1, 0, 0]], [[0, 0, 5], [7, 5, 0]])
[[1, 3, -4], [-6, -5, 0]]
trace(matrix)

Specs

trace([[number]]) :: number

Computes the the trace of a matrix. This is the sum of the elements down the diagonal of a matrix.

Examples
iex> ExAlgebra.Matrix.trace([[6, 1, 1], [4, -2, 5], [2, 8, 7]])
11
transpose(matrix)

Specs

transpose([[number]]) :: [[number]]

Computes the transpose of a matrix. This is the matrix At built from the matrix A where the entries Aij have been mapped to Aji.

Examples
iex> ExAlgebra.Matrix.transpose([[1, 3, 1], [1, 0, 0]])
[[1, 1], [3, 0], [1, 0]]