numeric v0.0.1 Elyanah.Numeric.Matrix
Matrix operations on Elixir Lists of Lists.
Summary
Functions
Elementwise add matrix a
to matrix b
Divide matrix a
by matrix b
Build an identity matrix of the given size
Return the inverse of a matrix if invertible. Otherwise return nil
Multiply matrices a
and b
Raise the matrix
to the given power
Elementwise subtract matrix a
from matrix b
Calculate the transpose of a matrix
Functions
Elementwise add matrix a
to matrix b
Examples
iex> Elyanah.Numeric.Matrix.add([[1,2],[3,4]],[[1,2],[3,4]])
[[2, 4], [6, 8]]
Divide matrix a
by matrix b
Examples
iex> Elyanah.Numeric.Matrix.divide([[1,2],[3,4]],[[1,2],[3,4]])
[[1.0, 0.0], [0.0, 1.0]]
Build an identity matrix of the given size
.
Examples
iex> Elyanah.Numeric.Matrix.identity(4)
[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
Return the inverse of a matrix if invertible. Otherwise return nil.
Examples
iex> ai = (a = [[1,2,3],[4,5,6],[7,8,9]]) |> Elyanah.Numeric.Matrix.inverse
nil
iex> ai = (a = [[1,2,3],[4,5,6],[7,8,10]]) |> Elyanah.Numeric.Matrix.inverse
[[-0.6666666666666665, -1.3333333333333335, 1.0],
[-0.6666666666666667, 3.6666666666666665, -2.0], [1.0, -2.0, 1.0]]
iex> Elyanah.Numeric.Matrix.multiply(ai, a) == Elyanah.Numeric.Matrix.identity(length(a))
true
Multiply matrices a
and b
.
Examples
iex> Elyanah.Numeric.Matrix.multiply([[1,2],[3,4],[5,6]],[[1,2,3],[4,5,6]])
[[9, 12, 15], [19, 26, 33], [29, 40, 51]]
Raise the matrix
to the given power
Examples
iex> Elyanah.Numeric.Matrix.power([[1,2,3],[4,5,6],[7,8,9]], 10)
[[132476037840, 162775103256, 193074168672],
[300005963406, 368621393481, 437236823556],
[467535888972, 574467683706, 681399478440]]
iex> Elyanah.Numeric.Matrix.power([[1,2,3],[4,5,6],[7,8,9]], 1)
[[1, 2, 3], [4, 5, 6], '\a\b\t']
iex> Elyanah.Numeric.Matrix.power([[1,2,3],[4,5,6],[7,8,9]], 0)
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]
Elementwise subtract matrix a
from matrix b
Examples
iex> Elyanah.Numeric.Matrix.subtract([[1,2],[3,4]],[[1,2],[3,4]])
[[0, 0], [0, 0]]
Calculate the transpose of a matrix
.
Examples
iex> Elyanah.Numeric.Matrix.transpose([[1,2,3], [4,5,6], [7,8,9]])
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
iex> Elyanah.Numeric.Matrix.transpose([[1,2], [3,4], [5,6], [7,8]])
[[1, 3, 5, 7], [2, 4, 6, 8]]
iex> Elyanah.Numeric.Matrix.transpose([[1,2]])
[[1], [2]]
iex> Elyanah.Numeric.Matrix.transpose([[1],[2]])
[[1, 2]]