# MatCreateSNESMF
Creates a matrix-free matrix context for use with a `SNES` solver.  This matrix can be used as the Jacobian argument for the routine `SNESSetJacobian()`. See `MatCreateMFFD()` for details on how the finite difference computation is done. 
## Synopsis
```
#include "petscsnes.h" 
#include "petscdm.h"   
PetscErrorCode MatCreateSNESMF(SNES snes, Mat *J)
```
Collective on snes


## Input Parameters

- ***snes -*** the `SNES` context



## Output Parameter

- ***J -*** the matrix-free matrix which is of type `MATMFFD`





## Notes
You can call `SNESSetJacobian()` with `MatMFFDComputeJacobian()` if you are using matrix and not a different
preconditioner matrix

If you wish to provide a different function to do differencing on to compute the matrix-free operator than
that provided to `SNESSetFunction()` then call `MatMFFDSetFunction()` with your function after this call.

The difference between this routine and `MatCreateMFFD()` is that this matrix
automatically gets the current base vector from the `SNES` object and not from an
explicit call to `MatMFFDSetBase()`.

If `MatMFFDSetBase()` is ever called on jac then this routine will NO longer get
the x from the `SNES` object and `MatMFFDSetBase()` must from that point on be used to
change the base vector x.

Using a different function for the differencing will not work if you are using non-linear left preconditioning.


## See Also
 `MATMFFD, `MatDestroy()`, `MatMFFDSetFunction()`, `MatMFFDSetFunctionError()`, `MatMFFDDSSetUmin()`
`MatMFFDSetHHistory()`, `MatMFFDResetHHistory()`, `MatCreateMFFD()`,
`MatMFFDGetH()`, `MatMFFDRegister()`, `MatMFFDComputeJacobian()`, `MatSNESMFSetReuseBase()`, `MatSNESMFGetReuseBase()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/mf/snesmfj.c.html#MatCreateSNESMF">src/snes/mf/snesmfj.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex15.c.html">src/ts/tutorials/ex15.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/snes/mf/snesmfj.c)


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