LinearAlgebraX
This module implements basic linear algebra methods for matrices with exact entries (e.g., Rational{Int}
values). The function names typically match the standard ones in Julia but with an x
(for "exact") appended.
The functions in this module work for all types of Integer
, Rational
, Complex{Integer}
, Complex{Rational}
, and Mod
entries in matrices. Other exact numbers may work as well, but are not tested.
As the goal of this module is always to give exact answers and, at the same time, be type stable, the results of many of these functions are big
. That is, the detx
of an integer matrix returns a BigInt
.
Functions
These functions in this module end with the letter x
and have the same definitions as their counterparts that do not have an x
. For exact types (such as Int
s) these functions give exact results.
detx
– exact determinantcofactor_det
– slower exact determinant (via cofactor expansion)nullspacex
– exact nullspacerankx
– exact rankinvx
– exact inverserrefx
– row reduced echelon formeye
– lovingly restoredchar_poly
– characteristic polynomialpermanent
– permanent of a square matrix
Examples
Determinant
julia> A = ones(Int,10,10)+eye(Int,10);
+LinearAlgebraX · LinearAlgebraX LinearAlgebraX
This module implements basic linear algebra methods for matrices with exact entries (e.g., Rational{Int}
values). The function names typically match the standard ones in Julia but with an x
(for "exact") appended.
The functions in this module work for all types of Integer
, Rational
, Complex{Integer}
, Complex{Rational}
, and Mod
entries in matrices. Other exact numbers may work as well, but are not tested.
As the goal of this module is always to give exact answers and, at the same time, be type stable, the results of many of these functions are big
. That is, the detx
of an integer matrix returns a BigInt
.
Functions
These functions in this module end with the letter x
and have the same definitions as their counterparts that do not have an x
. For exact types (such as Int
s) these functions give exact results.
detx
– exact determinant cofactor_det
– slower exact determinant (via cofactor expansion)nullspacex
– exact nullspacerankx
– exact rankinvx
– exact inverserrefx
– row reduced echelon formeye
– lovingly restoredchar_poly
– characteristic polynomialpermanent
– permanent of a square matrix
Examples follow.
Determinant
julia> A = ones(Int,10,10)+eye(Int,10);
julia> det(A)
-11.000000000000004
+10.999999999999998
julia> detx(A)
11
@@ -26,7 +26,7 @@
julia> detx(A)
┌ Warning: Using cofactor expansion to calculate determinant; may be very slow.
└ @ LinearAlgebraX ~/.julia/dev/LinearAlgebraX/src/detx.jl:41
-Mod{10}(4)
Nullspace
julia> A = reshape(collect(1:12),3,4)
+Mod{10}(4)
Nullspace
julia> A = reshape(collect(1:12),3,4)
3×4 Array{Int64,2}:
1 4 7 10
2 5 8 11
@@ -44,7 +44,7 @@
-0.475185 -0.272395
0.430549 0.717376
0.564458 -0.617566
- -0.519821 0.172585
Rank
Consider the 12-by-12 Hibert matrix, H
(see hilbert.jl
in the extras
folder):
12×12 Array{Rational{Int64},2}:
+ -0.519821 0.172585
Rank
Consider the 12-by-12 Hibert matrix, H
(see hilbert.jl
in the extras
folder):
12×12 Array{Rational{Int64},2}:
1//1 1//2 1//3 1//4 1//5 1//6 1//7 1//8 1//9 1//10 1//11 1//12
1//2 1//3 1//4 1//5 1//6 1//7 1//8 1//9 1//10 1//11 1//12 1//13
1//3 1//4 1//5 1//6 1//7 1//8 1//9 1//10 1//11 1//12 1//13 1//14
@@ -60,7 +60,7 @@
11
julia> rankx(H)
-12
Inverse
julia> using Mods
+12
Inverse
julia> using Mods
julia> A = rand(Mod{11},5,5)
5×5 Array{Mod{11},2}:
@@ -87,9 +87,9 @@
Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(1)
```
- ### Characteristic polynomial
+ ## Characteristic polynomial
julia> using SimplePolynomials, LinearAlgebra
julia> x = getx() x
julia> A = triu(ones(Int,5,5)) 5×5 Array{Int64,2}: 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 0 0 1
julia> char_poly(A) -1 + 5x - 10x^2 + 10x^3 - 5x^4 + x^5
julia> ans == (x-1)^5 true
julia> using Mods
julia> A = rand(Mod{17},4,4) 4×4 Array{Mod{17},2}: Mod{17}(16) Mod{17}(10) Mod{17}(9) Mod{17}(12) Mod{17}(15) Mod{17}(1) Mod{17}(1) Mod{17}(6) Mod{17}(3) Mod{17}(2) Mod{17}(5) Mod{17}(11) Mod{17}(5) Mod{17}(15) Mod{17}(15) Mod{17}(7)
julia> char_poly(A) Mod{17}(1) + Mod{17}(1)x + Mod{17}(16)x^2 + Mod{17}(5)x^3 + Mod{17}(1)x^4
julia> detx(A) Mod{17}(1)
- ### Row reduced echelon form
+ ## Row reduced echelon form
```
julia> A = rand(Int,4,6) .% 10
@@ -149,7 +149,7 @@
3-element Array{Rational{Int64},1}:
1//3
-2//3
- 1//1
However, entries cannot be assigned:
ulia> v[2] = 3//4
+ 1//1
However, entries cannot be assigned:
julia> v[2] = 3//4
ERROR: MethodError: no method matching setindex!(::HVector{Rational{Int64}}, ::Rational{Int64}, ::Int64)
Operations for HVector
s
The product of a matrix and a homogeneous vector is a homogeneous vector:
julia> A = rand(Int,3,3) .% 5
3×3 Array{Int64,2}:
-1 0 0
@@ -178,4 +178,17 @@
[-1//1 : 2//1 : 1//1]
julia> dot(v,w)
-1
Homogeneous Matrices
We also provide HMatrix
to represent a homogeneous matrix. These are constructed by passing an (ordinary) matrix. ``` julia> A = rand(Int,3,3).%5 3×3 Array{Int64,2}: 0 -4 3 1 4 -2 3 0 -3
julia> HMatrix(A) HMatrix: Rational{Int64}[0//1 4//3 -1//1; -1//3 -4//3 2//3; -1//1 0//1 1//1]
julia> Matrix(ans) 3×3 Array{Rational{Int64},2}: 0//1 4//3 -1//1 -1//3 -4//3 2//3 -1//1 0//1 1//1 ```
Settings
This document was generated with Documenter.jl version 1.5.0 on Sunday 25 August 2024. Using Julia version 1.10.4.
+1
Homogeneous Matrices
We also provide HMatrix
to represent a homogeneous matrix. These are constructed by passing an (ordinary) matrix.
julia> A = rand(Int,3,3).%5
+3×3 Array{Int64,2}:
+ 0 -4 3
+ 1 4 -2
+ 3 0 -3
+
+julia> HMatrix(A)
+HMatrix: Rational{Int64}[0//1 4//3 -1//1; -1//3 -4//3 2//3; -1//1 0//1 1//1]
+
+julia> Matrix(ans)
+3×3 Array{Rational{Int64},2}:
+ 0//1 4//3 -1//1
+ -1//3 -4//3 2//3
+ -1//1 0//1 1//1