MATDIAGONAL — PETSc 3.25.0 documentation

Skip to main content
`Ctrl`+`K`

# MATDIAGONAL

MATDIAGONAL = “diagonal” - A diagonal matrix type with the diagonal implemented as a `Vec`. Useful for cases where `VecPointwiseMult()` or `VecPointwiseDivide()` should be thought of as the actions of a linear operator.

## Note

The first use case is simply to call `MatCreateDiagonal()’ to provide the vector containing the diagonal matrix. The input vector will be referenced internally by the matrix: any changes to it will affect the matrix. Similar changes to the matrix will affect the vector.

For the second use case call `MatSetType()` with a type of `MATDIAGONAL` followed by a call to `MatDiagonalSetDiagonal()`. The input vector will be referenced internally by the matrix: any changes to it will affect the matrix. Similar changes to the matrix will affect the vector.

For the third use case call `MatSetType()` with a type of `MATDIAGONAL` followed by a calls to `MatSetSizes()` and `MatDiagonalSet()`. In this case the diagonal vector will not be referenced internally by the matrix, its values will be copied.

## See Also

Matrices, `Mat`, `MatCreateDiagonal()`, `MatDiagonalRestoreInverseDiagonal()`, `MatDiagonalGetDiagonal()`, `MatDiagonalRestoreDiagonal()`, `MatDiagonalGetInverseDiagonal()`, `MatDiagonalSet()`, `MatDiagonalSetDiagonal()`

## Level

advanced

## Location

src/mat/impls/diagonal/diagonal.c

Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages