# TaoDefaultComputeGradient
computes the gradient using finite differences. 
## Synopsis
```
#include "petsctao.h"  
PetscErrorCode TaoDefaultComputeGradient(Tao tao, Vec Xin, Vec G, void *dummy)
```
Collective on tao


## Input Parameters

- ***tao   -*** the Tao context
- ***X     -*** compute gradient at this point
- ***dummy -*** not used



## Output Parameter

- ***G -*** Gradient Vector



## Options Database Key

- ***-tao_fd_gradient      -*** activates TaoDefaultComputeGradient()
- ***-tao_fd_delta <delta> -*** change in X used to calculate finite differences





## Notes
This routine is slow and expensive, and is not optimized
to take advantage of sparsity in the problem.  Although
not recommended for general use
in large-scale applications, it can be useful in checking the
correctness of a user-provided gradient.  Use the tao method TAOTEST
to get an indication of whether your gradient is correct.
This finite difference gradient evaluation can be set using the routine `TaoSetGradient()` or by using the command line option -tao_fd_gradient


## See Also
 `Tao`, `TaoSetGradient()`

## Level
advanced

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/interface/fdiff.c.html#TaoDefaultComputeGradient">src/tao/interface/fdiff.c</A>


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


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