Julia LinearAlgebra
The LinearAlgebra package provides reference implementations of matrix decompositions and related utilities.
Example
julia> using LinearAlgebra;
julia> A = [1 2 3; 4 1 6; 7 8 1]
3×3 Matrix{Int64}:
1 2 3
4 1 6
7 8 1
julia> tr(A)
3
julia> det(A)
104.0
Functions
In the following calls, note that:
a and b are column vectors of equal size
m and n are matrices
These functions return a scalar value.
Function Call |
Meaning |
det(m) |
|
dot(a,b) |
|
eigmax(m) |
largest eigenvalue |
eigmin(m) |
smallest eigenvalue |
norm(a) |
|
rank(m) |
|
tr(a) |
These functions return a column vector.
Function Call |
Meaning |
Notes |
cross(a,b) |
a and b must be 3-dimensional |
|
diag(m) |
diagonal of the matrix |
|
eigvals(m) |
eigenvalues |
|
normalize(a) |
normalize to a distance of 1 |
|
These functions return a matrix.
Function Call |
Meaning |
bunchkaufman(m) |
Bunch-Kaufman factorization |
cholesky(m) |
Cholesky factorization |
diagm(a) |
diagonal matrix with this diagonal |
eigen(m) |
Eigen decomposition |
eigvecs(m) |
|
hessenberg(m) |
Hessenberg factorization |
lq(m) |
LQ decomposition |
lu(m) |
|
qr(m) |
|
schur(m) |
Schur factorization |
svd(m) |
There is also the positive definiteness test function, isposdef.
Eigen Decomposition
Note that the eigen function returns an object where the eigenvectors are accessible by the vectors property and the eigenvalues are accessible by the values property.
julia> F = eigen([1.0 0.0 0.0; 0.0 3.0 0.0; 0.0 0.0 18.0])
Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}
values:
3-element Vector{Float64}:
1.0
3.0
18.0
vectors:
3×3 Matrix{Float64}:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
julia> F.values
3-element Vector{Float64}:
1.0
3.0
18.0
julia> F.vectors
3×3 Matrix{Float64}:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
julia> vals, vecs = F; # destructuring via iteration
Constructors
Rather than exposing an eye function, this package exposes LinearAlgebra.I. Note that this is a sparse matrix, and must be type cast to fill it.
julia> using LinearAlgebra;
julia> I(3)
3×3 Diagonal{Bool, Vector{Bool}}:
1 ⋅ ⋅
⋅ 1 ⋅
⋅ ⋅ 1
julia> Matrix{Int}(I(3))
3×3 Matrix{Int64}:
1 0 0
0 1 0
0 0 1Note also that this follows the pattern established by other direct matrix constructors.
julia> d = Diagonal([1, 10, 100])
3×3 Diagonal{Int64, Vector{Int64}}:
1 ⋅ ⋅
⋅ 10 ⋅
⋅ ⋅ 100