# Gradual increasing of step size for a range of values

**URL:** <https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152>\
**Category:** General Usage\
**Created:** [May 16, 2022, 2:48pm UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152 "2022-05-16T14:48:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![devanshu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devanshu/32/37104_2.png) [@devanshu](https://discourse.julialang.org/u/devanshu)\
**Post date:** [May 16, 2022, 2:48pm UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/1 "2022-05-16T14:48:23Z")

</div>

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,

```julia
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?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 16, 2022, 5:30pm UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/2 "2022-05-16T17:30:18Z")

</div>

You could use an appropriate pair of inverse functions to do the smooth mapping.

A simple example using square root and power of 2:

```julia
using Plots
n = 100
x1, x2 = 0.0, 5000.0
x = LinRange(√x1, √x2, n).^2
plot(scatter(x), scatter(diff(x)))

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 16, 2022, 9:54pm UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/3 "2022-05-16T21:54:31Z")

</div>

Here is another approach, where the range between `x1` and `x2` has a variable step increasing linearly between `dx1` and `dx2`:

```julia
# x1, x2 are respected; while dx1, dx2 approximately so:
function vrange(x1,x2,dx1,dx2)
    n = round(Int, 2*(x2 - x1)/(dx1 + dx2))
    dx = LinRange(dx1,dx2,n-1)
    x = cumsum([x1; dx])
    return (x2 - x1)/(x[end] - x[1])*(x .- x1) .+ x1
end

using Plots
x1, x2 = 0, 5000
dx1, dx2 = 1, 50
x = vrange(x1,x2,dx1,dx2)
plot(scatter(x), scatter(diff(x)), ms=3)

```

---

<div class="post-metadata">

**Author:** ![devanshu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devanshu/32/37104_2.png) [@devanshu](https://discourse.julialang.org/u/devanshu)\
**Post date:** [May 17, 2022, 3:25am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/5 "2022-05-17T03:25:01Z")

</div>

The `range` function gives `MethodError`, but `LinRange` works. I appreciate this simple approach though. Thank you!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 17, 2022, 5:56am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/6 "2022-05-17T05:56:27Z")

</div>

> [@devanshu](#):
>
> The `range` function gives `MethodError`

Sorry, the function `mean()` required `using Statistics`. This was not necessary and I modified the code above.

---

<div class="post-metadata">

**Author:** ![devanshu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devanshu/32/37104_2.png) [@devanshu](https://discourse.julialang.org/u/devanshu)\
**Post date:** [May 17, 2022, 6:10am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/7 "2022-05-17T06:10:09Z")

</div>

Actually, I was referring to your first approach above, the one with a slowly varying function. The `range` function is giving an error there.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 17, 2022, 6:49am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/9 "2022-05-17T06:49:43Z")

</div>

> [@devanshu](#):
>
> `range` function gives `MethodError`

Which Julia version are you using? It was working here for 1.7.2:

```julia
julia> versioninfo()
Julia Version 1.7.2

```

In any case, edited the code.

---

<div class="post-metadata">

**Author:** ![devanshu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devanshu/32/37104_2.png) [@devanshu](https://discourse.julialang.org/u/devanshu)\
**Post date:** [May 17, 2022, 6:58am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/10 "2022-05-17T06:58:07Z")

</div>

> [@rafael.guerra](#):
>
> It was working here for 1.7.2:

I see. I have 1.6.3, that’s why.

---

<div class="post-metadata">

**Author:** ![devanshu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devanshu/32/37104_2.png) [@devanshu](https://discourse.julialang.org/u/devanshu)\
**Post date:** [May 17, 2022, 6:59am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/11 "2022-05-17T06:59:42Z")

</div>

By the way, any quick way to update on Windows?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [May 17, 2022, 7:39am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/12 "2022-05-17T07:39:16Z")

</div>

It is recommended to use the Windows Store and run [Juliaup](https://discourse.julialang.org/t/ann-juliaup-preview-julia-version-manager-and-windows-store-installer/61920).

There is also [UpdateJulia](https://discourse.julialang.org/t/updatejulia/72128), which looks good but did not try it because using the former.

---

<div class="post-metadata">

**Author:** ![devanshu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/devanshu/32/37104_2.png) [@devanshu](https://discourse.julialang.org/u/devanshu)\
**Post date:** [May 17, 2022, 10:01am UTC](https://discourse.julialang.org/t/gradual-increasing-of-step-size-for-a-range-of-values/81152/13 "2022-05-17T10:01:59Z")

</div>

> [@rafael.guerra](#):
>
> There is also [UpdateJulia](https://discourse.julialang.org/t/updatejulia/72128), which looks good

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.
