# SNESComputeJacobianDefault
Computes the Jacobian using finite differences. 
## Synopsis
```
#include "petscsnes.h"  
PetscErrorCode SNESComputeJacobianDefault(SNES snes, Vec x1, Mat J, Mat B, void *ctx)
```
Collective


## Input Parameters

- ***snes -*** the `SNES` context
- ***x1 -*** compute Jacobian at this point
- ***ctx -*** application's function context, as set with `SNESSetFunction()`



## Output Parameters

- ***J -*** Jacobian matrix (not altered in this routine)
- ***B -*** newly computed Jacobian matrix to use with preconditioner (generally the same as J)



## Options Database Keys

- ***-snes_fd -*** Activates `SNESComputeJacobianDefault()`
- ***-snes_test_err -*** Square root of function error tolerance, default square root of machine
epsilon (1.e-8 in double, 3.e-4 in single)
- ***-mat_fd_type -*** Either wp or ds (see `MATMFFD_WP` or `MATMFFD_DS`)



## Notes
This routine is slow and expensive, and is not currently optimized
to take advantage of sparsity in the problem.  Although
`SNESComputeJacobianDefault()` is not recommended for general use
in large-scale applications, It can be useful in checking the
correctness of a user-provided Jacobian.

An alternative routine that uses coloring to exploit matrix sparsity is
`SNESComputeJacobianDefaultColor()`.

This routine ignores the maximum number of function evaluations set with `SNESSetTolerances()` and the function
evaluations it performs are not counted in what is returned by of `SNESGetNumberFunctionEvals()`.

This function can be provided to `SNESSetJacobian()` along with a dense matrix to hold the Jacobian




## See Also
 `SNES`, `SNESSetJacobian()`, `SNESSetJacobian()`, `SNESComputeJacobianDefaultColor()`, `MatCreateSNESMF()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/snes/interface/snesj.c.html#SNESComputeJacobianDefault">src/snes/interface/snesj.c</A>

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


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/snes/interface/snesj.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)  
