Hi, I want to create an array of values ranging from 1 to 5000. For this, I use
LinRange(0, 5000, 200). However, for my purpose, I need more points for the lower regime compared to the higher ones. For this I tried,
params_1 = LinRange(0, 100, 100)
params_2 = LinRange(101, 5000, 100)
params = vcat(params_1, params_2)
But while plotting this showcases a clear discontinuity, which I want to avoid. So I was wondering if there was any better way to get gradually increase the step size in this interval?
You could use an appropriate pair of inverse functions to do the smooth mapping.
A simple example using square root and power of 2:
n = 100
x1, x2 = 0.0, 5000.0
x = LinRange(√x1, √x2, n).^2
Here is another approach, where the range between
x2 has a variable step increasing linearly between
# x1, x2 are respected; while dx1, dx2 approximately so:
n = round(Int, 2*(x2 - x1)/(dx1 + dx2))
dx = LinRange(dx1,dx2,n-1)
x = cumsum([x1; dx])
return (x2 - x1)/(x[end] - x)*(x .- x1) .+ x1
x1, x2 = 0, 5000
dx1, dx2 = 1, 50
x = vrange(x1,x2,dx1,dx2)
plot(scatter(x), scatter(diff(x)), ms=3)
range function gives
LinRange works. I appreciate this simple approach though. Thank you!
Sorry, the function
using Statistics. This was not necessary and I modified the code above.
Actually, I was referring to your first approach above, the one with a slowly varying function. The
range function is giving an error there.
Which Julia version are you using? It was working here for 1.7.2:
Julia Version 1.7.2
In any case, edited the code.
I see. I have 1.6.3, that’s why.
By the way, any quick way to update on Windows?
It is recommended to use the Windows Store and run Juliaup.
There is also UpdateJulia, which looks good but did not try it because using the former.
Yes, I am actually trying that, because I am not sure, but it seems for using Juliaup, I need to reinstall Julia from the Microsoft store, which seems cumbersome.