Range

Range[imax]

generates the list {1,2,,imax}.

Range[imin,imax]

generates the list {imin,,imax}.

Range[imin,imax,di]

uses step di.

Details

  • The arguments to Range need not be integers.
  • Range starts from imin and successively adds increments of di until the result is greater than imax.
  • Range uses the standard Wolfram Language iteration specification, as applied to a single variable.
  • Range has attribute Listable.

Examples

open allclose all

Basic Examples  (3)

Scope  (6)

Use a step of 2:

Use a negative step:

Use an exact numeric-valued step:

Use a machine-number step:

Use a precision-24 step:

Range of very large numbers:

Generalizations & Extensions  (2)

Use a symbolic step:

Use a list of range specifications:

Applications  (4)

Produce a geometric sequence:

Form a polynomial from coefficients:

Form a random permutation:

Find an inverse permutation:

Properties & Relations  (2)

Range[imin,imax,di] is equivalent to Table[i,{imin,imax,di}]:

Use Range or Span (;;) as Part specification:

Possible Issues  (3)

For some step sizes, Range may not include the upper limit given:

Even though the lower limit was exact, the inexact step makes the first element inexact:

Range accepts Quantity expressions as limits and steps:

For Quantity expressions, Precision is taken into account when determining whether elements are within the bounds of the limits:

Neat Examples  (1)

Make nested ranges:

Show it in tree form:

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png

RelatedLinks-NKS.png