exalgebra v0.0.2 ExAlgebra.Matrix

ExAlgebra.Matrix contains functions used in matrix algebra.

Summary

Functions

Returns the addition of two matrices. ## Examples

Returns the (i, j) cofactor of a matrix. ## Examples

Returns the determinant of a matrix. ## Examples

Returns the (i, j) minor of a matrix. ## Examples

iex> matrix = [[2, 3, 4], [1, 0, 0], [3, 4, 5]]
[[2, 3, 4], [1, 0, 0], [3, 4, 5]]

Returns the multiplication of two matrices. ## Examples

Removes the ith column of a matrix. ## Examples

Removes the ith row of a matrix. ## Examples

Returns the multiple of a matrix by a scalar. ## Examples

Returns the size of a matrix. ## Examples

Returns the (i, j) submatrix of a 3 x 3 matrix. ## Examples

Returns the subtraction of two matrices. ## Examples

Returns the trace of a matrix. ## Examples

iex> matrix = [[6, 1, 1], [4, -2, 5], [2, 8, 7]]
[[6, 1, 1], [4, -2, 5], [2, 8, 7]]

Returns the transpose of a matrix. ## Examples

Functions

add(list1, list2)

Specs

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

Returns the addition of two matrices. ## Examples

iex> matrix = [[1, 3, 1], [1, 0, 0]]
[[1, 3, 1], [1, 0, 0]]

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

Specs

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

Returns the (i, j) cofactor of a matrix. ## Examples

iex> matrix = [[2, 3, 4], [1, 0, 0], [3, 4, 5]]
[[2, 3, 4], [1, 0, 0], [3, 4, 5]]

iex> matrix |> ExAlgebra.Matrix.cofactor(1, 2)
-5
det(matrix)

Specs

det([[number]]) :: number

Returns the determinant of a matrix. ## Examples

iex> matrix = [[6, 1, 1], [4, -2, 5], [2, 8, 7]]
[[6, 1, 1], [4, -2, 5], [2, 8, 7]]

iex> matrix |> ExAlgebra.Matrix.det
-306
minor(matrix, i, j)

Specs

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

Returns the (i, j) minor of a matrix. ## Examples

iex> matrix = [[2, 3, 4], [1, 0, 0], [3, 4, 5]]
[[2, 3, 4], [1, 0, 0], [3, 4, 5]]

iex> matrix |> ExAlgebra.Matrix.minor(1, 2)
5
multiply(matrix_one, matrix_two)

Specs

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

Returns the multiplication of two matrices. ## Examples

iex> matrix = [[2, 3, 4], [1, 0, 0]]
[[2, 3, 4], [1, 0, 0]]

iex> matrix |> ExAlgebra.Matrix.multiply [[0, 1000], [1, 100], [0, 10]]
[[3, 2340], [0, 1000]]
remove_column(matrix, index)

Specs

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

Removes the ith column of a matrix. ## Examples

iex> matrix = [[2, 3, 4], [1, 0, 0], [3, 4, 5]]
[[2, 3, 4], [1, 0, 0], [3, 4, 5]]

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

Specs

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

Removes the ith row of a matrix. ## Examples

iex> matrix = [[2, 3, 4], [1, 0, 0], [3, 4, 5]]
[[2, 3, 4], [1, 0, 0], [3, 4, 5]]

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

Specs

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

Returns the multiple of a matrix by a scalar. ## Examples

iex> matrix = [[1, 3, 1], [1, 0, 0]]
[[1, 3, 1], [1, 0, 0]]

iex> matrix |> ExAlgebra.Matrix.scalar_multiply 2.5
[[2.5, 7.5, 2.5], [2.5, 0, 0]]
size(matrix)

Specs

size([[number]]) :: map

Returns the size of a matrix. ## Examples

iex> matrix = [[1, 2], [3, 4], [4, 3]]
[[1, 2], [3, 4], [4, 3]]

iex> matrix |> ExAlgebra.Matrix.size
%{rows: 3, columns: 2}
submatrix(matrix, i, j)

Specs

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

Returns the (i, j) submatrix of a 3 x 3 matrix. ## Examples

iex> matrix = [[2, 3, 4], [1, 0, 0], [3, 4, 5]]
[[[2, 3, 4], [1, 0, 0], [3, 4, 5]]

iex> matrix |> ExAlgebra.Matrix.submatrix(2, 3)
[[2, 3], [3, 4]]
subtract(list1, list2)

Specs

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

Returns the subtraction of two matrices. ## Examples

iex> matrix = [[1, 3, 1], [1, 0, 0]]
[[1, 3, 1], [1, 0, 0]]

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

Specs

trace([[number]]) :: number

Returns the trace of a matrix. ## Examples

iex> matrix = [[6, 1, 1], [4, -2, 5], [2, 8, 7]]
[[6, 1, 1], [4, -2, 5], [2, 8, 7]]

iex> matrix |> ExAlgebra.Matrix.trace
11
transpose(matrix)

Specs

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

Returns the transpose of a matrix. ## Examples

iex> matrix = [[1, 3, 1], [1, 0, 0]]
[[1, 3, 1], [1, 0, 0]]

iex> matrix |> ExAlgebra.Matrix.transpose
[[1, 0], [2, -6], [3, 7]]