# MatDuplicate

Duplicates a matrix including the non-zero structure.

### Synopsis

    #include "petscmat.h"
    PetscErrorCode  MatDuplicate(Mat mat,MatDuplicateOption op,Mat *M)

Collective on Mat

### Input Parameters

| mat | - the matrix
| op | - either MAT_DO_NOT_COPY_VALUES or MAT_COPY_VALUES, cause it to copy nonzero values as well or not

### Output Parameter

M -pointer to place new matrix

### C++ variants

| Mat MatDuplicate(Mat A) |  | -> |  | MatDuplicate(A,MAT_COPY_VALUES,&a); return a;
| Mat MatDuplicate(Mat A,MatDuplicateOption o) |  | -> |  | MatDuplicate(A,o,&a); return a;

### See Also

MatCopy(), MatConvert()

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/ksp/examples/tutorials/ex10.c.html