Accelerating the pace of engineering and science

# isbanded

Determine if matrix is within specific bandwidth

## Syntax

• tf = isbanded(A,lower,upper) example

## Description

example

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

## Examples

expand all

### Test Square Matrix

Create a 5-by-5 square matrix.

`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 =

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```

The result is a square matrix with nonzero diagonals above and below the main diagonal.

Specify both bandwidths, lower and upper, as 1 to test if A is tridiagonal.

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

1
```

The result is logical 1 (true).

Test if A has nonzero elements below the main diagonal by specifying lower as 0.

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

0```

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

### Test Nonsquare Matrix

Create a 3-by-5 matrix.

`A = [1 0 0 0 0; 2 1 0 0 0; 3 2 1 0 0]`
```A =

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

The result is a rectangular matrix.

Test if A has nonzero elements above the main diagonal.

`isbanded(A,2,0)`
```ans =

1```

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

### Test Sparse Block Matrix

Create a 100-by-100 sparse block matrix.

`B = kron(speye(25),ones(4));`

Test if B has a lower and upper bandwidth of 1.

`isbanded(B,1,1)`
```ans =

0```

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

Test if B has a lower and upper bandwidth of 3.

`isbanded(B,3,3)`
```ans =

1```

The result is logical 1 (true). The matrix, B, has an upper and lower bandwidth of 3 since the nonzero diagonal blocks are 4-by-4.

## Input Arguments

expand all

### A — Input arraynumeric array

Input array, specified as a numeric array. isbanded returns logical 0 (false) if A has more than two dimensions.

Data Types: single | double
Complex Number Support: Yes

### lower — Lower bandwidthnonnegative integer scalar

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 — Upper bandwidthnonnegative integer scalar

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

expand all

### 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. The table below lists some common tests.

Lower Bandwidth

Upper Bandwidth

Function Call

Tests for

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