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

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

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]]
det(a)
det([[number]]) :: number

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
diagonal(a)
diagonal([[number]]) :: [number]

Returns a list of the matrix diagonal elements.

Examples

iex> Matrix.diagonal([[1, 3, 5],
...>                  [2, 4, 7],
...>                  [1, 1, 0]])
[1, 4, 0]
dim(a)
dim([[number]]) :: {integer, integer}

Returns a tuple with the matrix dimensions as {rows, cols}.

Examples

Matrix.dim([[1, 1, 1],
...>        [2, 2, 2]])
{2, 3}
hadmard(a, b)
hadmard([[number]], [[number]]) :: [[number]]

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]]
identity(n)
identity(number) :: [[number]]

Returns an identity matrix with the provided dimension.

Examples

iex> Matrix.identity(3)
[[1, 0, 0],
 [0, 1, 0],
 [0, 0, 1]]
lu(a)
lu([[number]]) :: {[[number]], [[number]], [[number]]}

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]]}
mult(v, b)
mult([number], [[number]]) :: [[number]]

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]]
new(n, m)
new(number, number) :: [[number]]

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]]
pivot(a, n, m)
pivot([[number]], number, number) :: [[number]]

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]]
reduce(a)
reduce([[number]]) :: [[number]]

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]]
scalar(a, s)
scalar([[number]], number) :: [[number]]

Elementwise mutiplication with a scalar.

Examples

iex> Matrix.scalar([[2, 2, 2],
...>                [1, 1, 1]], 2)
[[4, 4, 4],
 [2, 2, 2]]
sub(a, b)
sub([[number]], [[number]]) :: [[number]]

Performs elementwise subtraction

Examples

iex> Matrix.sub([[1, 2, 3],
...>             [1, 2, 2]],
...>            [[1, 2, 3],
...>             [2, 2, 2]])
[[0, 0, 0],
 [-1, 0, 0]]
transp(a)
transp([[number]]) :: [[number]]

Transposes a matrix.

Examples

iex> Matrix.transp([[1, 2, 3], [4, 5, 6]])
[[1, 4],
 [2, 5],
 [3, 6]]