Skip to content

Commit da96fef

Browse files
author
Regan Koopmans
authored
Correct lyap definition for complex scalar arguments (#39901)
1 parent ae26fc6 commit da96fef

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

stdlib/LinearAlgebra/src/dense.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1568,4 +1568,4 @@ function lyap(A::StridedMatrix{T}, C::StridedMatrix{T}) where {T<:BlasFloat}
15681568
rmul!(Q*(Y * adjoint(Q)), inv(scale))
15691569
end
15701570
lyap(A::StridedMatrix{T}, C::StridedMatrix{T}) where {T<:Integer} = lyap(float(A), float(C))
1571-
lyap(a::T, c::T) where {T<:Number} = -c/(2a)
1571+
lyap(a::Union{Real,Complex}, c::Union{Real,Complex}) = -c/(2real(a))

stdlib/LinearAlgebra/test/dense.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,10 @@ end
767767
@test diag(zeros(0,1),2) == []
768768
end
769769

770+
@testset "issue #39857" begin
771+
@test lyap(1.0+2.0im, 3.0+4.0im) == -1.5 - 2.0im
772+
end
773+
770774
@testset "Matrix to real power" for elty in (Float64, ComplexF64)
771775
# Tests proposed at Higham, Deadman: Testing Matrix Function Algorithms Using Identities, March 2014
772776
#Aa : only positive real eigenvalues

0 commit comments

Comments
 (0)