# MatCreateMFFD

Creates a matrix-free matrix. See also MatCreateSNESMF()

### Synopsis

    #include "petscmat.h"
    PetscErrorCode PETSCMAT_DLLEXPORT MatCreateMFFD(MPI_Comm comm,PetscInt m,PetscInt n,PetscInt M,PetscInt N,Mat *J)

Collective on Vec

### Input Parameters

| comm | - MPI communicator
| m | - number of local rows (or PETSC_DECIDE to have calculated if M is given) This value should be the same as the local size used in creating the y vector for the matrix-vector product y = Ax.
| n | - This value should be the same as the local size used in creating the x vector for the matrix-vector product y = Ax. (or PETSC_DECIDE to have calculated if N is given) For square matrices n is almost always m.
| M | - number of global rows (or PETSC_DETERMINE to have calculated if m is given)
| N | - number of global columns (or PETSC_DETERMINE to have calculated if n is given)

### Output Parameter

J -the matrix-free matrix

### Notes

The matrix-free matrix context merely contains the function pointers and work space for performing finite difference approximations of Jacobian-vector products, F'(u)*a,

The default code uses the following approach to compute h

         F'(u)*a = [F(u+h*a) - F(u)]/h where
         h = error_rel*u'a/||a||^2                        if  |u'a| > umin*||a||_{1}
           = error_rel*umin*sign(u'a)*||a||_{1}/||a||^2   otherwise
     where
         error_rel = square root of relative error in function evaluation
         umin = minimum iterate parameter

The user can set the error_rel via MatMFFDSetFunctionError() and umin via MatMFFDDefaultSetUmin(); see the nonlinear solvers chapter of the users manual for details.

The user should call MatDestroy() when finished with the matrix-free matrix context.

### Options Database Keys

| -mat_mffd_err <error_rel> | - Sets error_rel
| -mat_mffd_unim <umin> | - Sets umin (for default PETSc routine that computes h only)
| -mat_mffd_ksp_monitor | - KSP monitor routine that prints differencing h
| -mat_mffd_check_positivity | -

### Keywords

default, matrix-free, create, matrix

### See Also

MatDestroy(), MatMFFDSetFunctionError(), MatMFFDDefaultSetUmin(), MatMFFDSetFunction()
MatMFFDSetHHistory(), MatMFFDResetHHistory(), MatCreateSNESMF(), MatMFFDGetH(),MatMFFDKSPMonitor(), MatMFFDRegisterDynamic),, MatMFFDComputeJacobian()

Level:advanced
Location: src/mat/impls/mffd/mffd.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages