:orphan:
# MatMFFDSetFunction
Sets the function used in applying the matrix free `MATMFFD` matrix.
## Synopsis
```
#include "petscmat.h"
PetscErrorCode MatMFFDSetFunction(Mat mat, PetscErrorCode (*func)(void *, Vec, Vec), void *funcctx)
```
Logically Collective
## Input Parameters
- ***mat -*** the matrix free matrix `MATMFFD` created via `MatCreateSNESMF()` or `MatCreateMFFD()`
- ***func -*** the function to use
- ***funcctx -*** optional function context passed to function
## Calling Sequence of `func`
```none
PetscErrorCode func(void *funcctx, Vec x, Vec f)
```
- ***funcctx -*** user provided context
- ***x -*** input vector
- ***f -*** computed output function
## Notes
If you use this you MUST call `MatAssemblyBegin()` and `MatAssemblyEnd()` on the matrix free
matrix inside your compute Jacobian routine
If this is not set then it will use the function set with `SNESSetFunction()` if `MatCreateSNESMF()` was used.
## See Also
[](ch_matrices), `Mat`, `MATMFFD`, `MatCreateSNESMF()`, `MatMFFDGetH()`, `MatCreateMFFD()`, `MATMFFD`,
`MatMFFDSetHHistory()`, `MatMFFDResetHHistory()`, `SNESetFunction()`
## Level
advanced
## Location
src/mat/impls/mffd/mffd.c
## Examples
src/snes/tutorials/ex22.c
## Implementations
MatMFFDSetFunction_MFFD(Mat mat, PetscErrorCode (*func) in src/mat/impls/mffd/mffd.c
---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/mat/impls/mffd/mffd.c)
[Index of all Mat routines](index.md)
[Table of Contents for all manual pages](/manualpages/index.md)
[Index of all manual pages](/manualpages/singleindex.md)