matrix_operation v0.3.5 MatrixOperation

Documentation for Matrix operation library.

Link to this section Summary

Functions

Matrix addition

A matrix is added by a constant.

A matrix is multiplied by a constant.

A column of a matrix is deleted.

A row of a matrix is deleted.

A determinant of a n×n square matrix is got.

Matrix diagonalization

Matrix diagonalization by the direct method [R^2×R^2/R^3×R^3 matrix]

Calculate eigenvalue by using QR decomposition

eigenvalue by the direct method [R^2×R^2/R^3×R^3 matrix]

A m×n matrix having even-elements is got.

Frobenius norm

A column of a matrix is got.

A element of a matrix is got.

A row of a matrix is got.

Hadamard division

Hadamard power

Hadamard product

Inverse Matrix

Calculate eigenvalue and eigenvector by using Jacobi method

Jordan_normal_form [R^2×R^2/R^3×R^3 matrix]

Leading principal minors are generetaed

Linear equations are solved by Cramer's rule.

Linear equations are solved by LU decomposition.

LU decomposition

max norm

one norm

Power iteration method (maximum eigen value and eigen vector)

Matrix product

Calculate the rank of a matrix by using QR decomposition

Numbers of row and column of a matrix are got.

Calculate singular Value by using QR decomposition

Matrix subtraction

Singular Value Decomposition (SVD) by using Jacobi method

Tensor product

Trace of a matrix

Transpose of a matrix

two norm

A n-th unit matrix is got.

A variance-covariance matrix is generated

Link to this section Functions

Matrix addition

Examples

iex> MatrixOperation.add([[3, 2, 3], [2, 1, 2]], [[2, 3, 1], [3, 2, 2]])
[[5, 5, 4], [5, 3, 4]]
Link to this function

const_addition(const, a)

A matrix is added by a constant.

Examples

iex> MatrixOperation.const_addition(1, [1.0, 2.0, 3.0])
[2.0, 3.0, 4.0]
Link to this function

const_multiple(const, a)

A matrix is multiplied by a constant.

Examples

iex> MatrixOperation.const_multiple(-1, [1.0, 2.0, 3.0])
[-1.0, -2.0, -3.0]
iex> MatrixOperation.const_multiple(2, [[1, 2, 3], [2, 2, 2], [3, 8, 9]])
[[2, 4, 6], [4, 4, 4], [6, 16, 18]]
Link to this function

cramer(a, vertical_vec, select_index)

Cramer's rule

Examples

iex> MatrixOperation.cramer([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[1], [0], [0]], 1)
1.0
iex> MatrixOperation.cramer([[0, -2, 1], [-1, 1, -4], [3, 3, 1]], [[3], [-7], [4]], 1)
2.0
Link to this function

delete_one_column(matrix, delete_index)

A column of a matrix is deleted.

Examples

