what does it mean x = -3:0.1:3 ? How it works?
Hi @Volodymyr_Pakholok, welcome to our forum. Please take time to format your questions and their titles appropriately. I have already corrected your prior post — please use that as a template/inspiration to edit this post.
For more details about asking questions here, see PSA: make it easier to help you.
I’ve unlisted this thread for now. Once the title is edited, I’ll be happy to restore it.
This is shorthand notation for a range from -3 to 3 (inclusive), with steps of size 0.1, i.e.:
julia> collect(-3:0.1:3)
61-element Vector{Float64}:
-3.0
-2.9
-2.8
-2.7
⋮
2.7
2.8
2.9
3.0
Here, I’ve used collect
to create a vector with every element of the range in it, however most of the time you don’t actually need to do this - it is more efficient to just work with the range, which only stores start and end point and stepsize:
julia> fieldnames(typeof(-3.0:0.1:3.0))
(:ref, :step, :len, :offset)
This allows you to create very large ranges at no extra cost:
julia> x = 1e10:0.1:1e15
1.0e10:0.1:1.0e15
julia> length(x)
9999900000000001
Here I’ve created a range that holds way more elements than I could fit in memory as Float64 - if I need any of them, they will be calculated on the fly:
julia> x[1_234_456_789]
1.01234456788e10