How to write xs[i]..xs[i+1] in Julia 1.5 , two dots

how to write in Julai 1.5

xs[i]..xs[i+1] in Julai 1.5

function make_intervals(N=10)
    xs = linspace(0, 2, N+1)
    return [xs[i]..xs[i+1] for i in 1:length(xs)-1]
end

Paul

what does this suppose to do?

1 Like

Not sure but I guess that you are trying to construct an array of intervals, in this case you need using IntervalArithmetic and then inside the function use the constructor interval(xs[i],xs[i+1]) or the macro @interval(xs[i],xs[i+1])

1 Like

Sorry for the format, used Julia on cell phone:

function make_intervals(a,b,N)
    x = range(a,b,length=N+1)
    return [[x[i], x[i+1]] for i in 1:N]
end

Result:

julia> make_intervals(0,2,10)    
10-element Array{Array{Float64,1},1}:                              
 [0.0, 0.2]
 [0.2, 0.4]                       
 [0.4, 0.6]                      
 [0.6, 0.8]
 [0.8, 1.0]
 [1.0, 1.2]
 [1.2, 1.4]                       
 [1.4, 1.6]
 [1.6, 1.8]
 [1.8, 2.0]

PS: could you please spell Julia correctly, three times “Julai” is a bit too much.

6 Likes

If you change linspace(0, 2, N+1) to range(a, b, length=N+1) as suggested by @rafael.guerra, the function works.

Note that you can also use the mince function:

make_interval(N=10) = mince(0 .. 2, N)

make_interval()
10-element Array{Interval{Float64},1}:
 [0, 0.200001]
    [0.2, 0.400001]
    [0.4, 0.6]
    [0.599999, 0.800001]
    [0.8, 1]
 [1, 1.2]
    [1.19999, 1.4]
    [1.39999, 1.60001]
    [1.6, 1.80001]
    [1.8, 2]
1 Like

Sorry to take over your post but, what it is this … notation that you use ? My Julia says it’s undefined.

1 Like

@HenriDeh, this thread concerns the package IntervalArithmetic.jl.