elixir_linear_algebra v1.0.0 ELA.Matrix
Contains operations for working with matrices.
Summary
Functions
Performs elmentwise addition
Returns the determinat of the matrix. Uses LU-decomposition to calculate it
Returns a list of the matrix diagonal elements
Returns a tuple with the matrix dimensions as {rows, cols}
Elementwise multiplication with two matrices. This is known as the Hadmard product
Returns an identity matrix with the provided dimension
Returns an LU-decomposition on Crout’s form with the permutation matrix used on the form {l, u, p}
Matrix multiplication. Can also multiply matrices with vectors. Always returns a matrix
Returns a matrix filled wiht zeroes as with n rows and m columns
Pivots them matrix a on the element on row n, column m (zero indexed). Pivoting performs row operations to make the pivot element 1 and all others in the same column 0
Returns a row equivalent matrix on reduced row echelon form
Elementwise mutiplication with a scalar
Performs elementwise subtraction
Transposes a matrix
Functions
Performs elmentwise addition
Examples
iex> Matrix.add([[1, 2, 3],
...> [1, 1, 1]],
...> [[1, 2, 2],
...> [1, 2, 1]])
[[2, 4, 5],
[2, 3, 2]]
Returns the determinat of the matrix. Uses LU-decomposition to calculate it.
Examples
iex> Matrix.det([[1, 3, 5],
...> [2, 4, 7],
...> [1, 1, 0]])
4
Returns a list of the matrix diagonal elements.
Examples
iex> Matrix.diagonal([[1, 3, 5],
...> [2, 4, 7],
...> [1, 1, 0]])
[1, 4, 0]
Returns a tuple with the matrix dimensions as {rows, cols}.
Examples
Matrix.dim([[1, 1, 1],
...> [2, 2, 2]])
{2, 3}
Elementwise multiplication with two matrices. This is known as the Hadmard product.
Examples
iex> Matrix.hadmard([[1, 2],
...> [1, 1]],
...> [[1, 2],
...> [0, 2]])
[[1, 4],
[0, 2]]
Returns an identity matrix with the provided dimension.
Examples
iex> Matrix.identity(3)
[[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]
Returns an LU-decomposition on Crout’s form with the permutation matrix used on the form {l, u, p}.
Examples
iex> Matrix.lu([[1, 3, 5],
...> [2, 4, 7],
...> [1, 1, 0]])
{[[1, 0, 0],
[0.5, 1, 0],
[0.5, -1, 1]],
[[2, 4, 7],
[0, 1.0, 1.5],
[0, 0, -2.0]]
[[0, 1, 0],
[1, 0, 0],
[0, 0, 1]]}
Matrix multiplication. Can also multiply matrices with vectors. Always returns a matrix.
Examples
iex> Matrix.mult([1, 1],
...> [[1, 0, 1],
...> [1, 1, 1]])
[[2, 1, 2]]
iex> Matrix.mult([[1, 0, 1],
...> [1, 1, 1]],
...> [[1],
...> [1],
...> [1]])
[[2],
[3]]
Returns a matrix filled wiht zeroes as with n rows and m columns.
Examples
iex> Matrix.new(3, 2)
[[0, 0],
[0, 0],
[0, 0]]
Pivots them matrix a on the element on row n, column m (zero indexed). Pivoting performs row operations to make the pivot element 1 and all others in the same column 0.
Examples
iex> Matrix.pivot([[2.0, 3.0],
...> [2.0, 3.0],
...> [3.0, 6.0]], 1, 0)
[[0.0, 0.0],
[1.0, 1.5],
[0.0, 1.5]]
Returns a row equivalent matrix on reduced row echelon form.
Examples
iex> Matrix.reduce([[1.0, 1.0, 2.0, 1.0],
...> [2.0, 1.0, 6.0, 4.0],
...> [1.0, 2.0, 2.0, 3.0]])
[[1.0, 0.0, 0.0, -5.0],
[0.0, 1.0, 0.0, 2.0],
[0.0, 0.0, 1.0, 2.0]]
Elementwise mutiplication with a scalar.
Examples
iex> Matrix.scalar([[2, 2, 2],
...> [1, 1, 1]], 2)
[[4, 4, 4],
[2, 2, 2]]