RunMat
  • Pricing
RunMat
GitHub
GitHub
DownloadSign InTry in Browser
DesktopRuntimeServer
RunMat

Run math blazing fast

GitHubX (Twitter)LinkedIn

Company

  • About
  • Pricing
  • Contact

Explore

  • RunMat for academia
  • RunMat vs MATLAB Online
  • Benchmarks

Get product updates and release notes from the RunMat team.

© 2026 Dystr · Made withfor the scientific community.

RunMat™ is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

LicensePrivacy
/
See all docs
Builtin Reference
    • colon
    • createArray
    • empty
    • eye
    • false
    • full
    • inf
    • linspace
    • logspace
    • magic
    • meshgrid
    • nan
    • nchoosek
    • ndgrid
    • nonzeros
    • ones
    • peaks
    • perms
    • rand
    • randi
    • randn
    • randperm
    • range
    • sparse
    • spdiags
    • speye
    • spones
    • sprand
    • true
    • zeros

linspace — Generate linearly spaced row vectors in MATLAB and RunMat.

linspace(a, b, n) returns n linearly spaced points between a and b, inclusive. Default point count and row-vector output behavior follow MATLAB semantics.

Syntax

x = linspace(start, stop)
x = linspace(start, stop, n)

Inputs

NameTypeRequiredDefaultDescription
startNumericScalarYes—Starting value.
stopNumericScalarYes—Ending value.
nNumericScalarNo100Number of points.

Returns

NameTypeDescription
xNumericArrayRow vector of linearly spaced values.

Errors

IdentifierWhenMessage
—More than three input arguments are provided.linspace: expected at most three input arguments
—The count argument is not a numeric scalar value.linspace: number of points must be a scalar
—The count argument is infinite.linspace: number of points must not be infinite
—The count argument exceeds platform limits.linspace: number of points is too large for this platform

How linspace works

  • linspace(a, b) is equivalent to linspace(a, b, 100).
  • linspace(a, b, 0) returns a 1×0 empty row vector whose floating class follows the endpoints.
  • linspace(a, b, 1) returns b.
  • linspace(a, b, 2) returns [a b].
  • Complex end points are supported; the real and imaginary parts are interpolated independently.
  • Endpoints may be single- or double-precision scalars, 1×1 tensors, or GPU scalars; integer and logical endpoints are rejected.
  • The third argument may be a floating scalar or any of the eight integer classes. Finite floating counts are floored, non-positive counts produce an empty row vector, and infinite or platform-oversized counts raise an error.
  • A NaN count produces a 1×1 row vector containing NaN.

Does RunMat run linspace on the GPU?

GPU endpoints are downloaded only through their exact owner. For real output, RunMat first offers generation to that owner's linspace hook and validates the returned handle's shape, device, owner, precision, and non-aliasing. Otherwise it generates on the host and restores the result to the source owner when representable, preserving explicit or automatic provenance; complex output follows the same gather-and-restore rule.

GPU memory and residency

You usually do not need to call gpuArray yourself in RunMat. A resident endpoint selects its exact owning provider; endpoints from different devices are rejected. The runtime prefers that owner's linspace hook for real sequences. If direct generation is unavailable, it generates on the host and restores the result to the same owner when the provider supports the required real or complex class and precision; otherwise the correctly typed result remains on the host.

Examples

Creating five points between zero and one

x = linspace(0, 1, 5)

Expected output:

% Row vector with five equally spaced points
x = [0 0.25 0.5 0.75 1]

Sampling 100 points when the third argument is omitted

t = linspace(-pi, pi)

Expected output:

% t is a 1x100 row vector spanning [-pi, pi]
disp(t(1));
disp(t(end))

Constructing complex breakpoints

z = linspace(1+1i, -3+2i, 4)

Expected output:

z =
   1.0000 + 1.0000i   -0.3333 + 1.3333i   -1.6667 + 1.6667i   -3.0000 + 2.0000i

Staying on the GPU automatically

a = gpuArray(0);
b = gpuArray(2*pi);
theta = linspace(a, b, 1024);
wave = sin(theta)

