function logspace
logspace(
a: number,
b: number,
n?: number,
): array

Create logarithmically spaced arrays.

Generates an array of logarithmically spaced points between 10a and 10b (inclusive). If the number of points n is not provided, it defaults to 10.

Examples

Logarithmically spaced points from 100 to 101 with 5 points

import { assertEquals } from "jsr:@std/assert";

assertEquals(
  logspace(0, 1, 5),
  [1, 1.7782794100389228, 3.1622776601683795, 5.623413251903491, 10]
);

Default 10 points from 100 to 102

import { assertEquals } from "jsr:@std/assert";

assertEquals(
  logspace(0, 2),
  [
    1, 1.6681005372000588, 2.7825594022071245, 4.641588833612778,
    7.742636826811269, 12.91549665014884, 21.544346900318832, 35.93813663804626,
    59.94842503189409, 100,
  ]
);

Single point (start and end are the same)

import { assertEquals } from "jsr:@std/assert";

assertEquals(logspace(1, 1, 1), [10]);

Logarithmically spaced points from 10^-1 to 10^1

import { assertEquals } from "jsr:@std/assert";

assertEquals(logspace(-1, 1, 3), [0.1, 1, 10]);

Logarithmically spaced points from 103 to 104 with 4 points

import { assertEquals } from "jsr:@std/assert";

assertEquals(
  logspace(3, 4, 4),
  [1000, 2154.4346900318847, 4641.588833612777, 10000]
);

Parameters

a: number

The lower bound (exponent)

b: number

The upper bound (exponent)

optional
n: number = 10

The number of points to generate

Return Type

An array of logarithmically spaced points

Throws

If fewer than two arguments are provided