# PCSetOperators
Sets the matrix associated with the linear system and a (possibly) different one associated with the preconditioner. 
## Synopsis
```
#include "petscksp.h" 
PetscErrorCode PCSetOperators(PC pc, Mat Amat, Mat Pmat)
```
Logically Collective


## Input Parameters

- ***pc -*** the preconditioner context
- ***Amat -*** the matrix that defines the linear system
- ***Pmat -*** the matrix to be used in constructing the preconditioner, usually the same as Amat.



## Notes
Passing a NULL for Amat or Pmat removes the matrix that is currently used.

If you wish to replace either Amat or Pmat but leave the other one untouched then
first call `KSPGetOperators()` to get the one you wish to keep, call `PetscObjectReference()`
on it and then pass it back in in your call to `KSPSetOperators()`.


## More Notes about Repeated Solution of Linear Systems
PETSc does NOT reset the matrix entries of either Amat or Pmat
to zero after a linear solve; the user is completely responsible for
matrix assembly.  See the routine `MatZeroEntries()` if desiring to
zero all elements of a matrix.




## See Also
 `PC`, `PCGetOperators()`, `MatZeroEntries()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/pc/interface/precon.c.html#PCSetOperators">src/ksp/pc/interface/precon.c</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/ksp/pc/interface/precon.c)


[Index of all PC routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
