File tree Expand file tree Collapse file tree 5 files changed +65
-4
lines changed Expand file tree Collapse file tree 5 files changed +65
-4
lines changed Original file line number Diff line number Diff line change 11name = " LinearAlgebraX"
22uuid = " 9b3f67b0-2d00-526e-9884-9e4938f8fb88"
3- version = " 0.0.1 "
3+ version = " 0.0.2 "
44
55[deps ]
66LinearAlgebra = " 37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
7+ SimplePolynomials = " cc47b68c-3164-5771-a705-2bc0097375a0"
8+ SimpleRationalFunctions = " 1a520dc8-4f4e-523b-a9bd-3b3d46c5454b"
79
810[compat ]
911julia = " 1"
12+ SimplePolynomials = " 0"
13+ SimpleRationalFunctions = " 0"
1014
1115[extras ]
1216Test = " 8dfed614-e22c-5e08-85e1-65c5234f0b40"
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ For exact types (such as `Int`s) these functions give exact results.
2929* ` invx ` -- exact inverse
3030* ` rrefx ` -- row reduced echelon form
3131* ` eye ` -- lovingly restored
32+ * ` char_poly ` -- characteristic polynomial
3233
3334## Examples
3435
@@ -133,8 +134,31 @@ julia> A*B
133134 Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(0) Mod{11}(1)
134135 ```
135136
137+ #### Characteristic polynomial
138+
139+ ```
140+ julia> using SimplePolynomials, LinearAlgebra
141+
142+ julia> x = getx()
143+ x
144+
145+ julia> A = triu(ones(Int,5,5))
146+ 5×5 Array{Int64,2}:
147+ 1 1 1 1 1
148+ 0 1 1 1 1
149+ 0 0 1 1 1
150+ 0 0 0 1 1
151+ 0 0 0 0 1
152+
153+ julia> char_poly(A)
154+ -1 + 5*x - 10*x^2 + 10*x^3 - 5*x^4 + x^5
155+
156+ julia> ans == (x-1)^5
157+ true
158+ ```
159+
136160 #### Row reduced echelon form
137-
161+
138162 ```
139163 julia> A = rand(Int,4,6) .% 10
1401644×6 Array{Int64,2}:
@@ -164,3 +188,7 @@ julia> rrefx(A)
164188 0//1 0//1 1//1 1//1 0//1 551//650 512//325
165189 0//1 0//1 0//1 0//1 1//1 -379//325 204//325
166190 ```
191+
192+ ## To do
193+
194+ Still having some issues with integer overflow.
Original file line number Diff line number Diff line change 11module LinearAlgebraX
2- using LinearAlgebra
2+ using LinearAlgebra, SimplePolynomials, SimpleRationalFunctions
33
44
55# IntegerX is any sort of real or Gaussian integer
@@ -8,6 +8,8 @@ IntegerX = Union{S,Complex{S}} where S<:Integer
88# RationalX is a Rational or Complex Rational based on integers
99RationalX = Union{Rational{S},Complex{Rational{S}}} where S<: Integer
1010
11+ TypeX = Union{IntegerX, RationalX}
12+
1113
1214function _recip (x:: T ) where T <: IntegerX
1315 return 1 // x
@@ -22,7 +24,7 @@ include("rrefx.jl")
2224include (" invx.jl" )
2325include (" rankx.jl" )
2426include (" nullspacex.jl" )
25-
27+ include ( " char_poly.jl " )
2628
2729
2830end # module
Original file line number Diff line number Diff line change 1+ export char_poly
2+
3+ function char_poly (A:: Matrix{T} ) where T<: TypeX
4+ r,c = size (A)
5+ @assert r== c " Matrix must be square"
6+
7+ xI = zeros (SimplePolynomial,r,r)
8+ x = getx ()
9+ for i= 1 : r
10+ xI[i,i] = x
11+ end
12+
13+ f = detx (xI- A)
14+ p = integerize (numerator (f))
15+ end
Original file line number Diff line number Diff line change @@ -15,3 +15,15 @@ H = hilbert(12)
1515A = ones (Int,3 ,5 )
1616N = nullspacex (A)
1717@test all (0 .== A* N)
18+
19+
20+ using SimplePolynomials
21+
22+ A = triu (ones (Int,5 ,5 ))
23+ p = char_poly (A)
24+ x = getx ()
25+ @test p == (x- 1 )^ 5
26+
27+ A = ones (Int,5 ,5 )
28+ p = char_poly (A)
29+ @test p == x^ 4 * (x- 5 )
You can’t perform that action at this time.
0 commit comments