How to take union of interval elements in Interval Vector?

You could do something like within IntervalArithemtic:

julia> using IntervalArithmetic

julia> X = [Interval(0.0, 0.1), Interval(1,2), Interval(0.1, 0.2), Interval(9,10), Interval(2,3), Interval(0.2, 0.3), Interval(10,11), Interval(2,3), Interval(9,10)];

julia> XY = Set{Interval{Float64}}()
Set{Interval{Float64}}()

julia> for x in X
    any(x .⊆ XY) && continue
    for y in X
        (x == y || isempty(x ∩ y)) && continue
        x = hull(x, y)
    end
    push!(XY, x)
end

julia> XY
Set{Interval{Float64}} with 3 elements:
  [0, 0.3]
  [1, 3]
  [9, 11]
2 Likes