Skip to content

Commit 505d546

Browse files
PBrdngsaschatimme
authored andcommitted
Add determinant (#86)
Closes #58 #78
1 parent 95dc00a commit 505d546

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/MultivariatePolynomials.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ module MultivariatePolynomials
55
#using DocStringExtensions
66

77
using Compat
8-
import Compat.LinearAlgebra: dot, norm
8+
import Compat.LinearAlgebra: dot, norm, det
99

1010
# The ' operator lowers to `transpose()` in v0.6 and to
11-
# `adjoint()` in v0.7+.
11+
# `adjoint()` in v0.7+.
1212
# TOOD: remove this switch when dropping v0.6 support
1313
@static if VERSION <= v"0.7.0-DEV.3351"
1414
import Base: transpose
@@ -91,5 +91,6 @@ include("comparison.jl")
9191
include("substitution.jl")
9292
include("differentiation.jl")
9393
include("division.jl")
94+
include("det.jl")
9495

9596
end # module

src/det.jl

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function det(M::Matrix{<:AbstractPolynomialLike})
2+
m = size(M)[1]
3+
if m > 2
4+
return sum((-1)^(i-1) * M[i,1] * det(M[1:end .!= i, 2:end]) for i in 1:m)
5+
else
6+
return M[1,1] * M[2,2] - M[2,1] * M[1,2]
7+
end
8+
end

test/commutativetests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include("monomial.jl")
44
include("term.jl")
55
include("monovec.jl")
66
include("polynomial.jl")
7+
include("det.jl")
78

89
include("rational.jl")
910

test/det.jl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@testset "Det" begin
2+
Mod.@polyvar x y
3+
4+
@test det([x 1; y 1]) == x - y
5+
@test det([x 1; x 1]) == 0
6+
@test det([x 1 1 1; x y 1 2; 0 0 0 1; x 0 y 0]) == -x*y^2 + 2*x*y - x
7+
end

0 commit comments

Comments
 (0)