• Generates an array of evenly spaced numbers between x1 and x2.

    By default, the range is exclusive of the endpoint (x2). If the inclusive option is set to true, the endpoint will be included.

    Parameters

    • x1: number

      The starting value of the range.

    • x2: number

      The ending value of the range.

    • n: number = 100

      The number of intervals to divide the range into. Defaults to 100.

    • inclusive: boolean = false

      Whether to include the endpoint (x2) in the range. Defaults to false.

    Returns number[]

    An array of evenly spaced numbers between x1 and x2.

    const result = linspace(0, 1, 5);
    // Returns [0, 0.2, 0.4, 0.6, 0.8]

    const result2 = linspace(0, 1, 5, true);
    // Returns [0, 0.25, 0.5, 0.75, 1]

    const result3 = linspace(10, 20, 2, true);
    // Returns [10, 20]