bandwidth
Lower and upper matrix bandwidth
Description
Examples
Find Bandwidth of Triangular Matrix
Create a 6-by-6 lower triangular matrix.
A = tril(magic(6))
A = 6×6
35 0 0 0 0 0
3 32 0 0 0 0
31 9 2 0 0 0
8 28 33 17 0 0
30 5 34 12 14 0
4 36 29 13 18 11
Find the lower bandwidth of A
by specifying type
as 'lower'
. The result is 5 since every diagonal below the main diagonal has nonzero elements.
B = bandwidth(A,'lower')
B = 5
Find the upper bandwidth of A
by specifying type
as 'upper'
. The result is 0 since there are no nonzero elements above the main diagonal.
B = bandwidth(A,'upper')
B = 0
Find Bandwidth of Sparse Block Matrix
Create a 100-by-100 sparse block matrix.
B = kron(speye(25),ones(4));
View a 10-by-10 section of elements from the top left of B
.
full(B(1:10,1:10))
ans = 10×10
1 1 1 1 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0
0 0 0 0 1 1 1 1 0 0
0 0 0 0 1 1 1 1 0 0
0 0 0 0 1 1 1 1 0 0
0 0 0 0 1 1 1 1 0 0
0 0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 1 1
B
has 4-by-4 blocks of ones centered on the main diagonal.
Find both the lower and upper bandwidths of B
by specifying two output arguments.
[lower,upper] = bandwidth(B)
lower = 3
upper = 3
Input Arguments
A
— Input matrix
2-D numeric matrix
Input matrix, specified as a 2-D numeric matrix. A
can
be either full or sparse.
Data Types: single
| double
Complex Number Support: Yes
type
— Bandwidth type
'lower'
| 'upper'
Bandwidth type, specified as 'lower'
or 'upper'
.
Specify
'lower'
for the lower bandwidth (below the main diagonal).Specify
'upper'
for the upper bandwidth (above the main diagonal).
Output Arguments
B
— Lower or upper bandwidth
nonnegative integer scalar
Lower or upper bandwidth, returned as a nonnegative integer scalar.
If
type
is'lower'
, then0
≤B
≤size(A,1)-1
.If
type
is'upper'
, then0
≤B
≤size(A,2)-1
.
lower
— Lower bandwidth
nonnegative integer scalar
Lower bandwidth, returned as a nonnegative integer scalar. lower
is
in the range 0
≤ lower
≤ size(A,1)-1
.
upper
— Upper bandwidth
nonnegative integer scalar
Upper bandwidth, returned as a nonnegative integer scalar. upper
is
in the range 0
≤ upper
≤ size(A,2)-1
.
More About
Upper and Lower Bandwidth
The upper and lower bandwidths of a matrix are measured by finding the last diagonal (above or below the main diagonal, respectively) that contains nonzero values.
That is, for a matrix A with elements Aij:
The upper bandwidth B1 is the smallest number such that whenever .
The lower bandwidth B2 is the smallest number such that whenever .
Note that this measurement does not disallow intermediate diagonals in a band from being all zero, but instead focuses on the location of the last diagonal containing nonzeros. By convention, the upper and lower bandwidths of an empty matrix are both zero.
Tips
Use the
isbanded
function to test if a matrix is within a specific lower and upper bandwidth.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Code generation does not support sparse matrix inputs for this function.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The bandwidth
function
fully supports GPU arrays. To run the function on a GPU, specify the input data as a gpuArray
(Parallel Computing Toolbox). For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2014a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)