iex> MatrixOperation.delete_one_column([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 2)
[[1, 3], [4, 6], [7, 9]]
Link to this function

delete_one_row(matrix, delete_index)

A row of a matrix is deleted.

Examples

iex> MatrixOperation.delete_one_row([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3)
[[1, 2, 3], [4, 5, 6]]

A determinant of a n×n square matrix is got.

Examples

iex> MatrixOperation.determinant([[1, 2, 1], [2, 1, 0], [1, 1, 2]])
-5
iex> MatrixOperation.determinant([[1, 2, 1, 1], [2, 1, 0, 1], [1, 1, 2, 1], [1, 2, 3, 4]])
-13
iex> MatrixOperation.determinant([ [3,1,1,2,1], [5,1,3,4,1], [2,0,1,0,1], [1,3,2,1,1], [1,1,1,1,1] ])
-14
Link to this function

diagonalization(a, loop_num)

Matrix diagonalization

Examples

iex> MatrixOperation.diagonalization([[1, 3], [4, 2]], 100) [[5.000000000000018, 0], [0, -1.999999999999997]] iex> MatrixOperation.diagonalization([[2, 1, -1], [1, 1, 0], [-1, 0, 1]], 100) [[3.000000000000001, 0, 0], [0, 1.0, 0], [0, 0, 0]]

Link to this function

diagonalization_direct(a)

Matrix diagonalization by the direct method [R^2×R^2/R^3×R^3 matrix]

Examples

iex> MatrixOperation.diagonalization_direct([[1, 3], [4, 2]]) [[5.0, 0], [0, -2.0]] iex> MatrixOperation.diagonalization_direct([[2, 1, -1], [1, 1, 0], [-1, 0, 1]]) [[3.0000000027003626, 0, 0], [0, 0, 0], [0, 0, 0.9999999918989121]]

Link to this function

eigenvalue(a, loop_num)

Calculate eigenvalue by using QR decomposition

Examples

iex> MatrixOperation.eigenvalue([[1, 4, 5], [4, 2, 6], [5, 6, 3]], 100) [12.17597106504691, -3.6686830979532696, -2.5072879670936357] iex> MatrixOperation.eigenvalue([[6, 1, 1, 1], [1, 7, 1, 1], [1, 1, 8, 1], [1, 1, 1, 9]], 100) [10.803886359051251, 7.507748705362773, 6.39227529027387, 5.296089645312106]

Link to this function

eigenvalue_direct(arg1)

eigenvalue by the direct method [R^2×R^2/R^3×R^3 matrix]

Examples

iex> MatrixOperation.eigenvalue_direct([[3, 1], [2, 2]]) [4.0, 1.0] iex> MatrixOperation.eigenvalue_direct([[6, -3], [4, -1]]) [3.0, 2.0] iex> MatrixOperation.eigenvalue_direct([[1, 1, 1], [1, 2, 1], [1, 2, 3]]) [4.561552806429505, 0.43844714673139706, 1.0000000468390973] iex> MatrixOperation.eigenvalue_direct([[2, 1, -1], [1, 1, 0], [-1, 0, 1]]) [3.0000000027003626, 0, 0.9999999918989121]

Link to this function

even_matrix(m, n, s)

A m×n matrix having even-elements is got.

Examples

iex> MatrixOperation.even_matrix(2, 3, 0) [[0, 0, 0], [0, 0, 0]] iex> MatrixOperation.even_matrix(3, 2, 1) [[1, 1], [1, 1], [1, 1]]

Link to this function

exchange_one_column(matrix, exchange_index, exchange_list)

A row of a matrix is exchanged.

Examples

iex> MatrixOperation.exchange_one_column([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 2, [1, 1, 1])
[[1, 1, 3], [4, 1, 6], [7, 1, 9]]
Link to this function

exchange_one_row(matrix, exchange_index, exchange_list)

A row of a matrix is exchanged.

Examples

iex> MatrixOperation.exchange_one_row([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3, [1, 1, 1])
[[1, 2, 3], [4, 5, 6], [1, 1, 1]]
Link to this function

frobenius_norm(a)

Frobenius norm

Examples

iex> MatrixOperation.frobenius_norm([[2, 3], [1, 4], [2, 1]]) 5.916079783099616 iex> MatrixOperation.frobenius_norm([[1, 3, 3], [2, 4, 1], [2, 3, 2]]) 7.54983443527075

Link to this function

get_one_column(matrix, column_index)

A column of a matrix is got.

Examples

iex> MatrixOperation.get_one_column([[1, 2, 3], [4, 5, 6], [7, 8, 9] ], 1)
[1, 4, 7]
Link to this function

get_one_element(matrix, list)

A element of a matrix is got.

Examples

iex> MatrixOperation.get_one_element([[1, 2, 3], [4, 5, 6], [7, 8, 9] ], [1, 1]) 1

Link to this function

get_one_row(matrix, row_index)

A row of a matrix is got.

Examples

iex> MatrixOperation.get_one_row([[1, 2, 3], [4, 5, 6], [7, 8, 9] ], 1) [1, 2, 3]

Link to this function

hadamard_division(a, b)

Hadamard division

Examples

iex> MatrixOperation.hadamard_division([[3, 2, 3], [2, 1, 2]], [[2, 3, 1], [3, 2, 2]])
[[1.5, 0.6666666666666666, 3.0], [0.6666666666666666, 0.5, 1.0]]
Link to this function

hadamard_power(a, n)

Hadamard power

Examples

iex> MatrixOperation.hadamard_power([[3, 2, 3], [2, 1, 2]], 2)
[[9.0, 4.0, 9.0], [4.0, 1.0, 4.0]]
Link to this function

hadamard_product(a, b)

Hadamard product

Examples

iex> MatrixOperation.hadamard_product([[3, 2, 3], [2, 1, 2]], [[2, 3, 1], [3, 2, 2]])
[[6, 6, 3], [6, 2, 4]]
Link to this function

inverse_matrix(a)

Inverse Matrix

Examples

iex> MatrixOperation.inverse_matrix([[1, 1, -1], [-2, -1, 1], [-1, -2, 1]])
[[-1.0, -1.0, 0.0], [-1.0, 0.0, -1.0], [-3.0, -1.0, -1.0]]
Link to this function

jacobi(a, loop_num)

Calculate eigenvalue and eigenvector by using Jacobi method

Examples

iex> MatrixOperation.jacobi([[10, 3, 2], [3, 5, 1], [2, 1, 0]], 100) [

[11.827601656659317, 3.5956497715829547, -0.42325142824210527],
[
  [0.8892872578006493, -0.42761854121982545, -0.16220529066103917],
  [0.4179466723082325, 0.9038581385545962, -0.09143874712126684],
  [0.1857114757355589, 0.013522151221627882, 0.982511271796136]
]

]

Link to this function

jordan_normal_form(arg1)

Jordan_normal_form [R^2×R^2/R^3×R^3 matrix]

Examples

iex> MatrixOperation.jordan_normal_form([[1, 3], [4, 2]]) [[5.0, 0], [0, -2.0]] iex> MatrixOperation.jordan_normal_form([[7, 2], [-2, 3]]) [[5.0, 1], [0, 5.0]] iex> MatrixOperation.jordan_normal_form([[2, 1, -1], [1, 1, 0], [-1, 0, 1]]) [[3.0000000027003626, 0, 0], [0, 0, 0], [0, 0, 0.9999999918989121]] iex> MatrixOperation.jordan_normal_form([[1, -1, 1], [0, 2, -2], [1, 1, 3]]) [[2.0, 1, 0], [0, 2.0, 1], [0, 0, 2.0]] iex> MatrixOperation.jordan_normal_form([[3, 0, 1], [-1, 2, -1], [-1, 0, 1]]) [[2.0, 1, 0], [0, 2.0, 0], [0, 0, 2.0]] iex> MatrixOperation.jordan_normal_form([[1, 0, -1], [0, 2, 0], [0, 1, 1]]) [[2.0, 0, 0], [0, 0.9999999999999999, 1], [0, 0, 0.9999999999999999]] iex> MatrixOperation.jordan_normal_form([[6, 2, 3], [-3, 0, -2], [-4, -2, -1]]) [[1.0, 0, 0], [0, 2.0, 1], [0, 0, 2.0]]

Link to this function

leading_principal_minor(a, k)

Leading principal minors are generetaed

Examples

iex> MatrixOperation.leading_principal_minor([[1, 3, 2], [2, 5, 1], [3, 4, 5]], 2) [[1, 3], [2, 5]]

Link to this function

linear_equations_cramer(a, vertical_vec)

Linear equations are solved by Cramer's rule.

Examples

iex> MatrixOperation.linear_equations_cramer([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[1], [0], [0]])
[1.0, 0.0, 0.0]
iex> MatrixOperation.linear_equations_cramer([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[1], [0], [0]])
[1.0, 0.0, 0.0]
Link to this function

linear_equations_direct(a, vertical_vec)

Linear equations are solved by LU decomposition.

Examples

iex> MatrixOperation.linear_equations_direct([[1, 0, 0], [0, 1, 0], [0, 0, 1]], [[1], [0], [0]])
[1.0, 0.0, 0.0]
iex> MatrixOperation.linear_equations_direct([[4, 1, 1], [1, 3, 1], [2, 1, 5]], [[9], [10], [19]])
[1.0, 2.0, 3.0]
Link to this function

lu_decomposition(a)

LU decomposition

Examples

iex> MatrixOperation.lu_decomposition([[1, 1, 0, 3], [2, 1, -1, 1], [3, -1, -1, 2], [-1, 2, 3, -1]]) [

[[1, 0, 0, 0], [2.0, 1, 0, 0], [3.0, 4.0, 1, 0], [-1.0, -3.0, 0.0, 1]],
[[1, 1, 0, 3], [0, -1.0, -1.0, -5.0], [0, 0, 3.0, 13.0], [0, 0, 0, -13.0]]

]

max norm

Examples

iex> MatrixOperation.max_norm([[2, 3], [1, 4], [2, 1]]) 8 iex> MatrixOperation.max_norm([[1, 3, 3], [2, 4, 1], [2, 3, 2]]) 10

one norm

Examples

iex> MatrixOperation.one_norm([[2, 3], [1, 4], [2, 1]]) 5 iex> MatrixOperation.one_norm([[1, 3, 3], [2, 4, 1], [2, 3, 2]]) 7

Link to this function

power_iteration(a, max_k)

Power iteration method (maximum eigen value and eigen vector)

Examples

iex> MatrixOperation.power_iteration([[3, 1], [2, 2]], 100) [

4.0,
[2.8284271247461903, 2.8284271247461903]

] iex> MatrixOperation.power_iteration([[1, 1, 2], [0, 2, -1], [0, 0, 3]], 100) [

3.0,
[1.0, -2.0, 2.0]

]

Matrix product

Examples

iex> MatrixOperation.product([[3, 2, 3], [2, 1, 2]], [[2, 3], [2, 1], [3, 5]])
[[19, 26], [12, 17]]
Link to this function

rank(matrix, loop_num)

Calculate the rank of a matrix by using QR decomposition

Examples

iex> MatrixOperation.rank([[2, 3, 4], [1, 4, 2], [2, 1, 4]], 100)
2
iex> MatrixOperation.rank([[2, 3, 4, 2], [1, 4, 2, 3], [2, 1, 4, 4]], 100)
3
Link to this function

row_column_matrix(a)

Numbers of row and column of a matrix are got.

Examples

iex> MatrixOperation.row_column_matrix([[3, 2, 3], [2, 1, 2]]) [2, 3]

Link to this function

singular_value(a, loop_num)

Calculate singular Value by using QR decomposition

Examples

iex> MatrixOperation.singular_value([[1, 2, 3, 1], [2, 4, 1, 5], [3, 3, 10, 8]], 100) [14.912172620559879, 4.236463407782015, 1.6369134152873956, 0.0]

Matrix subtraction

Examples

iex> MatrixOperation.subtract([[3, 2, 3], [2, 1, 2]], [[2, 3, 1], [3, 2, 2]])
[[1, -1, 2], [-1, -1, 0]]
Link to this function

svd(a, loop_num)

Singular Value Decomposition (SVD) by using Jacobi method

Examples

iex> MatrixOperation.svd([[1, 0, 0], [0, 1, 1]], 100) [

[1.0, 1.4142135623730951],
[[1.0, 0], [0, 1.0]],
[
  [1.0, 0, 0],
  [0, 0.7071067458364744, -0.707106816536619],
  [0, 0.707106816536619, 0.7071067458364744]
]

]

Link to this function

svd_sub(a, a_t, loop_num)

Link to this function

tensor_product(a, b)

Tensor product

Examples

iex> MatrixOperation.tensor_product([[3, 2, 3], [2, 1, 2]], [[2, 3, 1], [2, 1, 2], [3, 5, 3]])
[
[
[[6, 9, 3], [6, 3, 6], [9, 15, 9]],
[[4, 6, 2], [4, 2, 4], [6, 10, 6]],
[[6, 9, 3], [6, 3, 6], [9, 15, 9]]
],
[
[[4, 6, 2], [4, 2, 4], [6, 10, 6]],
[[2, 3, 1], [2, 1, 2], [3, 5, 3]],
[[4, 6, 2], [4, 2, 4], [6, 10, 6]]
]
]

Trace of a matrix

Examples

iex> MatrixOperation.trace([[1.0, 2.0], [3.0, 4.0]])
5.0

Transpose of a matrix

Examples

iex> MatrixOperation.transpose([[1.0, 2.0], [3.0, 4.0]])
[[1.0, 3.0], [2.0, 4.0]]

two norm

Examples

iex> MatrixOperation.two_norm([[2, 3], [1, 4], [2, 1]]) 5.674983803488139 iex> MatrixOperation.two_norm([[1, 3, 3], [2, 4, 1], [2, 3, 2]]) 7.329546646114924

A n-th unit matrix is got.

Examples

iex> MatrixOperation.unit_matrix(3) [[1, 0, 0], [0, 1, 0], [0, 0, 1]]

Link to this function

variance_covariance_matrix(data)

A variance-covariance matrix is generated

Examples

iex> MatrixOperation.variance_covariance_matrix([[40, 80], [80, 90], [90, 100]]) [

[466.66666666666663, 166.66666666666666],
[166.66666666666666, 66.66666666666666]

]