Matrix properties
This page collects functions which compute values, invariants, or associated objects from matrices, rather than testing whether matrices satisfy certain conditions. Examples include determinants, ranks, inverses, nullspaces, polynomials, and related constructions.
Basic properties
AbstractAlgebra.number_of_rows — Method
number_of_rows(a::MatElem)Return the number of rows of the given matrix.
Examples
julia> M = matrix(ZZ, [1 2 3; 4 5 6])
[1 2 3]
[4 5 6]
julia> number_of_rows(M)
2AbstractAlgebra.number_of_columns — Method
number_of_columns(a::MatElem)Return the number of columns of the given matrix.
Examples
julia> M = matrix(ZZ, [1 2 3; 4 5 6])
[1 2 3]
[4 5 6]
julia> number_of_columns(M)
3Base.length — Method
length(a::MatrixElem{T}) where T <: NCRingElementReturn the number of entries in the given matrix.
Examples
julia> M = matrix(ZZ, [1 2 3; 4 5 6])
[1 2 3]
[4 5 6]
julia> length(M)
6Trace, determinant and rank
LinearAlgebra.tr — Method
tr(x::MatElem{T}) where T <: NCRingElementReturn the trace of the matrix $x$, i.e. the sum of its diagonal elements. The matrix is required to be square.
Examples
julia> R, t = polynomial_ring(QQ, :t)
(Univariate polynomial ring in t over rationals, t)
julia> S = matrix_space(R, 3, 3)
Matrix space of 3 rows and 3 columns
over univariate polynomial ring in t over rationals
julia> A = S([t + 1 t R(1); t^2 t t; R(-2) t + 2 t^2 + t + 1])
[t + 1 t 1]
[ t^2 t t]
[ -2 t + 2 t^2 + t + 1]
julia> b = tr(A)
t^2 + 3*t + 2LinearAlgebra.det — Method
det(M::MatElem{T}) where {T <: RingElement}Return the determinant of the given matrix $M$. The matrix is required to be square.
Examples
julia> R, x = polynomial_ring(QQ, :x)
(Univariate polynomial ring in x over rationals, x)
julia> A = R[x 1; 1 x^2];
julia> det(A)
x^3 - 1LinearAlgebra.rank — Method
rank(M::MatElem{T}) where {T <: RingElement}Return the rank of the given matrix $M$.
Examples
julia> A = QQ[1 2 3; 2 4 6; 1 1 1];
julia> rank(A)
2Inverses
Base.inv — Method
inv(M::MatElem{T}) where {T <: RingElement}Given an invertible $n \times n$ matrix $M$ over a ring, return the $n \times n$ matrix $X$ such that $MX = I_n$, where $I_n$ is the $n \times n$ identity matrix.
If $M$ is not invertible over the base ring, an exception is raised.
Examples
julia> M = matrix(QQ, 3, 3, [1 2 3; 4 5 6; 0 0 1])
[1//1 2//1 3//1]
[4//1 5//1 6//1]
[0//1 0//1 1//1]
julia> inv(M)
[-5//3 2//3 1//1]
[ 4//3 -1//3 -2//1]
[ 0//1 0//1 1//1]AbstractAlgebra.pseudo_inv — Method
pseudo_inv(M::MatElem{T}) where {T <: RingElement}Given a non-singular $n \times n$ matrix $M$ over a ring, return a tuple $X, d$ consisting of an $n \times n$ matrix $X$ and a denominator $d$ such that $MX = dI_n$, where $I_n$ is the $n \times n$ identity matrix.
The denominator $d$ is the determinant of $M$ up to sign.
If $M$ is not invertible over the base ring, an exception is raised.
Examples
julia> M = matrix(QQ, 3, 3, [1 2 3;4 5 6;0 0 1])
[1//1 2//1 3//1]
[4//1 5//1 6//1]
[0//1 0//1 1//1]
julia> pseudo_inv(M)
([5 -2 -3; -4 1 6; 0 0 -3], -3//1)Characteristic and minimal polynomials
AbstractAlgebra.charpoly — Method
charpoly(Y::MatElem{T}) where {T <: RingElement}
charpoly(S::PolyRing{T}, Y::MatElem{T}) where {T <: RingElement}Return the characteristic polynomial $p$ of the square matrix $Y$. If a polynomial ring $S$ over the same base ring as $Y$ is supplied, the resulting polynomial is an element of it.
Examples
julia> R, = residue_ring(ZZ, 7);
julia> S = matrix_space(R, 4, 4)
Matrix space of 4 rows and 4 columns
over residue ring of integers modulo 7
julia> T, y = polynomial_ring(R, :y)
(Univariate polynomial ring in y over R, y)
julia> M = S([R(1) R(2) R(4) R(3); R(2) R(5) R(1) R(0);
R(6) R(1) R(3) R(2); R(1) R(1) R(3) R(5)])
[1 2 4 3]
[2 5 1 0]
[6 1 3 2]
[1 1 3 5]
julia> A = charpoly(T, M)
y^4 + 2*y^2 + 6*y + 2
julia> A = charpoly(M)
x^4 + 2*x^2 + 6*x + 2AbstractAlgebra.minpoly — Method
minpoly(M::MatElem{T}) where {T <: RingElement}
minpoly(S::PolyRing{T}, M::MatElem{T}) where {T <: RingElement}Return the minimal polynomial $p$ of the square matrix $M$. If a polynomial ring $S$ over the same base ring as $Y$ is supplied, the resulting polynomial is an element of it.
Examples
julia> R = GF(13)
Finite field F_13
julia> S, y = polynomial_ring(R, :y)
(Univariate polynomial ring in y over R, y)
julia> M = R[7 6 1;
7 7 5;
8 12 5]
[7 6 1]
[7 7 5]
[8 12 5]
julia> A = minpoly(S, M)
y^2 + 10*y
julia> A = minpoly(M)
x^2 + 10*x
Powers
AbstractAlgebra.powers — Method
powers(a::Union{NCRingElement, MatElem}, d::Int)Return an array $M$ of "powers" of a where $M[i + 1] = a^i$ for $i = 0..d$.
Examples
julia> M = ZZ[1 2 3; 2 3 4; 4 5 5]
[1 2 3]
[2 3 4]
[4 5 5]
julia> A = powers(M, 4)
5-element Vector{AbstractAlgebra.Generic.MatSpaceElem{BigInt}}:
[1 0 0; 0 1 0; 0 0 1]
[1 2 3; 2 3 4; 4 5 5]
[17 23 26; 24 33 38; 34 48 57]
[167 233 273; 242 337 394; 358 497 579]
[1725 2398 2798; 2492 3465 4044; 3668 5102 5957]Gram matrices
AbstractAlgebra.gram — Method
gram(x::MatElem)Return the Gram matrix of $x$, i.e. if $x$ is an $r \times c$ matrix, return the $r \times r$ matrix whose $(i, j)$-th entry is the dot product of the $i$-th and $j$-th rows of $x$.
Examples
julia> R, t = polynomial_ring(QQ, :t)
(Univariate polynomial ring in t over rationals, t)
julia> S = matrix_space(R, 3, 3)
Matrix space of 3 rows and 3 columns
over univariate polynomial ring in t over rationals
julia> A = S([t + 1 t R(1); t^2 t t; R(-2) t + 2 t^2 + t + 1])
[t + 1 t 1]
[ t^2 t t]
[ -2 t + 2 t^2 + t + 1]
julia> B = gram(A)
[2*t^2 + 2*t + 2 t^3 + 2*t^2 + t 2*t^2 + t - 1]
[t^3 + 2*t^2 + t t^4 + 2*t^2 t^3 + 3*t]
[ 2*t^2 + t - 1 t^3 + 3*t t^4 + 2*t^3 + 4*t^2 + 6*t + 9]Content
AbstractAlgebra.content — Method
content(x::MatrixElem{T}) where T <: RingElementReturn the greatest common divisor of all entries of the matrix $x$, assuming such a greatest common divisor exists.
Examples
julia> R, t = polynomial_ring(QQ, :t)
(Univariate polynomial ring in t over rationals, t)
julia> S = matrix_space(R, 3, 3)
Matrix space of 3 rows and 3 columns
over univariate polynomial ring in t over rationals
julia> A = S([t + 1 t R(1); t^2 t t; R(-2) t + 2 t^2 + t + 1])
[t + 1 t 1]
[ t^2 t t]
[ -2 t + 2 t^2 + t + 1]
julia> b = content(A)
1Minors and exterior powers
AbstractAlgebra.minors — Method
minors(A::MatElem, k::Int)Return an array consisting of all $k$-minors of the given matrix $A$, i.e. the determinants of all $k \times k$ submatrices of $A$.
Examples
julia> A = ZZ[1 2 3; 4 5 6]
[1 2 3]
[4 5 6]
julia> minors(A, 2)
3-element Vector{BigInt}:
-3
-6
-3AbstractAlgebra.minors_with_position — Method
minors_with_position(A::MatElem, k::Int)Return an array consisting of all $k$-minors of $A$, together with the row and column indices defining the corresponding submatrices.
Examples
julia> A = ZZ[1 2 3; 4 5 6]
[1 2 3]
[4 5 6]
julia> minors_with_position(A, 2)
3-element Vector{Tuple{BigInt, Vector{Int64}, Vector{Int64}}}:
(-3, [1, 2], [1, 2])
(-6, [1, 2], [1, 3])
(-3, [1, 2], [2, 3])AbstractAlgebra.minors_iterator — Method
minors_iterator(A::MatElem, k::Int)Return an iterator computing all $k$-minors of $A$, i.e. the determinants of all $k \times k$ submatrices of $A$.
Examples
julia> A = ZZ[1 2 3; 4 5 6]
[1 2 3]
[4 5 6]
julia> first(minors_iterator(A, 2))
-3
julia> collect(minors_iterator(A, 2))
3-element Vector{BigInt}:
-3
-6
-3
AbstractAlgebra.minors_iterator_with_position — Method
minors_iterator_with_position(A::MatElem, k::Int)Return an iterator computing all $k$-minors of $A$, together with the row and column indices defining the corresponding submatrices.
Examples
julia> A = ZZ[1 2 3; 4 5 6]
[1 2 3]
[4 5 6]
julia> first(minors_iterator_with_position(A, 2))
(-3, [1, 2], [1, 2])AbstractAlgebra.exterior_power — Method
exterior_power(A::MatElem, k::Int) -> MatElemReturn the matrix of the induced map on the k-th exterior power. Its entries are the determinants of the $k \times k$ submatrices of $A$.
Examples
julia> A = matrix(ZZ, 3, 3, [1, 2, 3, 4, 5, 6, 7, 8, 9]);
julia> exterior_power(A, 2)
[-3 -6 -3]
[-6 -12 -6]
[-3 -6 -3]Pfaffians
AbstractAlgebra.pfaffian — Method
pfaffian(M::MatElem)Return the Pfaffian of the skew-symmetric matrix $M$.
Examples
julia> R, x = polynomial_ring(QQ, ["x$i" for i in 1:6]);
julia> M = R[0 x[1] x[2] x[3]; -x[1] 0 x[4] x[5]; -x[2] -x[4] 0 x[6]; -x[3] -x[5] -x[6] 0]
[ 0 x1 x2 x3]
[-x1 0 x4 x5]
[-x2 -x4 0 x6]
[-x3 -x5 -x6 0]
julia> pfaffian(M)
x1*x6 - x2*x5 + x3*x4AbstractAlgebra.pfaffians — Method
pfaffians(M::MatElem, k::Int)Return a vector consisting of the Pfaffians of all $k \times k$ principal submatrices of the skew-symmetric matrix $M$.
Examples
julia> R, x = polynomial_ring(QQ, ["x$i" for i in 1:6]);
julia> M = R[0 x[1] x[2] x[3]; -x[1] 0 x[4] x[5]; -x[2] -x[4] 0 x[6]; -x[3] -x[5] -x[6] 0]
[ 0 x1 x2 x3]
[-x1 0 x4 x5]
[-x2 -x4 0 x6]
[-x3 -x5 -x6 0]
julia> pfaffians(M, 2)
6-element Vector{AbstractAlgebra.Generic.MPoly{Rational{BigInt}}}:
x1
x2
x4
x3
x5
x6