Main Content

isbanded

Determine if matrix is within specified bandwidth

Description

example

tf = isbanded(A,lower,upper) returns logical 1 (true) if A is a matrix within the specified lower and upper bandwidths. Otherwise, it returns logical 0 (false).

Examples

collapse all

Create a 5-by-5 square matrix with nonzero diagonals above and below the main diagonal.

A = [2 3 0 0 0; 1 -2 -3 0 0; 0 -1 2 3 0; 0 0 1 -2 -3; 0 0 0 -1 2]
A = 5×5

     2     3     0     0     0
     1    -2    -3     0     0
     0    -1     2     3     0
     0     0     1    -2    -3
     0     0     0    -1     2

Test if the matrix is tridiagonal by specifying both the lower and upper bandwidths as 1.

isbanded(A,1,1)
ans = logical
   1

The matrix is tridiagonal because it has nonzero elements only on the main diagonal and the diagonals above and below the main diagonal.

Test if the matrix has only elements with a value of 0 below the main diagonal by specifying the lower bandwidth as 0.

isbanded(A,0,1)
ans = logical
   0

The result is logical 0 (false) because the matrix has nonzero elements below the main diagonal.

Create a 3-by-5 matrix.

A = [1 0 0 0 0; 2 1 0 0 0; 3 2 1 0 0]
A = 3×5

     1     0     0     0     0
     2     1     0     0     0
     3     2     1     0     0

Test if the matrix has only elements with a value of 0 above the main diagonal.

isbanded(A,2,0)
ans = logical
   1

The result is logical 1 (true) because the elements above the main diagonal are all zero.

Create a 100-by-100 sparse block matrix. Test if the matrix is within a lower and upper bandwidth of 1.

B = kron(speye(25),ones(4));
isbanded(B,1,1)
ans = logical
   0

The result is logical 0 (false) because the nonzero blocks centered on the main diagonal are larger than 2-by-2.

Test if the matrix is within a lower and upper bandwidth of 3.

isbanded(B,3,3)
ans = logical
   1

The matrix has an upper and lower bandwidth of 3 because the nonzero diagonal blocks are 4-by-4.

Input Arguments

collapse all

Input array. isbanded returns logical 0 (false) if A has more than two dimensions.

Data Types: single | double | logical
Complex Number Support: Yes

Lower bandwidth, specified as a nonnegative integer scalar. The lower bandwidth is the number of nonzero diagonals below the main diagonal. isbanded returns logical 0 (false) if there are nonzero elements below the boundary diagonal, diag(A,-lower).

Upper bandwidth, specified as a nonnegative integer scalar. The upper bandwidth is the number of nonzero diagonals above the main diagonal. isbanded returns logical 0 (false) if there are nonzero elements above the boundary diagonal, diag(A,upper).

Tips

  • Use the bandwidth function to find the upper and lower bandwidths of a given matrix.

  • Use isbanded to test for several different matrix structures by specifying appropriate upper and lower bandwidths. This table lists some common tests.

    Lower Bandwidth

    Upper Bandwidth

    Function Call

    Matrix Structure

    00isbanded(A,0,0)

    Diagonal matrix

    11isbanded(A,1,1)

    Tridiagonal matrix

    0size(A,2)isbanded(A,0,size(A,2))

    Upper triangular matrix

    size(A,1)0isbanded(A,size(A,1),0)

    Lower triangular matrix

    1size(A,2)isbanded(A,1,size(A,2))

    Upper Hessenberg matrix

    size(A,1)1isbanded(A,size(A,1),1)

    Lower Hessenberg matrix

Extended Capabilities

Version History

Introduced in R2014a