# isbanded

Determine if matrix is within specific bandwidth

## Syntax

``tf = isbanded(A,lower,upper)``

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

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

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

`isbanded(A,1,1)`
```ans = logical 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 = logical 0 ```

The result is logical `0` (`false`) because `A` 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 `A` has nonzero elements 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.

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

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

`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 `B` has a lower and upper bandwidth of `3`.

`isbanded(B,3,3)`
```ans = logical 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

collapse all

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

Lower Bandwidth

Upper Bandwidth

Function Call

Tests for

`0``0``isbanded(A,0,0)`

Diagonal matrix

`1``1``isbanded(A,1,1)`

Tridiagonal matrix

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

Upper triangular matrix

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

Lower triangular matrix

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

Upper Hessenberg matrix

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

Lower Hessenberg matrix