From c17e3b85796d3588ffb7407c9acdf4f572925b73 Mon Sep 17 00:00:00 2001 From: Massimiliano Fasi Date: Mon, 20 Jan 2025 10:06:11 +0000 Subject: [PATCH] feat(matrices): add logdet(::Hilbert) --- src/matrices/hilbert.jl | 5 +++++ test/runtests.jl | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/matrices/hilbert.jl b/src/matrices/hilbert.jl index 47d84b9..99fb69e 100644 --- a/src/matrices/hilbert.jl +++ b/src/matrices/hilbert.jl @@ -52,6 +52,11 @@ LinearAlgebra.issymmetric(A::Hilbert) = A.m == A.n return T(one(T) / (i + j - 1)) end +logc(x) = sum([sum(log.(1:i)) for i = 2:(x-1)]) +function LinearAlgebra.logdet(A::Hilbert) + LinearAlgebra.checksquare(A) + return (4 * logc(A.n) - logc(2 * A.n)) +end LinearAlgebra.det(A::Hilbert) = inv(det(inv(A))) function inv(A::Hilbert{T}) where {T} diff --git a/test/runtests.jl b/test/runtests.jl index 83ec762..3cb9b0f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -33,7 +33,7 @@ function test_linear_algebra_functions(A::AbstractMatrix) @try_catch results[func] = func(A) == func(matrix) end - computation_functions = [adjoint, transpose, det, eigvals] + computation_functions = [adjoint, transpose, det, logdet, eigvals] if determinant != 0 append!(computation_functions, [inv]) end