Accelerating the pace of engineering and science

# bandwidth

Lower and upper matrix bandwidth

## Syntax

• [lower,upper] = bandwidth(A) example

## Description

example

B = bandwidth(A,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,upper] = bandwidth(A) returns the lower bandwidth, lower, and upper bandwidth, upper, of matrix A.

## Examples

expand all

### Find Bandwidth of Triangular Matrix

Create a 6-by-6 lower triangular matrix.

`A = tril(magic(6))`
```A =

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

`B = bandwidth(A,'lower')`
```B =

5```

The result is 5 because every diagonal below the main diagonal has nonzero elements.

Find the upper bandwidth of A by specifying type as 'upper'.

`B = bandwidth(A,'upper')`
```B =

0```

The result is 0 because there are no nonzero elements above the main diagonal.

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

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

The lower and upper bandwidths are both 3.

## Input Arguments

expand all

### A — Input matrix2-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. The lower bandwidth is the number of nonzero diagonals below the main diagonal.

• Specify 'upper' for the upper bandwidth. The upper bandwidth is the number of nonzero diagonals above the main diagonal.

Data Types: char

## Output Arguments

expand all

### B — Lower or upper bandwidthnonnegative integer scalar

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

• If type is 'lower', then B is the number of nonzero diagonals below the main diagonal and 0 ≤ B ≤ size(A,1)-1.

• If type is 'upper', then B is the number of nonzero diagonals above the main diagonal and 0 ≤ B ≤ size(A,2)-1.

### lower — Lower bandwidthnonnegative integer scalar

Lower bandwidth, returned as a nonnegative integer scalar. The lower bandwidth is the number of nonzero diagonals below the main diagonal. lower is in the range 0 ≤ lower ≤ size(A,1)-1.

### upper — Upper bandwidthnonnegative integer scalar

Upper bandwidth, returned as a nonnegative integer scalar. The upper bandwidth is the number of nonzero diagonals above the main diagonal. upper is in the range 0 ≤ upper ≤ size(A,2)-1.

expand all

### Bandwidth

The upper and lower bandwidths of a matrix are the number of nonzero diagonals above and below the main diagonal, respectively.

In terms of the upper and lower bandwidths, the total bandwidth of the matrix is equal to upper + lower + 1.

### Tips

• Use the isbanded function to test if a matrix is within a specific lower and upper bandwidth.