ones range creates an Int64 array:
julia> o = ones(1:3)
3-element Array{Int64,1}:
1
1
1
julia> o[1] = 3.5
ERROR: InexactError()
in setindex!(::Array{Int64,1}, ::Float64, ::Int64) at ./array.jl:339
in eval(::Module, ::Any) at ./boot.jl:226
You cannot assign Float64 to an Int64 array (you get this error).
You want to simply use ones(n)to get a Float64 array:
julia> ones(3)
3-element Array{Float64,1}:
1.0
1.0
1.0
Note: you do not need collectbefore repeating in the range:
for k = collect(1:n)
instead, iterate over the range:
for k = 1:n
source
share