Accelerating the pace of engineering and science

# istriu

Determine if matrix is upper triangular

## Description

example

tf = istriu(A) returns logical 1 (true) if A is an upper triangular matrix; otherwise, it returns logical 0 (false).

## Examples

expand all

### Test Upper Triangular Matrix

Create a 5-by-5 matrix.

`A = triu(magic(5))`
```A =

17    24     1     8    15
0     5     7    14    16
0     0    13    20    22
0     0     0    21     3
0     0     0     0     9```

Test A to see if it is upper triangular.

`istriu(A)`
```ans =

1
```

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

### Test Matrix of Zeros

Create a 5-by-5 matrix of zeros.

`Z = zeros(5);`

Test Z to see if it is upper triangular.

`istriu(Z)`
```ans =

1
```

The result is logical 1 (true) because an upper triangular matrix can have any number of zeros on the main diagonal.

## Input Arguments

expand all

### A — Input arraynumeric array

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

Data Types: single | double
Complex Number Support: Yes

expand all

### Upper Triangular Matrix

A matrix is upper triangular if all elements below the main diagonal are zero. Any number of the elements on the main diagonal can also be zero.

For example, the matrix

$A=\left(\begin{array}{cccc}1& -1& -1& -1\\ 0& \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}1& -2& -2\\ 0& \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}0& \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}1& -3\\ 0& \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}0& \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}0& \text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}1\end{array}\right)$

is upper triangular. A diagonal matrix is both upper and lower triangular.

### Tips

• Use the triu function to produce upper triangular matrices for which istriu returns logical 1 (true).

• The functions isdiag, istriu, and istril are special cases of the function isbanded, which can perform all of the same tests with suitably defined upper and lower bandwidths. For example, istriu(A) == isbanded(A,0,size(A,2)).