# MatResidual
Default routine to calculate the residual r = b - Ax 
## Synopsis
```
#include "petscmat.h" 
PetscErrorCode MatResidual(Mat mat, Vec b, Vec x, Vec r)
```
Collective


## Input Parameters

- ***mat -*** the matrix
- ***b   -*** the right-hand-side
- ***x   -*** the approximate solution



## Output Parameter

- ***r -*** location to store the residual





## See Also
 `Mat`, `MatMult()`, `MatMultAdd()`, `PCMGSetResidual()`

## Level
developer

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/mat/interface/matrix.c.html#MatResidual">src/mat/interface/matrix.c</A>


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


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