# Documentation

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

# isdiag

Determine if matrix is diagonal

## Description

example

tf = isdiag(A) returns logical 1 (true) if A is a diagonal matrix; otherwise, it returns logical 0 (false).

## Examples

collapse all

### Test Diagonal Matrix

Create a 4-by-4 identity matrix.

I = eye(4)
I =

1     0     0     0
0     1     0     0
0     0     1     0
0     0     0     1

Test to see if the matrix is diagonal.

isdiag(I)
ans =

1

The result is logical 1 (true) because all of the nonzero elements in I are on the main diagonal.

### Test Banded Matrix

Create a matrix with nonzero elements on the main and first diagonals.

A = 3*eye(4) + diag([2 2 2],1)
A =

3     2     0     0
0     3     2     0
0     0     3     2
0     0     0     3

Test to see if the matrix is diagonal.

isdiag(A)
ans =

0

The matrix is not diagonal since there are nonzero elements above the main diagonal.

Create a new matrix, B, from the main diagonal elements of A.

B = diag(diag(A));

Test to see if B is a diagonal matrix.

isdiag(B)
ans =

1

The result is logical 1 (true) because there are no nonzero elements above or below the main diagonal of B.

## Input Arguments

collapse all

### A — Input arraynumeric array

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

Data Types: single | double
Complex Number Support: Yes

collapse all

### Diagonal Matrix

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

For example, the 4-by-4 identity matrix,

${I}_{4}=\left(\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\\ 0& 0& 0& 1\end{array}\right)$

is a diagonal matrix. Diagonal matrices are typically, but not always, square.

### Tips

• Use the diag function to produce diagonal matrices for which isdiag 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, isdiag(A) == isbanded(A,0,0).