logspace — Generate logarithmically spaced row vectors in MATLAB and RunMat.
logspace(a, b, n) returns a row vector of logarithmically spaced points from 10^a to 10^b. When b is exactly pi, the final value is pi. Real or complex single endpoints produce single output when either endpoint is single; otherwise output is double.
Syntax
x = logspace(start, stop)
x = logspace(start, stop, n)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
start | NumericScalar | Yes | — | Starting exponent value. |
stop | NumericScalar | Yes | — | Ending exponent value. |
n | NumericScalar | No | 50 | Number of points. |
Returns
| Name | Type | Description |
|---|---|---|
x | NumericArray | Row vector of logarithmically spaced values. |
Errors
| Identifier | When | Message |
|---|---|---|
| — | More than three input arguments are provided. | logspace: expected two or three input arguments |
| — | The count argument is not a numeric scalar value. | logspace: number of points must be a scalar |
| — | The count argument is NaN or infinite. | logspace: number of points must be finite |
| — | The count argument exceeds platform limits. | logspace: number of points is too large for this platform |
RunMat:gpu:ProviderOwnershipMismatch | Resident scalar inputs do not have one exact owning provider. | logspace: GPU scalar inputs must have the same owning provider |
RunMat:logspace:GpuUploadFailed | An explicitly resident result cannot be restored to its source provider. | logspace: failed to preserve explicit gpuArray residency |
How logspace works
logspace(a, b)is equivalent tologspace(a, b, 50).logspace(a, b, 0)returns a1 × 0empty row vector whose precision follows the endpoints.logspace(a, b, 1)returns the effective final endpoint:10^b, orpiwhenbis exactlypi.logspace(a, b, 2)returns both effective endpoints.- Endpoints may be real or complex scalars. Complex inputs produce complex outputs using the analytic definition
10^z = e^{z ln 10}. - Endpoints must be real or complex single or double scalars. Integer and logical endpoints are rejected.
- Scalar inputs may be numeric literals,
1×1tensors, or GPU scalars. Non-scalar inputs raise an error. - The third argument must be a finite real numeric scalar. Fractional values are floored, and zero or negative values produce a
1 × 0row vector.
Does RunMat run logspace on the GPU?
Providers that implement linspace, scalar multiplication, and unary_exp can build real sequences entirely on the exact endpoint owner. If a hook is unavailable, explicit residency is restored to that same owner after host fallback, while automatic residency may return a host value. Complex explicit endpoints are computed on the host and uploaded back to their owner.
GPU memory and residency
GPU endpoints establish an exact device owner, and endpoints from different owners are rejected. Explicitly resident endpoints force the result back to that owner when fallback is needed. Automatically resident inputs may fall back to a host result. Large host-generated sequences may be automatically placed on the active provider when the offload threshold is met.
Examples
Creating decades between 10 and 1000
x = logspace(1, 3, 3)Expected output:
x = [10 100 1000]Generating logarithmic spacing with the default 50 points
f = logspace(1, 4)Expected output:
% f is a 1x50 row vector spanning [10, 10^4]
disp(f(1));
disp(f(end))Requesting a single logarithmic sample
edge = logspace(-3, 2, 1)Expected output:
edge = 100Building a swept frequency vector on the GPU
lo = gpuArray(0);
hi = gpuArray(3);
freq = logspace(lo, hi, 256);
resp = sin(2*pi*freq)Expected output:
% freq and resp remain on the GPU when an acceleration provider is active.
disp(gather(freq(1:5)))Producing complex logarithmic spacing
z = logspace(1+1i, 2+2i, 4)Expected output:
% Complex row vector with magnitudes and phases progressing logarithmically
disp(z)Matching MATLAB's legacy logspace(a, pi, n) syntax
theta = logspace(-1, pi, 5)Expected output:
% Interprets pi literally: theta(end) == pi
disp(theta(end))Using logspace with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how logspace changes the result.
Run a small logspace example, explain the result, then change one input and compare the output.
FAQ
What base does logspace use?⌄
RunMat follows MATLAB and always computes powers of ten. To use another base, build your own sequence (base .^ linspace(...)) or multiply the output by a constant factor.
Does logspace include both endpoints?⌄
Yes. The first element is exactly 10^a. The final element is exactly 10^b, except for the special b == pi form, whose final element is exactly pi.
Can I request zero points?⌄
Yes. logspace(a, b, 0) returns a 1 × 0 empty row vector.
What happens when a equals b?⌄
Every element equals 10^a. For example, logspace(2, 2, 4) returns [100 100 100 100].
Does logspace support complex endpoints?⌄
Yes. Real and imaginary components are interpolated independently, and the final values are computed using 10^z = e^{z ln 10}.
Is the third argument required to be an integer?⌄
No. Finite fractional counts are floored. Zero and negative counts return an empty 1 × 0 row vector.
Does the function support GPU scalars?⌄
Yes. Endpoint scalars are read without discarding their owner or explicit-residency provenance. Supported sequences are generated on that owner; explicit fallback restores the result to the same owner.
How accurate is the last element?⌄
The implementation explicitly overwrites the final element with the effective endpoint—10^b, or pi for the exact b == pi form—to avoid floating-point drift.
How does logspace differ from linspace?⌄
linspace spaces points linearly between two values, whereas logspace spaces points logarithmically between powers of ten.
Can I generate descending values?⌄
Yes. logspace(3, 1, 4) returns [1000 464.1589 215.4435 100], decreasing logarithmically.
Related Array functions
Creation
colon · createArray · empty · eye · false · full · inf · linspace · 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
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how logspace is executed, line by line, in Rust.
- View the source for logspace 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.