bandwidth — Compute matrix structural bandwidth or SISO transfer-function frequency bandwidth.
For a matrix, bandwidth(A) returns lower and optional upper structural bandwidth. For a scalar SISO tf model, bandwidth(sys, dbdrop) returns the first downward frequency-response gain-drop crossing in rad/s.
Syntax
[lower, upper] = bandwidth(A)
b = bandwidth(A, selector)
w = bandwidth(sys, dbdrop)Inputs
A- Type
Any- Required
- Yes
- Description
- Input matrix.
selector- Type
Any- Required
- No
- Description
- Selector string: "lower" or "upper".
sys- Type
Any- Required
- Yes
- Description
- Zero-delay scalar SISO tf model.
dbdrop- Type
NumericScalar- Required
- No
- Default
-3- Description
- Finite negative gain drop in decibels.
Returns
lower- Type
NumericScalar- Description
- Lower bandwidth scalar.
upper- Type
NumericScalar- Description
- Upper bandwidth scalar.
b- Type
NumericScalar- Description
- Selected lower or upper bandwidth scalar.
Returned values from bandwidth depend on how many outputs the caller requests.
Errors
RunMat:bandwidth:InvalidArgument- When
- Selector argument is invalid or argument count exceeds supported forms.
- Message
bandwidth: invalid argument
RunMat:bandwidth:InvalidInput- When
- Input type/shape cannot be processed as a numeric or logical 2-D matrix.
- Message
bandwidth: invalid input
RunMat:bandwidth:Internal- When
- Runtime fails while constructing intermediate tensors or values.
- Message
bandwidth: internal runtime failure
RunMat:bandwidth:UnsupportedModel- When
- A transfer function is well formed but outside the current zero-delay scalar SISO physical-frequency subset.
- Message
bandwidth: unsupported model
Transfer-function frequency bandwidth
For a zero-delay scalar SISO tf model, bandwidth(sys) returns the first physical frequency where the response falls below its nonzero finite DC magnitude by 3 dB. bandwidth(sys, dbdrop) selects a finite negative dB drop. The result is a host double scalar in rad/s; Inf means no downward crossing in the supported domain.
Continuous models and discrete models with a known positive sample period are supported. An unspecified discrete sample period, state-space or MIMO model, delay, or zero/infinite DC gain is not yet supported. The host evaluator uses the model's physical s/z polynomial view; finite managed calls require a complete output owner and otherwise fail before evaluation. This overload never invokes the matrix/GPU structure hook.
Behavior and supported arrays
bandwidth(A) inspects the nonzero pattern of matrix A and returns the lower bandwidth as its first output and the upper bandwidth as its optional second output. A 'lower' or 'upper' selector returns one side.
lower = bandwidth(A) returns the lower bandwidth. [lower, upper] = bandwidth(A) returns separate lower and upper double scalars. A diagonal matrix has zero for both, and each side counts the furthest nonzero from the main diagonal.
bandwidth(A, 'lower') returns only the lower bandwidth, while bandwidth(A, 'upper') returns only the upper bandwidth.
RunMat accepts full or sparse single/double real or complex matrices. RunMat mode additionally accepts full or sparse logical matrices and all eight real integer classes, plus paired complex-integer dense matrices; MATLAB-compatible mode rejects those extensions before host or provider dispatch.
Sparse CSC column indices and authoritative typed stored values are scanned directly without densifying. Explicitly stored numeric zeros are ignored; logical sparse pattern entries are true. Exact integer zero tests never cross a floating conversion. Outputs remain double scalar metadata.
Nonzero detection treats any value that is not numerically equal to zero (including NaN or Inf) as nonzero, matching MATLAB semantics.
Empty matrices and all-zero matrices report zero for both the lower and upper outputs.
Inputs must be two-dimensional matrices. Higher-dimensional arrays (with any dimension beyond the second larger than one) raise an error.
Complex matrices are supported. A complex entry counts as nonzero if either the real or imaginary part is nonzero.
GPU residency and provider behavior
Documented single/double GPU inputs use the provider bandwidth hook when available and otherwise gather. Integer and logical GPU inputs are gated RunMat extensions; admitted values gather exactly before the floating-only provider hook and return host double scalar metadata.
bandwidth leverages the active acceleration provider for documented floating input when available. The WGPU backend scans the matrix on-device and reads back lower/upper metadata. Providers without the hook gather and reuse the CPU implementation. Admitted integer/logical extensions gather before provider dispatch so packed typed buffers are never interpreted by floating shaders.
Runs a device-side reduction when the acceleration provider implements the bandwidth hook; falls back to gathering on providers without support.
Examples
Frequency bandwidth of a low-pass model
H = tf(1, [1 1]); w = bandwidth(H); fprintf("%.2f\n", w);Expected output:
1.00Checking the bandwidth of a diagonal matrix
A = eye(4);
bw = bandwidth(A)Expected output:
bw = 0Requesting only the lower bandwidth
A = [-1 0 0; 2 3 0; 4 5 6];
lower_bw = bandwidth(A, 'lower')Expected output:
lower_bw = 2Requesting only the upper bandwidth
B = [1 2 0 0; 0 3 4 0; 0 0 5 6];
upper_bw = bandwidth(B, 'upper')Expected output:
upper_bw = 1Analysing a rectangular matrix
C = [0 0 7; 8 0 0; 0 9 0; 0 0 10];
[lower, upper] = bandwidth(C)Expected output:
lower = 1, upper = 2Working with complex-valued matrices
Z = [1+2i 0; 0 3-4i; 5i 0];
[lower, upper] = bandwidth(Z)Expected output:
lower = 2, upper = 0Inspecting a GPU-resident matrix
G = gpuArray([0 1 0; 2 0 3; 0 0 0]);
[lower, upper] = bandwidth(G)Expected output:
lower = 1, upper = 1Using bandwidth with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how bandwidth changes the result.
Run a small bandwidth example, explain the result, then change one input and compare the output.
FAQ
How does bandwidth distinguish a matrix from a control model?⌄
A canonical tf object selects frequency bandwidth; numeric, logical, sparse and GPU matrices retain the lower/upper structural-bandwidth forms.
What do lower and upper bandwidths of zero mean?⌄
Separate lower and upper outputs of zero indicate that all nonzero elements are on the main diagonal.
How are rows or columns full of zeros handled?⌄
Zero rows or columns do not increase the bandwidth; only nonzero entries affect the result.
Does bandwidth treat NaN values as nonzero?⌄
Yes. Any value that is not exactly zero—including NaN or Inf—counts as nonzero.
Can I request only the lower or upper bandwidth?⌄
Yes. Pass 'lower' or 'upper' as the second argument to obtain a scalar result.
Why does bandwidth error on higher-dimensional arrays?⌄
The builtin matches MATLAB and only operates on two-dimensional matrices. Use reshape to collapse trailing singleton dimensions before calling bandwidth.
Does bandwidth work with sparse matrices?⌄
Yes. Host sparse CSC inputs are scanned without converting to a dense matrix; explicitly stored numeric zeros do not contribute to either bandwidth.
What precision does the result use?⌄
The result is always returned as double precision (double), matching MATLAB.
Will this function keep my data on the GPU?⌄
Documented floating input stays resident when the provider implements the hook, with only lower/upper metadata read back. Providers without the hook gather. Integer and logical extension inputs gather exactly before provider dispatch.
Can I call bandwidth inside fused expressions?⌄
Yes. The builtin returns host double scalar metadata, so it behaves like other metadata queries.
What happens if I pass logical matrices?⌄
Logical input is a gated RunMat extension because the documented matrix domain is single/double. In RunMat mode, true entries count as nonzero.
Related Linalg functions
Structure
isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Source you can read
Every RunMat function's source is public. Read exactly how bandwidth is executed, line by line, in Rust.
- View the source for bandwidth in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.