Expected output:

% theta and wave remain on the GPU when an acceleration provider is active.
disp(gather(theta(1:5)))

Using linspace with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how linspace changes the result.

Run a small linspace example, explain the result, then change one input and compare the output.

FAQ

What is the default number of points?⌄

If you omit the third argument, RunMat uses 100 points, matching MATLAB.

Does linspace include the end points?⌄

Yes. The first element is exactly the start point a and the final element is exactly the end point b.

Can I request zero points?⌄

Yes. Zero and negative counts return a 1×0 empty row vector.

Does the third argument need to be an integer?⌄

No. RunMat floors a finite floating count, accepts exact scalar counts from every integer class, and maps non-positive counts to an empty result. Infinite and platform-oversized counts raise an error.

Does linspace support complex inputs?⌄

Yes. Real and imaginary components are interpolated independently. Mixed real and complex inputs return a complex row vector.

How accurate is the final point?⌄

The implementation explicitly overwrites the final element with b to avoid floating-point drift, matching MATLAB behaviour.

Can I pass GPU scalars?⌄

Yes. RunMat reads each endpoint through its exact owning provider. Real sequences use that provider's linspace hook when available; host-generated real or complex results are restored to the owner when it can represent the output class. Endpoints owned by different devices are rejected.

What precision is used?⌄

Double endpoints produce double output. If either endpoint is single precision, RunMat produces single output; a provider must support that precision to keep a restored result resident.

How does linspace differ from the colon operator?⌄

linspace lets you specify the number of points directly. The colon operator (start:step:end) fixes the spacing instead.

What happens when a equals b?⌄

Every element equals a (and b). For example, linspace(5, 5, 4) returns [5 5 5 5].

What does linspace do in MATLAB?⌄

linspace(a, b, n) generates a row vector of n evenly spaced points between a and b, inclusive. The default value of n is 100.

How is linspace different from the colon operator?⌄

The colon operator a:step:b specifies a step size and may not include the endpoint exactly. linspace(a, b, n) specifies the number of points and always includes both endpoints.

Can I use linspace to create logarithmically spaced points?⌄

Not directly. Use logspace(a, b, n) for logarithmic spacing, which is equivalent to 10.^linspace(a, b, n).

Does linspace work with complex numbers?⌄

Yes. linspace(1+2i, 5+10i, 5) linearly interpolates both the real and imaginary parts independently.

Can I use linspace with GPU arrays in RunMat?⌄

Yes. Pass compatible GPU scalars from one device. RunMat preserves their owning provider and provenance, using direct generation or one host-generation-and-restore fallback when possible.

Related Array functions

Creation

colon · createArray · empty · eye · false · full · inf · logspace · magic · meshgrid · nan · nchoosek · ndgrid · nonzeros · ones · peaks · perms · rand · randi · randn · randperm · range · sparse · spdiags · speye · spones · sprand · true · zeros

Grouping

accumarray · combinations · discretize · findgroups · groupcounts · grp2idx · splitapply

Sorting Sets

argsort · intersect · ismember · ismembertol · issorted · issortedrows · setdiff · setxor · sort · sortrows · union · unique

Shape

blkdiag · cat · circshift · diag · flip · fliplr · flipud · horzcat · ipermute · kron · permute · repelem · repmat · reshape · rot90 · squeeze · toeplitz · tril · triu · vertcat

Indexing

find · ind2sub · sub2ind

Introspection

iscolumn · isempty · ismatrix · isrow · isscalar · isvector · length · ndims · numel · size

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how linspace is executed, line by line, in Rust.

  • View the source for linspace in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • How linspace works
  • Does RunMat run linspace on the GPU?
  • GPU memory and residency
  • Examples
  • Creating five points between zero and one
  • Sampling 100 points when the third argument is omitted
  • Constructing complex breakpoints
  • Staying on the GPU automatically
  • Using linspace with coding agents
  • FAQ
  • Related Array functions
  • Creation
  • Grouping
  • Sorting Sets
  • Shape
  • Indexing
  • Introspection
  • Open-source implementation
  • About RunMat