0
$\begingroup$

Is there a way to generate n numbers whose space between them grows incrementally and which that space varies between a min value and a max value? It's not important the domain of these numbers.

Is there a way to generate n numbers whose space between them grows incrementally and which that space varies between a min value and a max value? It's not important the domain of these numbers.

I immagine to create a procedure like this:

const serie = computeSerie(n, minSpace, maxSpace) 

// domain is not important, for example [1, +infinity] but also [0, 1], what you prefer

const serie1 = computeSerie(5, 1, 1) // [1, 2, 3, 4, 5]
const serie2 = computeSerie(5, 2, 2) // [1, 3, 5, 7, 9]
const serie3 = computeSerie(5, 1, 4) // [1, ...] I don't know, I suppose to use a pow math function (?)
const serie4 = computeSerie(7, 1, 6) // [1, 2, 4, 8, 13, 18, 24] I don't know if it is the right sequence

I need a sequence that visually is similar to:

Visually:

serie1: |-|-|-|-|
serie2: |--|--|--|--|
serie3: |-|???|--| 
serie4: |-|--|---|----|-----|------|

as you can see, serie4 is something that grows and the first distance is 1, the last one is 6 and in total it includes 7 numbers.

I've no idea what is the logic behind. Which is the best way (or simply a way) to create a sequence of number whose distance between them grows and with a fixed min and max distance?

$\endgroup$

1 Answer 1

1
$\begingroup$

This is not hard if you break it down step by step. First of all, let's name the values we need to work with.

Let $a_1 ... a_n$ be the sequence you want to generate.

Let $b$ be the smallest interval, and $c$ be the amount that each interval is incremented. So, the largest interval will be $b + (n-2)c$.

[edit:] If you have the largest interval, say $d$, then you can find the increment:
$d = b +(n-2)c \\ c = (d-b)/(n-2)$

And then we just put it all together:

$a_2 = a_1 + b \\ a_3 = a_2 + b + c \\ ... \\ a_{i+1} = a_i + b + (i-1)c \\ ... \\ a_n = a_{n-1} + b + (n-2)c \\ $

$\endgroup$
4
  • $\begingroup$ Thank you Caledon, bit it's a bit different. I need to fix the smallest and largest interval, not the the amount that each interval is incremented $\endgroup$ Oct 12, 2021 at 16:31
  • $\begingroup$ You're right. I used the increment because it makes the notation much simpler. If you know what the largest interval is, then it's pretty easy to calculate the increment. $\endgroup$
    – Caledon
    Oct 12, 2021 at 16:33
  • $\begingroup$ Last question: can you explain me why the largest interval is 𝑏+(𝑛−2)𝑐? $\endgroup$ Oct 13, 2021 at 6:33
  • 1
    $\begingroup$ the first interval is b. The 2nd interval is b + c. The 3rd is b + 2c. Continue like this. There are n-1 intervals; the final one will be b + (n-2)c. $\endgroup$
    – Caledon
    Oct 13, 2021 at 13:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .