Message Boards Message Boards

0
|
23010 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Use a Wolfram Language equivalent to Matlab's "linspace" function?

Posted 5 years ago

Hello

Matlab has a built in function called linspace, that, according to the documentation, generates a linearly spaced vector, but "gives direct control over the number of points and always includes the endpoints".

Mathematica doesn't work with vectors, rather with lists, but I wish to generate a list of numbers that start from x1 and ends at x2, with n points in between (such that the spacing between the points is (x2-x1)/(n-1).

I couldn't find help with Table. Table generates a list of numbers with a starting point and an end point, with an extra option for the intervals, but I want to have n numbers in between.

Is there any work around?

POSTED BY: Ehud Behar
4 Replies

use:

Subdivide
POSTED BY: Sander Huisman
Posted 5 years ago
POSTED BY: Kyle Martin
Posted 2 years ago

You can also do

Array[f,n,{a,b}]

to generate a list of length n with elements f[i] with values from a to b.

For example

Array[Sin[2 \[Pi] 440 #] &, 100, {0, 1}]
POSTED BY: Ehud Behar
Posted 5 years ago

Thanks very much!

POSTED BY: Ehud Behar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract