Create sequence with equal distance between items

234 Views Asked by At

How do I create a sequence of $N = 10$ numbers starting from 0 to $T = 1$ with equal distance between each element in Maple.

How do I obtain this? I am thinking that it could be something like $$ \left\{ \frac{i - 1}{N - 1} \cdot T \right\}_{i=1}^N $$ where $T = 1$ and $N = 10$ translated to seq((i-1)*T / (N-1), i=1..N), but it seems a bit complex.

Is this the right way to do it? Does it have a name (e.g. equadistant sequence)?

Also, what would it look like if I wanted if the first number should be different from $0$?

2

There are 2 best solutions below

2
On BEST ANSWER

You are looking to create an Arithmetic sequence with a starting term of $a= 0$

since you are adding $10$ terms between them , the last term $1$ is given by;

$1= 0+(N+2-1)d$ $\quad$ where $d$ is the common difference

$d = \frac1{N+1}$

since you are adding $10 $ terms here $N=10$

$\implies d = \frac1{11}$

so the terms are given by $a_n = 0+(n-1)\frac1{11}$

which is $0,\frac1{11},\frac2{11},\frac3{11},\frac4{11}\cdots1$

In general if you want to add $N $ terms between two numbers $a$ and $b$, the common difference is $d= \frac{b-a}{N+1}$

and the terms are $a_n = a+(n-1)\frac{b-a}{N+1}$

0
On
a := 0:                                        
b := 1:                                        
N := 10:                                       

seq( a + (n-1) * (b-a) / (N-1) , n = 1 .. N );

         0, 1/9, 2/9, 1/3, 4/9, 5/9, 2/3, 7/9, 8/9, 1

[start of edit] There is a slightly simpler syntax for that, though it still requires you to supply the common difference.

seq( x, x = a .. b, (b-a)/(N-1) );

         0, 1/9, 2/9, 1/3, 4/9, 5/9, 2/3, 7/9, 8/9, 1

And in more recent versions of Maple there is this terser form,

seq( a .. b, (b-a)/(N-1) );

         0, 1/9, 2/9, 1/3, 4/9, 5/9, 2/3, 7/9, 8/9, 1

It's quite a common task, and recently I've been considering putting in a Maple tech-support request for something like the following (which I've just "made up",

seq( a .. b,  numterms=N );

[end of edit]

NB. The formula given by The Integrator, ie, a+(n-1)*(b-a)/(N+1) is incorrect. The common difference should is (b-a)/(N-1) and not (b-a)/(N+1).

Between ten evenly spaced things there are nine separating segments. This is analogous to the inverse of the so-called fencepost problem, where that question is about how many posts are needed for a given number of equal segments. Your question involved figuring out how many segments there are between the given number of posts.

The Integrator has an "off-by-two error" rather than the more common "off-by-one error". It's an understandable slip, to compensate "the wrong way".

seq( a + (n-1) * (b-a) / (N+1) , n = 1 .. N );

  0, 1/11, 2/11, 3/11, 4/11, 5/11, 6/11, 7/11, 8/11, 9/11

seq( a + (n-1) * (b-a) / (N+1) , n = 1 .. 12 );

                                                           10
  0, 1/11, 2/11, 3/11, 4/11, 5/11, 6/11, 7/11, 8/11, 9/11, --, 1
                                                           11