bandwidth - Lower and upper matrix bandwidth - MATLAB (original) (raw)

Lower and upper matrix bandwidth

Syntax

Description

[B](#bt6ati7-1-B) = bandwidth([A](#bt6ati7-1-A),[type](#bt6ati7-1-type)) returns the bandwidth of matrix A specified by type. Specify type as 'lower' for the lower bandwidth, or 'upper' for the upper bandwidth.

example

[[lower](#bt6ati7-1-lower),[upper](#bt6ati7-1-upper)] = bandwidth([A](#bt6ati7-1-A)) returns the lower bandwidth, lower, and upper bandwidth, upper, of matrix A.

example

Examples

collapse all

Create a 6-by-6 lower triangular matrix.

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.

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.

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.

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)

Input Arguments

collapse all

Input matrix, specified as a 2-D numeric matrix. A can be either full or sparse.

Data Types: single | double
Complex Number Support: Yes

Bandwidth type, specified as 'lower' or 'upper'.

Output Arguments

collapse all

Lower or upper bandwidth, returned as a nonnegative integer scalar.

Lower bandwidth, returned as a nonnegative integer scalar. lower is in the range 0lowersize(A,1)-1.

Upper bandwidth, returned as a nonnegative integer scalar. upper is in the range 0uppersize(A,2)-1.

More About

collapse all

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 _A_ij:

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

Extended Capabilities

expand all

Usage notes and limitations:

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).

Version History

Introduced in R2014a

expand all

The bandwidth supports C/C++ code generation for sparse matrix inputs.