# MatGetDiagonal

Gets the diagonal of a matrix.

### Synopsis

    #include "petscmat.h"
    PetscErrorCode PETSCMAT_DLLEXPORT MatGetDiagonal(Mat mat,Vec v)

Collective on Mat and Vec

### Input Parameters

| mat | - the matrix
| v | - the vector for storing the diagonal

### Output Parameter

v -the diagonal of the matrix

### Notes

For the SeqAIJ matrix format, this routine may also be called on a LU factored matrix; in that case it routines the reciprocal of the diagonal entries in U. It returns the entries permuted by the row and column permutation used during the symbolic factorization.

### See Also

MatGetRow(), MatGetSubmatrices(), MatGetSubmatrix(), MatGetRowMax()

Level:intermediate
Location:src/mat/interface/matrix.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/ksp/pc/examples/tutorials/ex1.c.html
src/ksp/pc/examples/tutorials/ex2.c.html
src/ksp/examples/tutorials/ex15.c.html
src/ksp/examples/tutorials/ex15f.F.html