Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added constructor for complex interval matrices #184

Merged
merged 2 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/matrix.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base: similar, ∈, ⊆, ∩, ∪
import Base: similar, ∈, ⊆, ∩, ∪, real, imag
import Random: rand
import IntervalArithmetic: ±, inf, sup, mid, diam, radius, midpoint_radius, hull

Expand Down Expand Up @@ -83,6 +83,10 @@ function IntervalMatrix(A::MT) where {T, IT<:AbstractInterval{T}, MT<:AbstractMa
return IntervalMatrix{T, IT, MT}(A)
end

function IntervalMatrix(A::MT) where {T, IT<:Complex{Interval{T}}, MT <:AbstractMatrix{IT}}
return IntervalMatrix{T, IT, MT}(A)
end

# constructor from uniform scaling
function IntervalMatrix(αI::UniformScaling{Interval{T}}, m::Integer, n::Integer=m) where {T}
return IntervalMatrix(Matrix(αI, m, n))
Expand Down
4 changes: 4 additions & 0 deletions src/operations/numops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ A pair `(C, S)` such that the entries of `C` are the central points and the
entries of `S` are the (nonnegative) radii of the intervals in `A`.
"""
midpoint_radius(A::IntervalMatrix) = (mid(A), radius(A))


real(M::IntervalMatrix) = IntervalMatrix(real(M.mat))
imag(M::IntervalMatrix) = IntervalMatrix(imag(M.mat))
18 changes: 18 additions & 0 deletions test/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@ end
@test c ≈ [-0.1 -4.; 4. -0.1]
@test s ≈ [1. 0.1; 0.1 1.]
end

@testset "Complex interval matrices" begin
m1 = IntervalMatrix([(1..2)+im*(3..4) 1;2 3])
@test m1 isa IntervalMatrix{Float64}
@test eltype(m1) == Complex{Interval{Float64}}

rp = real(m1)
ip = imag(m1)
@test rp isa IntervalMatrix{Float64}
@test eltype(rp) == Interval{Float64}

@test ip isa IntervalMatrix{Float64}
@test eltype(ip) == Interval{Float64}

m2 = IntervalMatrix([1+im 2+im;3+im 4+im])
@test m2 isa IntervalMatrix{Float64}
@test eltype(m2) == Complex{Interval{Float64}}
end